tensorflow.rb 1.9 KB

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