dojo.rb 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. require 'yajl/json_gem'
  2. module Docs
  3. class Dojo < UrlScraper
  4. include StubRootPage
  5. self.type = 'dojo'
  6. self.release = '1.10'
  7. self.base_url = "http://dojotoolkit.org/api/#{release}/"
  8. # Dojo expects all the requests to be xhrs or it redirects you back to the docs home page
  9. # where it uses js to call the backend based on the URL so you get the appropriate documentation
  10. self.headers = { 'User-Agent' => 'devdocs.io' , 'X-Requested-With' => 'XMLHttpRequest' }
  11. self.links = {
  12. home: 'http://dojotoolkit.org',
  13. code: 'https://github.com/dojo/dojo'
  14. }
  15. html_filters.push 'dojo/entries', 'dojo/clean_html', 'title'
  16. text_filters.push 'dojo/clean_urls'
  17. options[:container] = false
  18. options[:title] = false
  19. options[:root_title] = 'Dojo Toolkit'
  20. options[:only_patterns] = [/\Adojo\//]
  21. options[:skip_patterns] = [/dijit/, /dojox/]
  22. options[:attribution] = <<-HTML
  23. &copy; 2005&ndash;2015 The Dojo Foundation<br>
  24. Licensed under the AFL 2.1 and BSD 3-Clause licenses.
  25. HTML
  26. private
  27. def root_page_body
  28. response = request_one("#{self.base_url}tree.json")
  29. json = JSON.parse(response.body)
  30. urls = get_url_list(json)
  31. urls.map { |url| "<a href='#{url}'>#{url}</a>" }.join
  32. end
  33. def get_url_list(json, set = Set.new)
  34. set.add("#{self.class.base_url}#{json['fullname']}.html?xhr=true")
  35. json['children'].each { |child| get_url_list(child, set) } if json['children']
  36. set
  37. end
  38. end
  39. end