From b035be3e2c625ed44d4d80131db4f75ee4e809b4 Mon Sep 17 00:00:00 2001 From: Thibaut Date: Sat, 8 Feb 2014 18:38:39 -0500 Subject: [PATCH] Update Less scraper (1.6.3) --- .../templates/pages/about_tmpl.coffee | 6 +- assets/stylesheets/pages/_less.scss | 12 +-- lib/docs/filters/less/clean_html.rb | 33 +++----- lib/docs/filters/less/entries.rb | 79 +++++++++++-------- lib/docs/scrapers/less.rb | 17 ++-- 5 files changed, 74 insertions(+), 73 deletions(-) diff --git a/assets/javascripts/templates/pages/about_tmpl.coffee b/assets/javascripts/templates/pages/about_tmpl.coffee index 03be6460..3d5e96d6 100644 --- a/assets/javascripts/templates/pages/about_tmpl.coffee +++ b/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', diff --git a/assets/stylesheets/pages/_less.scss b/assets/stylesheets/pages/_less.scss index 3baa31b2..57cb44d3 100644 --- a/assets/stylesheets/pages/_less.scss +++ b/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; } } diff --git a/lib/docs/filters/less/clean_html.rb b/lib/docs/filters/less/clean_html.rb index d246cdcc..8045e195 100644 --- a/lib/docs/filters/less/clean_html.rb +++ b/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 diff --git a/lib/docs/filters/less/entries.rb b/lib/docs/filters/less/entries.rb index 5e2fbda7..7de7cbf4 100644 --- a/lib/docs/filters/less/entries.rb +++ b/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 diff --git a/lib/docs/scrapers/less.rb b/lib/docs/scrapers/less.rb index 310b8ea9..d06404f6 100644 --- a/lib/docs/scrapers/less.rb +++ b/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 - © 2009–2014 Alexis Sellier & The Core Less Team
- Licensed under the Apache License v2.0. + © 2009–2014 The Core Less Team
+ Licensed under the Creative Commons Attribution License 3.0. HTML end end