From 35df0414dcbf9d458314a82002004c32f93d8153 Mon Sep 17 00:00:00 2001 From: Thibaut Courouble Date: Sat, 6 Feb 2016 15:56:07 -0500 Subject: [PATCH] Update JavaScript documentation Closes #332. --- lib/docs/filters/javascript/entries.rb | 18 +++++++++++++++--- lib/docs/filters/mdn/clean_html.rb | 3 ++- lib/docs/scrapers/mdn/javascript.rb | 7 +++++-- 3 files changed, 22 insertions(+), 6 deletions(-) diff --git a/lib/docs/filters/javascript/entries.rb b/lib/docs/filters/javascript/entries.rb index c5cf6c7f..e1110589 100644 --- a/lib/docs/filters/javascript/entries.rb +++ b/lib/docs/filters/javascript/entries.rb @@ -1,15 +1,16 @@ module Docs class Javascript class EntriesFilter < Docs::EntriesFilter - TYPES = %w(Array ArrayBuffer Boolean DataView Date Function Intl JSON Map - Math Number Object Promise RegExp Set SIMD String Symbol TypedArray - WeakMap WeakSet) + TYPES = %w(Array ArrayBuffer Atomics Boolean DataView Date Function + Generator Intl JSON Map Math Number Object Promise Reflect RegExp + Set SharedArrayBuffer SIMD String Symbol TypedArray WeakMap WeakSet) INTL_OBJECTS = %w(Collator DateTimeFormat NumberFormat) def get_name if slug.start_with? 'Global_Objects/' name, method, *rest = *slug.sub('Global_Objects/', '').split('/') name.prepend 'Intl.' if INTL_OBJECTS.include?(name) + name.prepend 'SIMD.' if html.include?("SIMD.#{name}") if method unless method == method.upcase || method == 'NaN' @@ -18,6 +19,15 @@ module Docs name << ".#{([method] + rest).join('.')}" end + if name.exclude?('.prototype') + path = name.split('.') + if ((node = at_css('.syntaxbox') || at_css('code')) && node.content =~ /(?:\s|\A)[a-z\_][a-zA-Z\_]+\.#{path.last}/) || + ((node = at_css('.standard-table')) && node.content =~ /\.prototype[\[\.]#{path.last}/) + path[-2] = path[-2][0].downcase + path[-2][1..-1] + name = path.join('.') + end + end + name else name = super @@ -45,6 +55,8 @@ module Docs 'Errors' elsif INTL_OBJECTS.include?(object) 'Intl' + elsif name.start_with?('SIMD') + 'SIMD' elsif method || TYPES.include?(object) object else diff --git a/lib/docs/filters/mdn/clean_html.rb b/lib/docs/filters/mdn/clean_html.rb index 80a3c675..a53fddd6 100644 --- a/lib/docs/filters/mdn/clean_html.rb +++ b/lib/docs/filters/mdn/clean_html.rb @@ -7,7 +7,8 @@ module Docs '.breadcrumbs', # (e.g. CSS/animation) '.Quick_links', # (e.g. CSS/animation) '.todo', - '.draftHeader'] + '.draftHeader', + '.hidden'] def call css(*REMOVE_NODES).remove diff --git a/lib/docs/scrapers/mdn/javascript.rb b/lib/docs/scrapers/mdn/javascript.rb index 20199344..b302de06 100644 --- a/lib/docs/scrapers/mdn/javascript.rb +++ b/lib/docs/scrapers/mdn/javascript.rb @@ -12,7 +12,6 @@ module Docs /About /Code_comments /Deprecated_Features - /Deprecated_and_obsolete_features /Functions_and_function_scope /Global_Objects/Iterator /Global_Objects/Proxy @@ -35,7 +34,11 @@ module Docs /Operators /Statements) - options[:skip_patterns] = [/additional_examples/i, /noSuchMethod/i] + options[:skip_patterns] = [ + /additional_examples/i, + /noSuchMethod/i, + /Deprecated_and_obsolete_features/ + ] options[:fix_urls] = ->(url) do url.sub! 'https://developer.mozilla.org/en-US/docs/JavaScript/Reference', Javascript.base_url