angular.rb 1.5 KB

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