Jed Fox %!s(int64=7) %!d(string=hai) anos
pai
achega
1f2030de24

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

@@ -35,6 +35,7 @@
         'pages/angularjs',
         'pages/apache',
         'pages/async',
+        'pages/babel',
         'pages/bootstrap',
         'pages/c',
         'pages/cakephp',

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

@@ -35,6 +35,7 @@
         'pages/angularjs',
         'pages/apache',
         'pages/async',
+        'pages/babel',
         'pages/bootstrap',
         'pages/c',
         'pages/cakephp',

+ 10 - 0
assets/stylesheets/pages/_babel.scss

@@ -0,0 +1,10 @@
+._babel {
+  @extend %simple;
+  ._note {
+    h1, h2, h3, h4, h5, h6 {
+      &:first-child {
+        margin: 0.5em 0;
+      }
+    }
+  }
+}

+ 76 - 0
lib/docs/filters/babel/clean_html.rb

@@ -0,0 +1,76 @@
+module Docs
+  class Babel
+    class CleanHtmlFilter < Filter
+      def call
+        css('.btn-clipboard').remove
+
+        css('div.highlighter-rouge').each do |node|
+          pre = node.at_css('pre')
+
+          # copy over the highlighting metadata
+          match = /language-(\w+)/.match(node['class'])
+          if match
+            lang = match[1]
+            if lang == 'sh'
+              lang = 'bash'
+            end
+            pre['class'] = nil
+            pre['data-language'] = lang
+          end
+
+          # Remove the server-rendered syntax highlighting
+          code = pre.at_css('code')
+          code.content = code.text
+
+          # Remove the div.highlighter-rouge and div.highlight wrapping the <pre>
+          node.add_next_sibling pre
+          node.remove
+        end
+
+
+        css('blockquote').each do |node|
+          node.name = 'div'
+          node['class'] = '_note'
+        end
+
+        css((1..6).map { |n| "h#{n}" }).each do |header|
+          return unless header.at_css('a')
+          header.content = header.at_css('a').content
+        end
+
+
+        header = doc # .docs-content
+          .parent # .row
+          .parent # .container
+          .previous_element # .docs_header
+
+        toc = doc # .docs-content
+          .parent # .row
+          .at_css('.sidebar')
+        toc['class'] = '_toc'
+        toc.css('a').each do |a|
+          a['class'] = '_toc-link'
+          a.parent.remove if a.content == 'Community Discussion'
+        end
+        toc.css('ul').attr 'class', '_toc-list'
+
+        h1 = header.at_css('h1')
+        h1.content = h1.content
+          .titleize
+          .sub(/\bEnv\b/, 'env')
+          .sub(/\.[A-Z]/) { |s| s.downcase }
+          .sub(/\.babelrc/i, '.babelrc')
+          .sub('Common Js', 'CommonJS')
+          .sub('J Script', 'JScript')
+          .sub(/regexp/i, 'RegExp')
+          .sub(/api|Es(\d+)|cli|jsx?|[au]md/i) { |s| s.upcase }
+
+        doc.children.before toc
+        doc.children.before header.at_css 'p'
+        doc.children.before h1
+
+        doc
+      end
+    end
+  end
+end

+ 31 - 0
lib/docs/filters/babel/entries.rb

@@ -0,0 +1,31 @@
+module Docs
+  class Babel
+    class EntriesFilter < Docs::EntriesFilter
+      def get_name
+        at_css('h1').content.sub /^(minify|syntax)|(transform|preset)$/i, ''
+      end
+
+      def get_type
+        if subpath.start_with? 'plugins/preset'
+          'Presets'
+        elsif subpath.start_with? 'plugins/transform'
+          'Transform Plugins'
+        elsif subpath.start_with? 'plugins/minify'
+          'Minification'
+        elsif subpath.start_with? 'plugins/syntax'
+          'Syntax Plugins'
+        elsif subpath.start_with? 'plugins'
+          'Plugins'
+        elsif subpath.start_with? 'usage/'
+          'Usage'
+        else
+          'Docs'
+        end
+      end
+
+      def path
+        super
+      end
+    end
+  end
+end

+ 31 - 0
lib/docs/scrapers/babel.rb

@@ -0,0 +1,31 @@
+module Docs
+  class Babel < UrlScraper
+    self.type = 'babel'
+    self.base_url = 'http://babeljs.io/docs/'
+    self.root_path = '/plugins/'
+    self.release = '6.26.0'
+    self.initial_paths = %w[faq tour usage/babel-register core-packages editors usage/caveats]
+    self.links = {
+      home: 'https://babeljs.io/',
+      code: 'https://github.com/babel/babel'
+    }
+
+    html_filters.push 'babel/clean_html', 'babel/entries'
+
+    options[:trailing_slash] = true
+    options[:container] = '.docs-content'
+    options[:skip] = %w{setup/ community/videos/}
+    options[:fix_urls] = ->(url) do
+      return url unless url.start_with? self.base_url
+      url.sub %r{/(index\.\w+)?$}, ''
+    end
+
+    options[:attribution] = <<-HTML
+      &copy; 2018 Sebastian McKenzie<br>
+      Licensed under the
+      <a href="https://github.com/babel/website/blob/master/LICENSE">
+        MIT License
+      </a>
+    HTML
+  end
+end