Update Less scraper (1.6.3)

pull/62/merge
Thibaut 11 years ago
parent bc95cfdbfa
commit b035be3e2c

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

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

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

@ -1,48 +1,61 @@
module Docs module Docs
class Less class Less
class EntriesFilter < Docs::EntriesFilter class EntriesFilter < Docs::EntriesFilter
SKIP_NAMES = ['Parametric Mixins', 'Mixins With Multiple Parameters', def name
'Return Values', 'Unlocking Mixins', 'Media Queries as Variables'] at_css('h1').content
end
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? def type
false root_page? ? 'Language' : nil
end end
def additional_entries def additional_entries
root_page? ? language_entries : function_entries
end
def language_entries
entries = [] entries = []
type = ''
css('> [id]').each do |node| css('h1').each do |node|
if node.name == 'h2' name = node.content
type = node.content.strip entries << [name, node['id']] unless name == 'Overview'
type.sub! 'The Language', 'Language'
type.sub! 'functions', 'Functions'
next
end end
# Skip function categories (e.g. "Color definition") css('h2[id^="import-options-"]').each do |node|
next if node.name == 'h3' && type != 'Language' 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] def function_entries
name.gsub!(/ [A-Z]/) { |str| str.downcase! } entries = []
type = nil
entries << ['~', node['id'], type] if name == 'e' css('.docs-section').each do |section|
entries << [name, node['id'], type] 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 end
entries entries

@ -1,18 +1,21 @@
module Docs module Docs
class Less < UrlScraper class Less < UrlScraper
self.type = 'less' self.type = 'less'
self.version = '1.6.0' self.version = '1.6.3'
self.base_url = 'http://lesscss.org' 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[:title] = 'Less'
options[:container] = 'section' options[:container] = 'div[role=main]'
options[:skip_links] = true options[:follow_links] = false
options[:trailing_slash] = false
options[:attribution] = <<-HTML options[:attribution] = <<-HTML
&copy; 2009&ndash;2014 Alexis Sellier &amp; The Core Less Team<br> &copy; 2009&ndash;2014 The Core Less Team<br>
Licensed under the Apache License v2.0. Licensed under the Creative Commons Attribution License 3.0.
HTML HTML
end end
end end

Loading…
Cancel
Save