From f7ec336112e23ebd39e55f1ac9bed20ed2724395 Mon Sep 17 00:00:00 2001 From: Thibaut Courouble Date: Sun, 2 Oct 2016 14:54:59 -0400 Subject: [PATCH] Update MDN docs Closes #476. --- assets/stylesheets/pages/_mdn.scss | 4 ++++ lib/docs/filters/css/clean_html.rb | 4 ++++ lib/docs/filters/css/entries.rb | 9 ++++++++- lib/docs/filters/dom/entries.rb | 10 +++++++--- lib/docs/filters/dom_events/clean_html.rb | 5 +---- lib/docs/filters/dom_events/entries.rb | 18 ++++++++++++------ lib/docs/filters/mdn/clean_html.rb | 2 +- lib/docs/scrapers/mdn/css.rb | 5 +++-- 8 files changed, 40 insertions(+), 17 deletions(-) diff --git a/assets/stylesheets/pages/_mdn.scss b/assets/stylesheets/pages/_mdn.scss index a55ad23e..b21604ed 100644 --- a/assets/stylesheets/pages/_mdn.scss +++ b/assets/stylesheets/pages/_mdn.scss @@ -22,9 +22,11 @@ > h2 { @extend %block-heading; } > h3 { @extend %block-label, %label-blue; } + > h4 { font-size: 1em; } > .note, .notice, + .warning, .overheadIndicator, .syntaxbox, // CSS, JavaScript .twopartsyntaxbox, // CSS @@ -33,6 +35,8 @@ @extend %note; } + .warning { @extend %note-red; } + > .note { em { font-style: normal; diff --git a/lib/docs/filters/css/clean_html.rb b/lib/docs/filters/css/clean_html.rb index 0ba5b044..f202f7c9 100644 --- a/lib/docs/filters/css/clean_html.rb +++ b/lib/docs/filters/css/clean_html.rb @@ -12,6 +12,10 @@ module Docs end def other + css('.syntaxbox > .syntaxbox').each do |node| + node.parent.before(node.parent.children).remove + end + # Remove "|" and "||" links in syntax box (e.g. animation, all, etc.) css('.syntaxbox', '.twopartsyntaxbox').css('a').each do |node| if node.content == '|' || node.content == '||' diff --git a/lib/docs/filters/css/entries.rb b/lib/docs/filters/css/entries.rb index e90d79fb..5fd670d7 100644 --- a/lib/docs/filters/css/entries.rb +++ b/lib/docs/filters/css/entries.rb @@ -42,7 +42,9 @@ module Docs end def get_type - if type = TYPE_BY_PATH[slug.split('/').first] + if slug.include?('-webkit') || slug.include?('-moz') + 'Extensions' + elsif type = TYPE_BY_PATH[slug.split('/').first] type elsif type = get_spec type.remove! 'CSS ' @@ -123,6 +125,11 @@ module Docs def additional_entries ADDITIONAL_ENTRIES[slug] || [] end + + def include_default_entry? + return true unless warning = at_css('.warning').try(:content) + !warning.include?('CSS Flexible Box') && !warning.include?('replaced in newer drafts') + end end end end diff --git a/lib/docs/filters/dom/entries.rb b/lib/docs/filters/dom/entries.rb index b18f018a..86f9f50b 100644 --- a/lib/docs/filters/dom/entries.rb +++ b/lib/docs/filters/dom/entries.rb @@ -23,9 +23,10 @@ module Docs 'Intersection' => 'Intersection Observer', 'Media Capture' => 'Media', 'Media Source' => 'Media', - 'MediaStream' => 'Stream', + 'MediaStream' => 'Media Streams', 'Navigation Timing' => 'Web Performance', 'Network Information' => 'Network Information', + 'Payment Request' => 'Payment Request', 'Performance Timeline' => 'Web Performance', 'Pointer Events' => 'Pointer Events', 'Push API' => 'Push', @@ -33,7 +34,8 @@ module Docs 'Shadow DOM' => 'Shadow DOM', 'Server-Sent Events' => 'Server-Sent Events', 'Service Workers' => 'Service Workers', - 'Stream API' => 'Stream', + 'Stream API' => 'Media Streams', + 'Streams' => 'Media Streams', 'Touch Events' => 'Touch Events', 'Web Animations' => 'Animation', 'Web App Manifest' => 'Web App Manifest', @@ -71,6 +73,7 @@ module Docs 'location' => 'Location', 'navigator' => 'Navigator', 'MediaQuery' => 'MediaQuery', + 'MediaTrack' => 'Media Streams', 'Node' => 'Node', 'Notification' => 'Notification', 'OffscreenCanvas' => 'Canvas', @@ -108,7 +111,8 @@ module Docs 'ImageData' => 'Canvas', 'IndexedDB' => 'IndexedDB', 'Media Source' => 'Media', - 'MediaStream' => 'Stream', + 'MediaStream' => 'Media Streams', + 'Media Streams' => 'Media Streams', 'NodeList' => 'Node', 'Path2D' => 'Canvas', 'Pointer' => 'Pointer Events', diff --git a/lib/docs/filters/dom_events/clean_html.rb b/lib/docs/filters/dom_events/clean_html.rb index 21ab5792..805870a8 100644 --- a/lib/docs/filters/dom_events/clean_html.rb +++ b/lib/docs/filters/dom_events/clean_html.rb @@ -7,11 +7,8 @@ module Docs end def root - # Remove parapraph mentioning non-standard events - at_css('#Standard_events').previous_element.remove - # Remove everything after "Standard events" - css('.standard-table ~ *').remove + css('#Non-standard_events', '#Non-standard_events ~ *').remove # Remove events we don't want css('tr').each do |tr| diff --git a/lib/docs/filters/dom_events/entries.rb b/lib/docs/filters/dom_events/entries.rb index e56f96cf..608caa9e 100644 --- a/lib/docs/filters/dom_events/entries.rb +++ b/lib/docs/filters/dom_events/entries.rb @@ -4,6 +4,7 @@ module Docs TYPE_BY_INFO = { 'applicationCache' => 'Application Cache', 'Battery' => 'Battery', + 'Call' => 'Telephony', 'Clipboard' => 'Clipboard', 'CSS' => 'CSS', 'Drag' => 'Drag & Drop', @@ -27,6 +28,7 @@ module Docs 'Push' => 'Push', 'Progress' => 'Progress', 'Proximity' => 'Device', + 'Selection' => 'Selection', 'Server Sent' => 'Server Sent Events', 'Speech' => 'Web Speech', 'Storage' => 'Web Storage', @@ -37,6 +39,7 @@ module Docs 'Web App Manifest' => 'Web App Manifest', 'Web Audio' => 'Web Audio', 'Web Messaging' => 'Web Messaging', + 'WebGL' => 'WebGL', 'WebRTC' => 'WebRTC', 'WebVR' => 'WebVR', 'Wheel' => 'Mouse', @@ -47,7 +50,7 @@ module Docs LOAD_SLUGS = %w(abort beforeunload DOMContentLoaded error load readystatechange unload) - APPEND_TYPE = %w(Application\ Cache IndexedDB Progress + APPEND_TYPE = %w(Application\ Cache IndexedDB Progress Telephony Server\ Sent\ Events WebSocket Web\ Messaging Web\ Workers) def get_name @@ -62,10 +65,9 @@ module Docs elsif LOAD_SLUGS.include?(slug) 'Load' else - if info = at_css('.eventinfo, .properties').try(:content) - TYPE_BY_INFO.each_pair do |key, value| - return value if info.include?(key) - end + info = css('.eventinfo, .properties, .standard-table').map(&:content).join + TYPE_BY_INFO.each_pair do |key, value| + return value if info.include?(key) end 'Miscellaneous' @@ -73,7 +75,11 @@ module Docs end def include_default_entry? - !doc.content.include?('Firefox OS specific') + content = doc.content + !content.include?('Firefox OS specific') && + !content.include?('Addons specific') && + !content.include?('Mozilla specific') && + content !~ /Specification\s+XUL/ end end end diff --git a/lib/docs/filters/mdn/clean_html.rb b/lib/docs/filters/mdn/clean_html.rb index d160a184..84829aba 100644 --- a/lib/docs/filters/mdn/clean_html.rb +++ b/lib/docs/filters/mdn/clean_html.rb @@ -21,7 +21,7 @@ module Docs node.name = 'th' end - css('nobr', 'span[style*="font"]', 'pre code').each do |node| + css('nobr', 'span[style*="font"]', 'pre code', 'h2 strong').each do |node| node.before(node.children).remove end diff --git a/lib/docs/scrapers/mdn/css.rb b/lib/docs/scrapers/mdn/css.rb index 870d8eee..348f0b59 100644 --- a/lib/docs/scrapers/mdn/css.rb +++ b/lib/docs/scrapers/mdn/css.rb @@ -10,7 +10,7 @@ module Docs options[:skip] = %w(/CSS3 /Media/Visual /paged_media) options[:skip] += %w(/mq-boolean /single-transition-timing-function) # bug - options[:skip_patterns] = [/\-webkit/, /\-moz/, /Extensions/, /Tools/] + options[:skip_patterns] = [/Extensions/, /Tools/, /@media\/-webkit/, /webkit-mask/, /-moz-system-metric/] options[:replace_paths] = { '/%3Cbasic-shape%3E' => '/basic-shape', @@ -18,7 +18,8 @@ module Docs '/range' => '/@counter-style/range', '/symbols' => '/@counter-style/symbols', '/system' => '/@counter-style/system', - '/var' => '/var()' + '/var' => '/var()', + '/Flexbox' => '/CSS_Flexible_Box_Layout/Using_CSS_flexible_boxes' } options[:fix_urls] = ->(url) do