History

Update JavaScript documentation

Fixes #9

Thibaut committed 12 years ago

Commit 33bf9601 parent da165073 files · +24 −28Browse files

Unified · Split

3 files
  1. lib/docs/filters/javascript/clean_html.rb +8 −5
  2. lib/docs/filters/javascript/entries.rb +16 −17
  3. lib/docs/scrapers/mdn/javascript.rb +0 −6
lib/docs/filters/javascript/clean_html.rb+8−5
@@ -7,15 +7,12 @@ module Docs · 6 unmodified lines
77 end
88
99 def root
10− css(*%w(#About_this_Reference+div #About_this_Reference
11− #Typed_array_constructors+ul #Typed_array_constructors
12− #Internationalization_constructors+ul #Internationalization_constructors
13− #Comments~* #Comments)).remove
10+ css(*%w(#About_this_Reference+div #About_this_Reference #Comments~* #Comments)).remove
1411
1512 # Move "Global Objects" lists to the same level as the other ones
1613 div = at_css '#Global_Objects + div'
1714 div.css('h3').each { |node| node.name = 'h2' }
18− at_css('#Global_Objects').replace(div)
15+ at_css('#Global_Objects').replace(div.children)
1916
2017 # Remove heading links
2118 css('h2 > a').each do |node|
@@ -25,9 +22,15 @@ module Docs · 3 unmodified lines
2522 end
2623
2724 def other
25+ # Remove "style" attribute
2826 css('.inheritsbox', '.overheadIndicator').each do |node|
2927 node.remove_attribute 'style'
3028 end
29+
30+ # Remove <div> wrapping .overheadIndicator
31+ css('div > .overheadIndicator:first-child:last-child').each do |node|
32+ node.parent.replace(node)
33+ end
3134 end
3235 end
3336 end
lib/docs/filters/javascript/entries.rb+16−17
@@ -1,28 +1,17 @@
11 module Docs
22 class Javascript
33 class EntriesFilter < Docs::EntriesFilter
4− TYPES = %w(Array Boolean Date Function JSON Math Number Object RegExp String)
5−
6− ADDITIONAL_ENTRIES = {
7− 'operators/arithmetic_operators' => [
8− %w(++ .2B.2B_.28Increment.29),
9− %w(-- --_.28Decrement.29) ],
10− 'operators/bitwise_operators' => [
11− %w(& .26_(Bitwise_AND)),
12− %w(| .7C_(Bitwise_OR)),
13− %w(^ .5E_(Bitwise_XOR)),
14− %w(~ .7E_(Bitwise_NOT)),
15− %w(<< <<_(Left_shift)),
16− %w(>> >>_(Sign-propagating_right_shift)),
17− %w(>>> >>>_(Zero-fill_right_shift)) ]}
4+ TYPES = %w(Array Boolean Date Function Intl JSON Math Number Object RegExp String)
5+ INTL_OBJECTS = %w(Collator DateTimeFormat NumberFormat)
186
197 def get_name
208 if slug.start_with? 'Global_Objects/'
219 name, method = *slug.sub('Global_Objects/', '').split('/')
10+ name.prepend 'Intl.' if INTL_OBJECTS.include?(name)
2211
2312 if method
2413 unless method == method.upcase || method == 'NaN'
25− method = method[0].downcase + method[1..-1] # e.g. Constructor => constructor
14+ method = method[0].downcase + method[1..-1] # e.g. Trim => trim
2615 end
2716 name << ".#{method}"
2817 end
@@ -48,16 +37,26 @@ module Docs · 19 unmodified lines
4837 object, method = *slug.sub('Global_Objects/', '').split('/')
4938 if object.end_with? 'Error'
5039 'Errors'
40+ elsif INTL_OBJECTS.include?(object)
41+ 'Intl'
5142 elsif method || TYPES.include?(object)
5243 object
5344 else
5445 'Global Objects'
5546 end
47+ else
48+ 'Miscellaneous'
5649 end
5750 end
5851
59− def additional_entries
60− ADDITIONAL_ENTRIES[slug] || []
52+ def include_default_entry?
53+ node = doc.at_css '.overheadIndicator'
54+
55+ # Can't use :first-child because #doc is a DocumentFragment
56+ return true unless node && node.parent == doc && !node.previous_element
57+
58+ !node.content.include?('not on a standards track') &&
59+ !node.content.include?('removed from the Web')
6160 end
6261 end
6362 end
lib/docs/scrapers/mdn/javascript.rb+0−6
@@ -14,18 +14,12 @@ module Docs · 13 unmodified lines
1414 /Deprecated_Features
1515 /Deprecated_and_obsolete_features
1616 /Functions_and_function_scope
17− /Functions_and_function_scope/Strict_mode
1817 /Global_Objects/Iterator
19− /Global_Objects/Number/toInteger
20− /Global_Objects/ParallelArray
2118 /Global_Objects/Proxy
22− /Global_Objects/uneval
2319 /Reserved_Words
2420 /arrow_functions
2521 /rest_parameters)
2622
27− options[:skip_patterns] = [/Intl/, /Collator/, /DateTimeFormat/, /NumberFormat/]
28−
2923 # Duplicates
3024 options[:skip].concat %w(
3125 /Global_Objects