tensorflow.rb 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. # frozen_string_literal: true
  2. module Docs
  3. class Tensorflow < UrlScraper
  4. self.name = 'TensorFlow'
  5. self.type = 'tensorflow'
  6. self.release = '1.2'
  7. self.root_path = 'index.html'
  8. self.links = {
  9. home: 'https://www.tensorflow.org/',
  10. code: 'https://github.com/tensorflow/tensorflow'
  11. }
  12. html_filters.push 'tensorflow/entries', 'tensorflow/clean_html'
  13. options[:container] = '.devsite-main-content'
  14. options[:fix_urls] = ->(url) do
  15. url.sub! 'how_tos/../tutorials', 'tutorials'
  16. url
  17. end
  18. options[:attribution] = <<-HTML
  19. &copy; 2017 The TensorFlow Authors. All rights reserved.<br>
  20. Licensed under the Creative Commons Attribution License 3.0.<br>
  21. Code samples licensed under the Apache 2.0 License.
  22. HTML
  23. version 'Python' do
  24. include MultipleBaseUrls
  25. self.base_urls = ['https://www.tensorflow.org/api_docs/python/', 'https://www.tensorflow.org/api_guides/python/']
  26. end
  27. version 'C++' do
  28. include MultipleBaseUrls
  29. self.base_urls = ['https://www.tensorflow.org/api_docs/cc/', 'https://www.tensorflow.org/api_guides/cc/']
  30. end
  31. version 'Guide' do
  32. self.base_url = 'https://www.tensorflow.org/'
  33. self.root_path = 'get_started/get_started'
  34. self.initial_paths = %w(
  35. programmers_guide/reading_data
  36. tutorials/mandelbrot
  37. performance/performance_guide
  38. deploy/hadoop
  39. extend/architecture)
  40. options[:only_patterns] = [
  41. /\Aget_started/,
  42. /\Aprogrammers_guide/,
  43. /\Atutorials/,
  44. /\Aperformance/,
  45. /\Adeploy/,
  46. /\Aextend/]
  47. end
  48. private
  49. def parse(response)
  50. unless response.url == root_url || self.class.version == 'Guide'
  51. response.body.sub!(/<nav class="devsite-nav-responsive-sidebar.+?<\/nav>/m, '')
  52. response.body.gsub!(/<li class="devsite-nav-item">.+?<\/li>/m, '')
  53. end
  54. super
  55. end
  56. end
  57. end