|
|
@@ -1,12 +1,12 @@
|
|
|
+require 'yajl/json_gem'
|
|
|
+
|
|
|
module Docs
|
|
|
class Dojo < UrlScraper
|
|
|
include StubRootPage
|
|
|
- self.name = 'Dojo'
|
|
|
- self.slug = 'dojo'
|
|
|
+
|
|
|
self.type = 'dojo'
|
|
|
self.version = '1.10'
|
|
|
- self.base_url = 'http://dojotoolkit.org/api/1.10/'
|
|
|
-
|
|
|
+ self.base_url = "http://dojotoolkit.org/api/#{version}/"
|
|
|
|
|
|
# Dojo expects all the requests to be xhrs or it redirects you back to the docs home page
|
|
|
# where it uses js to call the backend based on the URL so you get the appropriate documentation
|
|
|
@@ -16,34 +16,34 @@ module Docs
|
|
|
code: 'https://github.com/dojo/dojo'
|
|
|
}
|
|
|
|
|
|
- html_filters.push 'dojo/clean_html', 'dojo/entries'
|
|
|
+ html_filters.push 'dojo/entries', 'dojo/clean_html', 'title'
|
|
|
+ text_filters.push 'dojo/clean_urls'
|
|
|
|
|
|
- # Don't use default selector on xhrs as no body or html document exists
|
|
|
options[:container] = false
|
|
|
+ options[:title] = false
|
|
|
+ options[:root_title] = 'Dojo Toolkit'
|
|
|
|
|
|
- def root_page_body
|
|
|
- require 'json'
|
|
|
- require 'set'
|
|
|
- response = Typhoeus::Request.new("dojotoolkit.org/api/1.10/tree.json",
|
|
|
- headers: { 'User-Agent' => 'devdocs.io' , 'X-Requested-With' => 'XMLHttpRequest' }).run
|
|
|
- treeJSON = JSON.parse(response.response_body)
|
|
|
- treeJSON = treeJSON["children"].bsearch { |framework| framework["name"] == "dojo" }
|
|
|
- @url_set = Set.new
|
|
|
- def get_url_list treeJSON
|
|
|
- @url_set.add(self.class.base_url + treeJSON["fullname"] + ".html?xhr=true")
|
|
|
- if (treeJSON["children"])
|
|
|
- treeJSON["children"].each do |child|
|
|
|
- get_url_list child
|
|
|
- end
|
|
|
- end
|
|
|
- end
|
|
|
- get_url_list treeJSON
|
|
|
- @url_set.map { |l| "<a href='#{l}'>#{l}</a>"}.join "<br>"
|
|
|
- end
|
|
|
+ options[:only_patterns] = [/\Adojo\//]
|
|
|
+ options[:skip_patterns] = [/dijit/, /dojox/]
|
|
|
|
|
|
options[:attribution] = <<-HTML
|
|
|
- The Dojo Toolkit is Copyright © 2005–2013 <br>
|
|
|
- Dual licensed under BSD 3-Clause and AFL.
|
|
|
+ © 2005–2015 The Dojo Foundation<br>
|
|
|
+ Licensed under the AFL 2.1 and BSD 3-Clause licenses.
|
|
|
HTML
|
|
|
+
|
|
|
+ private
|
|
|
+
|
|
|
+ def root_page_body
|
|
|
+ response = request_one("#{self.base_url}tree.json")
|
|
|
+ json = JSON.parse(response.body)
|
|
|
+ urls = get_url_list(json)
|
|
|
+ urls.map { |url| "<a href='#{url}'>#{url}</a>" }.join
|
|
|
+ end
|
|
|
+
|
|
|
+ def get_url_list(json, set = Set.new)
|
|
|
+ set.add("#{self.class.base_url}#{json['fullname']}.html?xhr=true")
|
|
|
+ json['children'].each { |child| get_url_list(child, set) } if json['children']
|
|
|
+ set
|
|
|
+ end
|
|
|
end
|
|
|
end
|