1
0

dojo.rb 1.4 KB

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