Ver Fonte

Update Less scraper (1.6.3)

Thibaut há 12 anos atrás
pai
commit
b035be3e2c

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

@@ -135,9 +135,9 @@ credits = [
     'https://raw.github.com/knockout/knockout/master/LICENSE'
   ], [
     'Less',
-    '2009-2014 Alexis Sellier & The Core Less Team',
-    'Apache v2',
-    'https://raw.github.com/less/less.js/master/LICENSE'
+    '2009-2014 The Core Less Team',
+    'CC BY',
+    'http://creativecommons.org/licenses/by/3.0/'
   ], [
     'Lo-Dash',
     '2009-2013 The Dojo Foundation',

+ 4 - 8
assets/stylesheets/pages/_less.scss

@@ -1,12 +1,8 @@
 ._less {
   padding-left: 1rem;
 
-  > h1, > h2, > h3 { margin-left: -1rem; }
-  > h2, > h3 { @extend %block-heading; }
-  > h4 { margin-top: 2em; }
-
-  > .function {
-    margin-left: -1rem;
-    @extend %block-label, %label-blue;
-  }
+  > h1, > h2, h3, h4 { margin-left: -1rem; }
+  > h2 { @extend %block-heading; }
+  h3, h4 { @extend %block-label, %label-blue; }
+  code { @extend %label; }
 }

+ 11 - 22
lib/docs/filters/less/clean_html.rb

@@ -2,37 +2,26 @@ module Docs
   class Less
     class CleanHtmlFilter < Filter
       def call
-        # Remove everything but language and function reference
-        doc.children = css('#docs', '#reference').children
+        css('.source-link').remove
 
-        # Change headings
-        css('h1', 'h2', 'h3').each do |node|
-          node.name = "h#{node.name.last.to_i + 1}"
-          node['id'] ||= node.content.strip.parameterize
+        css('#functions-overview').each do |node|
+          node.ancestors('.docs-section').remove
         end
 
-        # Remove .content div
-        css('.content').each do |node|
-          node.before(node.elements)
-          node.remove
+        css('.docs-section', 'blockquote').each do |node|
+          node.before(node.children).remove
         end
 
-        # Remove function index
-        css('#function-reference').each do |node|
-          while node.next.content.strip != 'String functions'
-            node.next.remove
-          end
+        css('.page-header').each do |node|
+          node.before(node.first_element_child).remove
         end
 
-        # Remove duplicates
-        [css('[id="unit"]').last, css('[id="color"]').last].each do |node|
-          node.next.remove while %w(h2 h3 h4).exclude?(node.next.name)
-          node.remove
+        css('h1, h2, h3, h4').each do |node|
+          node.name = node.name.sub(/\d/) { |i| i.to_i + 1 }
         end
 
-        # Differentiate function headings
-        css('#function-reference ~ h4').each do |node|
-          node['class'] = 'function'
+        css('pre').each do |node|
+          node.content = node.content
         end
 
         doc

+ 46 - 33
lib/docs/filters/less/entries.rb

@@ -1,48 +1,61 @@
 module Docs
   class Less
     class EntriesFilter < Docs::EntriesFilter
-      SKIP_NAMES = ['Parametric Mixins', 'Mixins With Multiple Parameters',
-        'Return Values', 'Unlocking Mixins', 'Media Queries as Variables']
-
-      REPLACE_NAMES = {
-        'The @arguments variable'                   => '@arguments',
-        'Advanced arguments and the @rest variable' => '@rest',
-        'The Keyword !important'                    => '!important',
-        'Pattern-matching and Guard expressions'    => 'Pattern-matching',
-        'Advanced Usage of &'                       => '&',
-        'Importing'                                 => '@import',
-        'JavaScript evaluation'                     => 'JavaScript',
-        '% format'                                  => '%'
-      }
-
-      def include_default_entry?
-        false
+      def name
+        at_css('h1').content
+      end
+
+      def type
+        root_page? ? 'Language' : nil
       end
 
       def additional_entries
+        root_page? ? language_entries : function_entries
+      end
+
+      def language_entries
         entries = []
-        type = ''
-
-        css('> [id]').each do |node|
-          if node.name == 'h2'
-            type = node.content.strip
-            type.sub! 'The Language', 'Language'
-            type.sub! 'functions', 'Functions'
-            next
-          end
 
-          # Skip function categories (e.g. "Color definition")
-          next if node.name == 'h3' && type != 'Language'
+        css('h1').each do |node|
+          name = node.content
+          entries << [name, node['id']] unless name == 'Overview'
+        end
+
+        css('h2[id^="import-options-"]').each do |node|
+          entries << ["@import #{node.content}", node['id']]
+        end
 
-          name = node.content.strip
+        entries.concat [
+          ['@var',              'variables-feature'],
+          ['@{} interpolation', 'variables-feature-variable-interpolation'],
+          ['url()',             'variables-feature-urls'],
+          ['@property',         'variables-feature-properties'],
+          ['@@var',             'variables-feature-variable-names'],
+          [':extend()',         'extend-feature'],
+          [':extend(all)',      'extend-feature-extend-quotallquot'],
+          ['@arguments',        'mixins-parametric-feature-the-codeargumentscode-variable'],
+          ['@rest',             'mixins-parametric-feature-advanced-arguments-and-the-coderestcode-variable'],
+          ['@import',           'import-directives-feature'],
+          ['when',              'mixin-guards-feature'],
+          ['.loop()',           'loops-feature'],
+          ['+:',                'merge-feature'] ]
 
-          next if SKIP_NAMES.include?(name)
+        entries
+      end
 
-          name = REPLACE_NAMES[name] if REPLACE_NAMES[name]
-          name.gsub!(/ [A-Z]/) { |str| str.downcase! }
+      def function_entries
+        entries = []
+        type = nil
 
-          entries << ['~', node['id'], type] if name == 'e'
-          entries << [name, node['id'], type]
+        css('.docs-section').each do |section|
+          if title = section.at_css('h1')
+            type = title.content
+            type.sub! %r{(\w+) Functions}, 'Functions: \1'
+          end
+
+          section.css('h3').each do |node|
+            entries << [node.content, node['id'], type]
+          end
         end
 
         entries

+ 10 - 7
lib/docs/scrapers/less.rb

@@ -1,18 +1,21 @@
 module Docs
   class Less < UrlScraper
     self.type = 'less'
-    self.version = '1.6.0'
+    self.version = '1.6.3'
     self.base_url = 'http://lesscss.org'
+    self.root_path = '/features'
+    self.initial_paths = %w(/functions)
 
-    html_filters.push 'less/clean_html', 'less/entries', 'title'
+    html_filters.push 'less/entries', 'less/clean_html', 'title'
 
-    options[:title] = 'LESS'
-    options[:container] = 'section'
-    options[:skip_links] = true
+    options[:title] = 'Less'
+    options[:container] = 'div[role=main]'
+    options[:follow_links] = false
+    options[:trailing_slash] = false
 
     options[:attribution] = <<-HTML
-      &copy; 2009&ndash;2014 Alexis Sellier &amp; The Core Less Team<br>
-      Licensed under the Apache License v2.0.
+      &copy; 2009&ndash;2014 The Core Less Team<br>
+      Licensed under the Creative Commons Attribution License 3.0.
     HTML
   end
 end