From c382eaf3cbcb9d6160cec72d68474265292f7f64 Mon Sep 17 00:00:00 2001 From: Thibaut Courouble Date: Sun, 25 Feb 2018 10:15:53 -0500 Subject: [PATCH] Update Electron documentation (1.8.2) --- .../templates/pages/about_tmpl.coffee | 2 +- lib/docs/filters/electron/clean_html.rb | 12 ++++++++++-- lib/docs/filters/electron/entries.rb | 16 ++++++++-------- lib/docs/scrapers/electron.rb | 16 ++++++++-------- 4 files changed, 27 insertions(+), 19 deletions(-) diff --git a/assets/javascripts/templates/pages/about_tmpl.coffee b/assets/javascripts/templates/pages/about_tmpl.coffee index 44e0dbe2..39b33f4e 100644 --- a/assets/javascripts/templates/pages/about_tmpl.coffee +++ b/assets/javascripts/templates/pages/about_tmpl.coffee @@ -232,7 +232,7 @@ credits = [ 'https://api.drupal.org/api/drupal/LICENSE.txt' ], [ 'Electron', - '2013-2017 GitHub Inc.', + '2013-2018 GitHub Inc.', 'MIT', 'https://raw.githubusercontent.com/electron/electron/master/LICENSE' ], [ diff --git a/lib/docs/filters/electron/clean_html.rb b/lib/docs/filters/electron/clean_html.rb index 8699763c..820cc87f 100644 --- a/lib/docs/filters/electron/clean_html.rb +++ b/lib/docs/filters/electron/clean_html.rb @@ -4,7 +4,7 @@ module Docs def call css('.header-link', 'hr + .text-center', 'hr').remove - css('.grid', '.row', '.col-ms-12', 'ul.docs-list > ul.docs-list').each do |node| + css('.grid', '.row', '.col-ms-12', 'ul.docs-list > ul.docs-list', '.sub-section').each do |node| node.before(node.children).remove end @@ -16,18 +16,26 @@ module Docs end end - at_css('h2').name = 'h1' unless at_css('h1') + at_css('h2').name = 'h1' if !at_css('h1') && at_css('h2') css('h3', 'h4', 'h5').each do |node| node.name = node.name.sub(/\d/) { |i| i.to_i - 1 } unless node.name == 'h3' && node.at_css('code') end if !at_css('h2') && at_css('h4') + css('h1 > a', 'h2 > a', 'h3 > a', 'h4 > a').each do |node| + node.before(node.children).remove + end + css('div.highlighter-rouge').each do |node| node['data-language'] = node['class'][/language-(\w+)/, 1] if node['class'] node.content = node.content.strip node.name = 'pre' end + css('pre > code.hljs').each do |node| + node.parent['data-language'] = node['class'][/language-(\w+)/, 1] + end + css('.highlighter-rouge').remove_attr('class') css('pre').each do |node| diff --git a/lib/docs/filters/electron/entries.rb b/lib/docs/filters/electron/entries.rb index 0f56e7e1..e6b5540c 100644 --- a/lib/docs/filters/electron/entries.rb +++ b/lib/docs/filters/electron/entries.rb @@ -2,6 +2,8 @@ module Docs class Electron class EntriesFilter < Docs::EntriesFilter def get_name + return 'API' if subpath == '/api' + name = at_css('h1, h2').content name.remove! 'Class: ' name.remove! ' Object' @@ -12,11 +14,13 @@ module Docs end def get_type - if subpath.start_with?('tutorial') || slug.in?(%w(glossary/ faq/)) + return 'API' if subpath == '/api' + + if subpath.start_with?('/tutorial') || subpath.in?(%w(/glossary /faq)) 'Guides' - elsif subpath.start_with?('development') + elsif subpath.start_with?('/development') 'Guides: Development' - elsif slug.in?(%w(api/synopsis/ api/chrome-command-line-switches/)) + elsif subpath.in?(%w(/api/synopsis /api/chrome-command-line-switches)) 'API' elsif at_css('h1, h2').content.include?(' Object') 'API: Objects' @@ -26,7 +30,7 @@ module Docs end def additional_entries - return [] unless slug.start_with?('api/') + return [] unless subpath.start_with?('/api') css('h3 > code', 'h4 > code').each_with_object [] do |node, entries| next if node.previous.try(:content).present? || node.next.try(:content).present? @@ -37,10 +41,6 @@ module Docs entries << [name, node.parent['id']] unless name == self.name end end - - def include_default_entry? - slug != 'api/' - end end end end diff --git a/lib/docs/scrapers/electron.rb b/lib/docs/scrapers/electron.rb index 96f0b9b2..86c82ed5 100644 --- a/lib/docs/scrapers/electron.rb +++ b/lib/docs/scrapers/electron.rb @@ -1,25 +1,25 @@ module Docs class Electron < UrlScraper self.type = 'electron' - self.base_url = 'https://electron.atom.io/docs/' - self.release = '1.7.9' + self.base_url = 'https://electronjs.org/docs' + self.release = '1.8.2' self.links = { - home: 'https://electron.atom.io/', + home: 'https://electronjs.org/', code: 'https://github.com/electron/electron' } html_filters.push 'electron/clean_html', 'electron/entries' - options[:trailing_slash] = true + options[:trailing_slash] = false options[:container] = '.page-section > .container, .page-section > .container-narrow' - options[:skip] = %w(guides/ development/ tutorial/ versions/ all/) + options[:skip] = %w(guides development tutorial versions all) + options[:skip_patterns] = [/\/history\z/] options[:replace_paths] = { - 'api/web-view-tag/' => 'api/webview-tag/', - 'api/web-view-tag' => 'api/webview-tag/' + 'api/web-view-tag' => 'api/webview-tag' } options[:attribution] = <<-HTML - © 2013–2017 GitHub Inc.
+ © 2013–2018 GitHub Inc.
Licensed under the MIT license. HTML end