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
7 end7 end
8 8
9 def root9 def root
10 css(*%w(#About_this_Reference+div #About_this_Reference10 css(*%w(#About_this_Reference+div #About_this_Reference #Comments~* #Comments)).remove
11 #Typed_array_constructors+ul #Typed_array_constructors
12 #Internationalization_constructors+ul #Internationalization_constructors
13 #Comments~* #Comments)).remove
14 11
15 # Move "Global Objects" lists to the same level as the other ones12 # Move "Global Objects" lists to the same level as the other ones
16 div = at_css '#Global_Objects + div'13 div = at_css '#Global_Objects + div'
17 div.css('h3').each { |node| node.name = 'h2' }14 div.css('h3').each { |node| node.name = 'h2' }
18 at_css('#Global_Objects').replace(div)15 at_css('#Global_Objects').replace(div.children)
19 16
20 # Remove heading links17 # Remove heading links
21 css('h2 > a').each do |node|18 css('h2 > a').each do |node|
@@ -25,9 +22,15 @@ module Docs · 3 unmodified lines
25 end22 end
26 23
27 def other24 def other
25 # Remove "style" attribute
28 css('.inheritsbox', '.overheadIndicator').each do |node|26 css('.inheritsbox', '.overheadIndicator').each do |node|
29 node.remove_attribute 'style'27 node.remove_attribute 'style'
30 end28 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
31 end34 end
32 end35 end
33 end36 end
lib/docs/filters/javascript/entries.rb+16−17
@@ -1,28 +1,17 @@
1module Docs1module Docs
2 class Javascript2 class Javascript
3 class EntriesFilter < Docs::EntriesFilter3 class EntriesFilter < Docs::EntriesFilter
4 TYPES = %w(Array Boolean Date Function JSON Math Number Object RegExp String)4 TYPES = %w(Array Boolean Date Function Intl JSON Math Number Object RegExp String)
5 5 INTL_OBJECTS = %w(Collator DateTimeFormat NumberFormat)
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)) ]}
18 6
19 def get_name7 def get_name
20 if slug.start_with? 'Global_Objects/'8 if slug.start_with? 'Global_Objects/'
21 name, method = *slug.sub('Global_Objects/', '').split('/')9 name, method = *slug.sub('Global_Objects/', '').split('/')
10 name.prepend 'Intl.' if INTL_OBJECTS.include?(name)
22 11
23 if method12 if method
24 unless method == method.upcase || method == 'NaN'13 unless method == method.upcase || method == 'NaN'
25 method = method[0].downcase + method[1..-1] # e.g. Constructor => constructor14 method = method[0].downcase + method[1..-1] # e.g. Trim => trim
26 end15 end
27 name << ".#{method}"16 name << ".#{method}"
28 end17 end
@@ -48,16 +37,26 @@ module Docs · 19 unmodified lines
48 object, method = *slug.sub('Global_Objects/', '').split('/')37 object, method = *slug.sub('Global_Objects/', '').split('/')
49 if object.end_with? 'Error'38 if object.end_with? 'Error'
50 'Errors'39 'Errors'
40 elsif INTL_OBJECTS.include?(object)
41 'Intl'
51 elsif method || TYPES.include?(object)42 elsif method || TYPES.include?(object)
52 object43 object
53 else44 else
54 'Global Objects'45 'Global Objects'
55 end46 end
47 else
48 'Miscellaneous'
56 end49 end
57 end50 end
58 51
59 def additional_entries52 def include_default_entry?
60 ADDITIONAL_ENTRIES[slug] || []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')
61 end60 end
62 end61 end
63 end62 end
lib/docs/scrapers/mdn/javascript.rb+0−6
@@ -14,18 +14,12 @@ module Docs · 13 unmodified lines
14 /Deprecated_Features14 /Deprecated_Features
15 /Deprecated_and_obsolete_features15 /Deprecated_and_obsolete_features
16 /Functions_and_function_scope16 /Functions_and_function_scope
17 /Functions_and_function_scope/Strict_mode
18 /Global_Objects/Iterator17 /Global_Objects/Iterator
19 /Global_Objects/Number/toInteger
20 /Global_Objects/ParallelArray
21 /Global_Objects/Proxy18 /Global_Objects/Proxy
22 /Global_Objects/uneval
23 /Reserved_Words19 /Reserved_Words
24 /arrow_functions20 /arrow_functions
25 /rest_parameters)21 /rest_parameters)
26 22
27 options[:skip_patterns] = [/Intl/, /Collator/, /DateTimeFormat/, /NumberFormat/]
28
29 # Duplicates23 # Duplicates
30 options[:skip].concat %w(24 options[:skip].concat %w(
31 /Global_Objects25 /Global_Objects