History

Update & improve MDN scrapers

Closes 260.

Thibaut committed 11 years ago

Commit ded6daa1 parent aad00635 files · +58 −10Browse files

Unified · Split

5 files
  1. lib/docs/filters/css/entries.rb +12 −9
  2. lib/docs/filters/dom/entries.rb +35 −0
  3. lib/docs/filters/dom_events/entries.rb +9 −0
  4. lib/docs/scrapers/mdn/dom.rb +1 −1
  5. lib/docs/scrapers/mdn/dom_events.rb +1 −0
lib/docs/filters/css/entries.rb+12−9
@@ -9,9 +9,6 @@ module Docs · 8 unmodified lines
99 linear-gradient radial-gradient repeating-linear-gradient
1010 repeating-radial-gradient var)
1111
12− PSEUDO_ELEMENT_SLUGS = %w(::after ::before ::first-letter ::first-line
13− ::selection)
14−
1512 VALUE_SLUGS = %w(auto inherit initial none normal unset)
1613
1714 ADDITIONAL_ENTRIES = {
@@ -39,6 +36,7 @@ module Docs · 21 unmodified lines
3936 'transform-function' => [
4037 %w(matrix() matrix() Functions),
4138 %w(matrix3d() matrix3d() Functions),
39+ %w(perspective() perspective() Functions),
4240 %w(rotate() rotate() Functions),
4341 %w(rotate3d() rotate3d() Functions),
4442 %w(rotateX() rotateX() Functions),
@@ -60,18 +58,21 @@ module Docs · 15 unmodified lines
6058
6159 def get_name
6260 case type
63− when 'Data Types' then "<#{super.remove ' value'}>"
64− when 'Functions' then "#{super}()"
61+ when 'Data Types' then "<#{super.remove ' value'}>"
62+ when 'Functions' then "#{super}()"
63+ when 'Miscellaneous' then slug.to_s.gsub('_', ' ').gsub('/', ': ')
6564 else super
6665 end
6766 end
6867
6968 def get_type
70− if slug.end_with? 'selectors'
69+ if slug.end_with?('selectors')
7170 'Selectors'
72− elsif slug.start_with? ':'
73− PSEUDO_ELEMENT_SLUGS.include?(slug) ? 'Pseudo-elements' : 'Pseudo-classes'
74− elsif slug.start_with? '@'
71+ elsif slug.start_with?('::')
72+ 'Pseudo-elements'
73+ elsif slug.start_with?(':')
74+ 'Pseudo-classes'
75+ elsif slug.start_with?('@')
7576 'At-rules'
7677 elsif DATA_TYPE_SLUGS.include?(slug)
7778 'Data Types'
@@ -79,6 +80,8 @@ module Docs · 1 unmodified line
7980 'Functions'
8081 elsif VALUE_SLUGS.include?(slug)
8182 'Values'
83+ elsif slug =~ /\A[a-z]+_/i
84+ 'Miscellaneous'
8285 else
8386 'Properties'
8487 end
lib/docs/filters/dom/entries.rb+35−0
@@ -4,6 +4,7 @@ module Docs · 3 unmodified lines
44 TYPE_BY_SPEC = {
55 'Battery Status' => 'Battery Status',
66 'Canvas ' => 'Canvas',
7+ 'CSS Font Loading' => 'CSS',
78 'CSS Object Model' => 'CSS',
89 'Cryptography' => 'Web Cryptography',
910 'Device Orientation' => 'Device Orientation',
@@ -19,6 +20,8 @@ module Docs · 9 unmodified lines
1920 'Navigation Timing' => 'Navigation Timing',
2021 'Network Information' => 'Network Information',
2122 'Push API' => 'Push',
23+ 'Shadow DOM' => 'Shadow DOM',
24+ 'Server-Sent Events' => 'Server-Sent Events',
2225 'Service Workers' => 'Service Workers',
2326 'Web Animations' => 'Animation',
2427 'Web Audio' => 'Web Audio',
@@ -64,6 +67,8 @@ module Docs · 39 unmodified lines
6467 'StyleSheet' => 'CSS',
6568 'Stylesheet' => 'CSS',
6669 'SVG' => 'SVG',
70+ 'timing' => 'Navigation Timing',
71+ 'Timing' => 'Navigation Timing',
6772 'Touch' => 'Touch',
6873 'TreeWalker' => 'TreeWalker',
6974 'URL' => 'URL',
@@ -74,15 +79,22 @@ module Docs · 4 unmodified lines
7479 TYPE_BY_NAME_INCLUDES = {
7580 'ChildNode' => 'Node',
7681 'Crypto' => 'Web Cryptography',
82+ 'FormData' => 'XMLHTTPRequest',
83+ 'ImageBitmap' => 'Canvas',
7784 'ImageData' => 'Canvas',
7885 'IndexedDB' => 'IndexedDB',
86+ 'Media Source' => 'Media',
7987 'MediaStream' => 'Media',
8088 'NodeList' => 'Node',
8189 'Path2D' => 'Canvas',
90+ 'Server-sent' => 'Server-Sent Events',
8291 'ServiceWorker' => 'Service Workers',
8392 'TextMetrics' => 'Canvas',
8493 'udio' => 'Web Audio',
94+ 'WebSocket' => 'Web Sockets',
8595 'WebGL' => 'WebGL',
96+ 'WEBGL' => 'WebGL',
97+ 'WebRTC' => 'WebRTC',
8698 'WebVR' => 'WebVR',
8799 'Worker' => 'Web Workers' }
88100
@@ -111,6 +123,7 @@ module Docs · 22 unmodified lines
111123 name.sub! 'API.', 'API: '
112124 # Comment.Comment => Comment.constructor
113125 name.sub! %r{\A(\w+)\.\1\z}, '\1.constructor' unless name == 'window.window'
126+ name.prepend 'XMLHttpRequest.' if slug.start_with?('XMLHttpRequest/') && !name.start_with?('XMLHttpRequest')
114127 name
115128 end
116129
@@ -160,6 +173,28 @@ module Docs · 43 unmodified lines
160173 content = node.content
161174 SKIP_CONTENT.none? { |str| content.include?(str) }
162175 end
176+
177+ def additional_entries
178+ entries = []
179+
180+ if slug == 'history' || slug == 'XMLHttpRequest'
181+ css('dt a[title*="not yet been written"]').each do |node|
182+ next if node.parent.at_css('.obsolete')
183+ name = node.content.sub('History', 'history')
184+ id = node.parent['id'] = name.parameterize
185+ entries << [name, id]
186+ end
187+ end
188+
189+ if slug == 'XMLHttpRequest'
190+ css('h2[id="Methods_2"] ~ h3').each do |node|
191+ break if node.content == 'Non-standard methods'
192+ entries << ["#{name}.#{node.content}", node['id']]
193+ end
194+ end
195+
196+ entries
197+ end
163198 end
164199 end
165200 end
lib/docs/filters/dom_events/entries.rb+9−0
@@ -3,12 +3,15 @@ module Docs · 2 unmodified lines
33 class EntriesFilter < Docs::EntriesFilter
44 TYPE_BY_INFO = {
55 'applicationCache' => 'Application Cache',
6+ 'Battery' => 'Battery',
67 'Clipboard' => 'Clipboard',
78 'CSS' => 'CSS',
89 'Drag' => 'Drag & Drop',
910 'Focus' => 'Focus',
1011 'Fullscreen' => 'Fullscreen',
12+ 'Gamepad' => 'Gamepad',
1113 'HashChange' => 'History',
14+ 'IDB' => 'IndexedDB',
1215 'IndexedDB' => 'IndexedDB',
1316 'Keyboard' => 'Keyboard',
1417 'edia' => 'Media',
@@ -16,6 +19,7 @@ module Docs · 1 unmodified line
1619 'Offline' => 'Offline',
1720 'Orientation' => 'Device',
1821 'Sensor' => 'Device',
22+ 'SVG' => 'SVG',
1923 'Page Visibility' => 'Page Visibility',
2024 'Pointer' => 'Mouse',
2125 'PopState' => 'History',
@@ -29,6 +33,7 @@ module Docs · 7 unmodified lines
2933 'WebSocket' => 'WebSocket',
3034 'Web Audio' => 'Web Audio',
3135 'Web Messaging' => 'Web Messaging',
36+ 'WebRTC' => 'WebRTC',
3237 'Wheel' => 'Mouse',
3338 'Worker' => 'Web Workers' }
3439
@@ -61,6 +66,10 @@ module Docs · 26 unmodified lines
6166 'Miscellaneous'
6267 end
6368 end
69+
70+ def include_default_entry?
71+ !doc.content.include?('Firefox OS specific')
72+ end
6473 end
6574 end
6675 end
lib/docs/scrapers/mdn/dom.rb+1−1
@@ -54,7 +54,7 @@ module Docs · 53 unmodified lines
5454 /\A\/InstallTrigger/,
5555 /\A\/Entity/,
5656 /\A\/Settings/,
57− /\A\/Telephony/,
57+ /telephony/i,
5858 /\A\/NFC_API/,
5959 /\A\/Window\/\w+bar/i,
6060 /\A\/Apps/,
lib/docs/scrapers/mdn/dom_events.rb+1−0
@@ -10,6 +10,7 @@ module Docs · 9 unmodified lines
1010 options[:root_title] = 'DOM Events'
1111
1212 options[:skip] = %w(/MozOrientation)
13+ options[:skip_patterns] = [/\A\/moz/i]
1314
1415 options[:fix_urls] = ->(url) do
1516 url.sub! 'https://developer.mozilla.org/en-US/Mozilla_event_reference', DomEvents.base_url