1
0
Эх сурвалжийг харах

Add webpack 2 documentation

Thibaut Courouble 9 жил өмнө
parent
commit
bfe83138e3

BIN
assets/images/docs.png


BIN
assets/images/docs@2x.png


+ 3 - 3
assets/javascripts/templates/pages/about_tmpl.coffee

@@ -590,10 +590,10 @@ credits = [
     'MIT',
     'https://raw.githubusercontent.com/vuejs/vue/master/LICENSE'
   ], [
-    'Webpack',
+    'webpack',
     '2012-2016 Tobias Koppers',
-    'MIT',
-    'https://raw.githubusercontent.com/webpack/webpack/master/LICENSE'
+    'CC BY',
+    'https://creativecommons.org/licenses/by/4.0/'
   ], [
     'Yarn',
     '2016-2017 Yarn Contributors',

+ 1 - 0
assets/stylesheets/application-dark.css.scss

@@ -92,5 +92,6 @@
         'pages/underscore',
         'pages/vagrant',
         'pages/vue',
+        'pages/webpack',
         'pages/yard',
         'pages/yii';

+ 1 - 0
assets/stylesheets/application.css.scss

@@ -92,5 +92,6 @@
         'pages/underscore',
         'pages/vagrant',
         'pages/vue',
+        'pages/webpack',
         'pages/yard',
         'pages/yii';

+ 1 - 1
assets/stylesheets/global/_icons.scss

@@ -139,7 +139,7 @@
 ._icon-npm:before           { background-position: -8rem -7rem; }
 ._icon-apache_http_server:before { background-position: -9rem -7rem; }
 ._icon-drupal:before        { background-position: 0 -8rem; }
-._icon-webpack:before       { background-position: -1rem -8rem; @extend %darkIconFix !optional; }
+._icon-webpack:before       { background-position: -1rem -8rem; }
 ._icon-phaser:before        { background-position: -2rem -8rem; }
 ._icon-vue:before           { background-position: -3rem -8rem; }
 ._icon-opentsdb:before      { background-position: -4rem -8rem; }

+ 1 - 2
assets/stylesheets/pages/_simple.scss

@@ -12,7 +12,7 @@
     h1, h2, h3 { margin-left: 0; }
   }
 
-  p > code, li > code, td > code { @extend %label; }
+  p > code, li > code, td > code, blockquote > code { @extend %label; }
   blockquote { @extend %note; }
   blockquote > h4, blockquote > h5 { margin-top: .25rem; }
 }
@@ -37,7 +37,6 @@
 ._redux,
 ._sinon,
 ._typescript,
-._webpack,
 ._yarn {
   @extend %simple;
 }

+ 5 - 0
assets/stylesheets/pages/_webpack.scss

@@ -0,0 +1,5 @@
+._webpack {
+  @extend %simple;
+
+  blockquote.tip { @extend %note-blue; }
+}

+ 24 - 22
lib/docs/filters/webpack/clean_html.rb

@@ -2,37 +2,39 @@ module Docs
   class Webpack
     class CleanHtmlFilter < Filter
       def call
-        root_page? ? root : other
-        doc
-      end
+        @doc = at_css('.page__content')
 
-      def root
-        @doc = at_css(".container > .row > .col-md-9")
+        at_css('h1').content = 'webpack' if root_page?
 
-        # Remove all introdcution before the hr,
-        # The introduction about the documentation site which isn't relevant
-        # in devdocs.
-        hr_index = doc.children.find_index { |node| node.name == "hr" }
-        doc.children[0..hr_index].each(&:remove)
-      end
+        css('h3').each do |node|
+          node.name = 'h2'
+        end unless at_css('h2')
 
-
-      def other
-        css('h1, h2, h3, h4').each do |node|
-          node.name = node.name.sub(/\d/) { |i| i.to_i + 1 }
+        css('.anchor[id]').each do |node|
+          node.parent['id'] = node['id']
+          node.remove
         end
 
-        # Re-create the header element
-        at_css("#wiki").child.before("<h1>#{at_css("#wikititle").content.titleize}</h1>")
+        css('hr', '.page__edit', 'hr + h3:contains("Contributors")', 'hr + h2:contains("Contributors")',
+            '.contributors', '.icon-link', '#maintainers.header', '#maintainers.header + table',
+            '#maintainer.header', '#maintainer.header + table').remove
 
-        @doc = at_css("#wiki")
+        css('> div', '.tip-content', '.header span').each do |node|
+          node.before(node.children).remove
+        end
 
-        css('.contents', 'a.anchor', 'hr').remove
+        css('> h1:first-child + h1').remove
 
-        css('pre').each do |node|
-          node.content = node.content
-          node['data-language'] = 'javascript'
+        css('.code-details-summary-span').each do |node|
+          node.content = node.content.remove(' (click to show)')
         end
+
+        css('pre > code').each do |node|
+          node.parent['data-language'] = node['class'][/lang-(\w+)/, 1].sub('jsx', 'js') if node['class']
+          node.parent.content = node.parent.content
+        end
+
+        doc
       end
     end
   end

+ 39 - 0
lib/docs/filters/webpack/clean_html_old.rb

@@ -0,0 +1,39 @@
+module Docs
+  class Webpack
+    class CleanHtmlOldFilter < Filter
+      def call
+        root_page? ? root : other
+        doc
+      end
+
+      def root
+        @doc = at_css(".container > .row > .col-md-9")
+
+        # Remove all introdcution before the hr,
+        # The introduction about the documentation site which isn't relevant
+        # in devdocs.
+        hr_index = doc.children.find_index { |node| node.name == "hr" }
+        doc.children[0..hr_index].each(&:remove)
+      end
+
+
+      def other
+        css('h1, h2, h3, h4').each do |node|
+          node.name = node.name.sub(/\d/) { |i| i.to_i + 1 }
+        end
+
+        # Re-create the header element
+        at_css("#wiki").child.before("<h1>#{at_css("#wikititle").content.titleize}</h1>")
+
+        @doc = at_css("#wiki")
+
+        css('.contents', 'a.anchor', 'hr').remove
+
+        css('pre').each do |node|
+          node.content = node.content
+          node['data-language'] = 'javascript'
+        end
+      end
+    end
+  end
+end

+ 27 - 17
lib/docs/filters/webpack/entries.rb

@@ -2,28 +2,38 @@ module Docs
   class Webpack
     class EntriesFilter < Docs::EntriesFilter
       def get_name
-        entry_link.content
+        name = at_css('h1').content
+        name.sub! ' - ', ': '
+        name
       end
 
-      def get_type
-        link_li = entry_link.parent
-        type_links_list = link_li.parent
-        current_type = type_links_list.parent
+      TYPE_BY_DIRECTORY = {
+        'get-started'   => 'Getting Started',
+        'concepts'      => 'Concepts',
+        'guides'        => 'Guides',
+        'api'           => 'API',
+        'configuration' => 'Configuration',
+        'loaders'       => 'Loaders',
+        'plugins'       => 'Plugins'
+      }
 
-        # current type is a
-        # <li>
-        #   TYPE
-        #   <li> <ul> .. links .. </ul> </li>
-        # </li>
-        #
-        # Grab the first children (which is the text nodes whose contains the type)
-        current_type.children.first.content.strip.titleize
+      def get_type
+        TYPE_BY_DIRECTORY[slug.split('/').first]
       end
 
-      private
-
-      def entry_link
-        at_css("a[href='#{self.path}']")
+      def additional_entries
+        if slug.start_with?('configuration')
+          css('h2[id] code').map do |node|
+            [node.content, node.parent['id']]
+          end
+        elsif slug.start_with?('api')
+          css('.header[id] code').each_with_object [] do |node, entries|
+            next if node.previous.try(:content).present?
+            entries << ["#{self.name}: #{node.content.sub(/\(.*\)/, '()')}", node.parent['id']]
+          end
+        else
+          []
+        end
       end
     end
   end

+ 31 - 0
lib/docs/filters/webpack/entries_old.rb

@@ -0,0 +1,31 @@
+module Docs
+  class Webpack
+    class EntriesOldFilter < Docs::EntriesFilter
+      def get_name
+        entry_link.content
+      end
+
+      def get_type
+        link_li = entry_link.parent
+        type_links_list = link_li.parent
+        current_type = type_links_list.parent
+
+        # current type is a
+        # <li>
+        #   TYPE
+        #   <li> <ul> .. links .. </ul> </li>
+        # </li>
+        #
+        # Grab the first children (which is the text nodes whose contains the type)
+        current_type.children.first.content.strip.titleize
+      end
+
+      private
+
+      def entry_link
+        at_css("a[href='#{self.path}']")
+      end
+    end
+  end
+end
+

+ 63 - 14
lib/docs/scrapers/webpack.rb

@@ -2,23 +2,72 @@ module Docs
   class Webpack < UrlScraper
     self.name = 'webpack'
     self.type = 'webpack'
-    self.release = '1.13.2'
-    self.base_url = 'https://webpack.github.io/docs/'
-    self.links = {
-      home: 'https://webpack.github.io/',
-      code: 'https://github.com/webpack/webpack'
-    }
 
-    html_filters.push 'webpack/entries', 'webpack/clean_html', 'title'
+    version '2' do
+      self.release = '2.2.0'
+      self.base_url = 'https://webpack.js.org/'
+      self.root_path = 'get-started/'
+      self.initial_paths = %w(
+        concepts/
+        guides/
+        api/
+        configuration/
+        loaders/
+        plugins/
+      )
+      self.links = {
+        home: 'https://webpack.js.org/',
+        code: 'https://github.com/webpack/webpack'
+      }
 
-    options[:title] = false
-    options[:root_title] = 'webpack'
+      html_filters.push 'webpack/clean_html', 'webpack/entries'
 
-    options[:skip] = %w(list-of-tutorials.html examples.html changelog.html ideas.html roadmap.html)
+      options[:container] = '.page'
+      options[:trailing_slash] = true
+      options[:only_patterns] = [
+        /\Aget-started\//,
+        /\Aconcepts\//,
+        /\Aguides\//,
+        /\Aapi\//,
+        /\Aconfiguration\//,
+        /\Aloaders\//,
+        /\Aplugins\//
+      ]
 
-    options[:attribution] = <<-HTML
-      &copy; 2012&ndash;2016 Tobias Koppers<br>
-      Licensed under the MIT License.
-    HTML
+      options[:attribution] = <<-HTML
+        &copy; 2012&ndash;2016 Tobias Koppers<br>
+        Licensed under the Creative Commons Attribution License 4.0.
+      HTML
+
+      ([self.root_path] + self.initial_paths).each do |path|
+        stub(path) do
+          capybara = load_capybara_selenium
+          capybara.app_host = self.base_url.origin
+          capybara.visit("#{self.base_url}#{path}")
+          capybara.execute_script('return document.body.innerHTML')
+        end
+      end
+    end
+
+    version '1' do
+      self.release = '1.13.2'
+      self.base_url = 'https://webpack.github.io/docs/'
+      self.links = {
+        home: 'https://webpack.github.io/',
+        code: 'https://github.com/webpack/webpack'
+      }
+
+      html_filters.push 'webpack/entries_old', 'webpack/clean_html_old', 'title'
+
+      options[:title] = false
+      options[:root_title] = 'webpack'
+
+      options[:skip] = %w(list-of-tutorials.html examples.html changelog.html ideas.html roadmap.html)
+
+      options[:attribution] = <<-HTML
+        &copy; 2012&ndash;2016 Tobias Koppers<br>
+        Licensed under the MIT License.
+      HTML
+    end
   end
 end

BIN
public/icons/docs/webpack/16.png


BIN
public/icons/docs/webpack/16@2x.png


+ 1 - 0
public/icons/docs/webpack/SOURCE

@@ -0,0 +1 @@
+https://github.com/webpack/media