meteor.rb 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. module Docs
  2. class Meteor < UrlScraper
  3. class << self
  4. attr_accessor :guide_url
  5. end
  6. self.type = 'meteor'
  7. self.root_path = 'index.html'
  8. self.links = {
  9. home: 'https://www.meteor.com/',
  10. code: 'https://github.com/meteor/meteor/'
  11. }
  12. html_filters.push 'meteor/entries', 'meteor/clean_html'
  13. options[:skip_patterns] = [/\Av\d/]
  14. options[:skip] = %w(
  15. CONTRIBUTING.html
  16. CHANGELOG.html
  17. using-packages.html
  18. writing-packages.html
  19. )
  20. options[:attribution] = <<-HTML
  21. &copy; 2011&ndash;2016 Meteor Development Group<br>
  22. Licensed under the MIT License.
  23. HTML
  24. version '1.4' do
  25. self.release = '1.4.0'
  26. self.base_url = 'https://docs.meteor.com/'
  27. self.guide_url = 'https://guide.meteor.com/'
  28. self.initial_urls = [guide_url]
  29. end
  30. version '1.3' do
  31. self.release = '1.3.5'
  32. self.base_url = "https://docs.meteor.com/v#{self.release}/"
  33. self.guide_url = 'https://guide.meteor.com/v1.3/'
  34. self.initial_urls = [guide_url]
  35. end
  36. def guide_url
  37. @guide_url ||= URL.parse(self.class.guide_url)
  38. end
  39. private
  40. def process_url?(url)
  41. base_url.contains?(url) || guide_url.contains?(url)
  42. end
  43. def process_response(response)
  44. original_host = @base_url.host
  45. original_path = @base_url.path
  46. @base_url.host = response.effective_url.host
  47. @base_url.path = response.effective_url.path[/\A\/v[\d\.]+\//, 0] || '/'
  48. super
  49. ensure
  50. @base_url.host = original_host
  51. @base_url.path = original_path
  52. end
  53. end
  54. end