-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathRakefile
55 lines (42 loc) · 1.38 KB
/
Rakefile
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
require 'rubygems'
require 'httparty'
require 'nokogiri'
require 'set'
def mdc_url(type)
'http://developer.mozilla.org/en/Core_JavaScript_1.5_Reference/Global_Objects/' + type
end
def document(url)
puts "Fetching #{url} ..."
Nokogiri.parse(HTTParty.get(url))
rescue
document(url)
end
MDC_URLS = %w(Array Boolean Date EvalError Error Function Math
Number Object RangeError ReferenceError RegExp
String SyntaxError TypeError URIError).
map(&method(:mdc_url))
ELEMENT_URL = 'http://developer.mozilla.org/en/DOM/element'
EVENT_URL = 'http://developer.mozilla.org/en/DOM/event'
STYLE_URL = 'http://developer.mozilla.org/en/DOM/CSS'
class MethodSet < SortedSet
def add_method(link)
name = link.text.strip.gsub(/^event\./, '')
add(name) if name =~ /^[a-z][a-zA-Z0-9\_\$]*$/
end
def import(url, selector)
document(url).search(selector).each(&method(:add_method))
end
end
namespace :import do
task :method_chain do
methods = MethodSet.new
MDC_URLS.each { |url| methods.import(url, 'dt a') }
methods.import(ELEMENT_URL, 'td code a:first-child')
document(ELEMENT_URL).search('#pageText>p').last.search('a').map do |link|
methods.import(link[:href], 'td code a:first-child')
end
methods.import(EVENT_URL, 'dt a')
methods.import(STYLE_URL, 'li a')
p methods.entries
end
end