meteor.rb 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. module Docs
  2. class Meteor < UrlScraper
  3. self.type = 'meteor'
  4. self.version = '1.0.4'
  5. self.base_url = 'http://docs.meteor.com'
  6. self.root_path = '/#/full/'
  7. self.links = {
  8. home: 'https://www.meteor.com/',
  9. code: 'https://github.com/meteor/meteor/'
  10. }
  11. html_filters.push 'meteor/entries', 'meteor/clean_html', 'title'
  12. options[:title] = 'Meteor'
  13. options[:skip_links] = true
  14. options[:attribution] = <<-HTML
  15. &copy; 2011&ndash;2015 Meteor Development Group<br>
  16. Licensed under the MIT License.
  17. HTML
  18. private
  19. def request_one(url)
  20. stub_root_page if url == root_url.to_s
  21. super
  22. end
  23. def request_all(urls, &block)
  24. stub_root_page
  25. super
  26. end
  27. def stub_root_page
  28. response = Typhoeus::Response.new(
  29. effective_url: root_url.to_s,
  30. code: 200,
  31. headers: { 'Content-Type' => 'text/html' },
  32. body: get_root_page_body)
  33. Typhoeus.stub(root_url.to_s).and_return(response)
  34. end
  35. def get_root_page_body
  36. require 'capybara'
  37. Capybara.current_driver = :selenium
  38. Capybara.visit(root_url.to_s)
  39. Capybara.find('.body')['innerHTML']
  40. end
  41. end
  42. end