angular.rb 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. module Docs
  2. class Angular < UrlScraper
  3. self.name = 'Angular.js'
  4. self.slug = 'angular'
  5. self.type = 'angular'
  6. self.version = '1.2.10'
  7. self.base_url = 'http://docs.angularjs.org/partials/api/'
  8. html_filters.insert_before 'normalize_paths', 'angular/clean_html'
  9. html_filters.push 'angular/entries', 'title'
  10. text_filters.push 'angular/clean_urls'
  11. options[:title] = false
  12. options[:root_title] = 'Angular.js'
  13. options[:fix_urls] = ->(url) do
  14. url.sub! '/partials/api/api/', '/partials/api/'
  15. url.sub! '/partials/api/guide/', '/guide/'
  16. url.sub! %r{/partials/api/(.+?)(?<!\.html)(?:\z|(#.*))}, '/partials/api/\1.html\2'
  17. url.gsub! '/partials/api/(.+?)\:', '/partials/api/\1%3A'
  18. url
  19. end
  20. options[:skip] = %w(ng.html)
  21. options[:attribution] = <<-HTML
  22. &copy; 2010&ndash;2014 Google, Inc.<br>
  23. Licensed under the Creative Commons Attribution License 3.0.
  24. HTML
  25. private
  26. def request_one(url)
  27. stub_root_page if url == root_url.to_s
  28. super
  29. end
  30. def request_all(urls, &block)
  31. stub_root_page
  32. super
  33. end
  34. def stub_root_page
  35. response = Typhoeus::Response.new(
  36. effective_url: root_url.to_s,
  37. code: 200,
  38. headers: { 'Content-Type' => 'text/html' },
  39. body: get_root_page_body)
  40. Typhoeus.stub(root_url.to_s).and_return(response)
  41. end
  42. def get_root_page_body
  43. require 'capybara'
  44. Capybara.current_driver = :selenium
  45. Capybara.visit('http://docs.angularjs.org/api/')
  46. Capybara.find('.side-navigation')['innerHTML']
  47. end
  48. end
  49. end