Update CSS documentation

Fixes #330. Closes #302.
pull/343/merge
Thibaut Courouble 9 years ago
parent f681391ead
commit 28e693d665

@ -1,6 +1,18 @@
module Docs
class Css
class EntriesFilter < Docs::EntriesFilter
TYPE_BY_PATH = {
'CSS_Animations' => 'Animations & Transitions',
'CSS_Background_and_Borders' => 'Backgrounds & Borders',
'CSS_Columns' => 'Multi-column Layout',
'CSS_Flexible_Box_Layout' => 'Flexible Box Layout',
'CSS_Images' => 'Image Values',
'CSS_Lists_and_Counters' => 'Lists & Counters',
'CSS_Transforms' => 'Transforms',
'Media_Queries' => 'Media Queries',
'transform-function' => 'Transforms'
}
DATA_TYPE_SLUGS = %w(angle basic-shape color_value counter frequency
gradient image integer length number percentage position_value ratio
resolution shape string time timing-function uri user-ident)
@ -9,84 +21,95 @@ module Docs
linear-gradient radial-gradient repeating-linear-gradient
repeating-radial-gradient var)
VALUE_SLUGS = %w(auto inherit initial none normal unset)
ADDITIONAL_ENTRIES = {
'shape' => [
%w(rect() Syntax Functions) ],
'uri' => [
%w(url() The_url()_functional_notation Functions) ],
'timing-function' => [
%w(cubic-bezier() The_cubic-bezier()_class_of_timing-functions Functions),
%w(steps() The_steps()_class_of_timing-functions Functions),
%w(linear linear Values),
%w(ease ease Values),
%w(ease-in ease-in Values),
%w(ease-in-out ease-in-out Values),
%w(ease-out ease-out Values),
%w(step-start step-start Values),
%w(step-end step-end Values) ],
'color_value' => [
%w(transparent transparent_keyword Values),
%w(currentColor currentColor_keyword Values),
%w(rgb() rgb() Functions),
%w(hsl() hsl() Functions),
%w(rgba() rgba() Functions),
%w(hsla() hsla() Functions) ],
'transform-function' => [
%w(matrix() matrix() Functions),
%w(matrix3d() matrix3d() Functions),
%w(perspective() perspective() Functions),
%w(rotate() rotate() Functions),
%w(rotate3d() rotate3d() Functions),
%w(rotateX() rotateX() Functions),
%w(rotateY() rotateY() Functions),
%w(rotateZ() rotateZ() Functions),
%w(scale() scale() Functions),
%w(scale3d() scale3d() Functions),
%w(scaleX() scaleX() Functions),
%w(scaleY() scaleY() Functions),
%w(scaleZ() scaleZ() Functions),
%w(skew() skew() Functions),
%w(skewX() skewX() Functions),
%w(skewY() skewY() Functions),
%w(translate() translate() Functions),
%w(translate3d() translate3d() Functions),
%w(translateX() translateX() Functions),
%w(translateY() translateY() Functions),
%w(translateZ() translate(Z) Functions) ]}
def get_name
case type
when 'Data Types' then "<#{super.remove ' value'}>"
when 'Functions' then "#{super}()"
when 'Miscellaneous' then slug.to_s.gsub('_', ' ').gsub('/', ': ')
else super
if DATA_TYPE_SLUGS.include?(slug)
"<#{super.remove ' value'}>"
elsif FUNCTION_SLUGS.include?(slug)
"#{super}()"
elsif slug =~ /\A[a-z]+_/i
slug.to_s.gsub('_', ' ').gsub('/', ': ')
elsif slug.start_with?('transform-function')
slug.split('/').last + '()'
else
super
end
end
def get_type
if slug.end_with?('selectors')
'Selectors'
elsif slug.start_with?('::')
'Pseudo-elements'
elsif slug.start_with?(':')
'Pseudo-classes'
elsif slug.start_with?('@')
'At-rules'
elsif DATA_TYPE_SLUGS.include?(slug)
'Data Types'
elsif FUNCTION_SLUGS.include?(slug)
'Functions'
elsif VALUE_SLUGS.include?(slug)
'Values'
elsif slug =~ /\A[a-z]+_/i
'Miscellaneous'
if type = get_spec
type.remove! 'CSS '
type.remove! ' Module'
type.remove! %r{ Level \d\z}
type.remove! %r{\(.*\)}
type.sub! 'and', '&'
type.strip!
type = 'Animations & Transitions' if type.in?(%w(Animations Transitions))
type = 'Image Values' if type == 'Image Values & Replaced Content'
type = 'Variables' if type == 'Custom Properties for Cascading Variables'
type.prepend 'Miscellaneous ' if type =~ /\ALevel \d\z/
type
elsif type = TYPE_BY_PATH[slug.split('/').first]
type
else
'Properties'
'Miscellaneous'
end
end
STATUSES = {
'spec-Living' => 0,
'spec-REC' => 1,
'spec-CR' => 2,
'spec-LC' => 3,
'spec-WD' => 4,
'spec-ED' => 5
}
PRIORITY_STATUSES = %w(spec-REC spec-CR)
PRIORITY_SPECS = ['CSS Basic Box Model', 'CSS Lists and Counters', 'CSS Paged Media']
def get_spec
return unless table = at_css('#Specifications + table') || css('.standard-table').last
specs = table.css('tbody tr').to_a
# [link, span]
specs.map! { |node| [node.at_css('> td:nth-child(1) > a'), node.at_css('> td:nth-child(2) > span')] }
# ignore non-CSS specs
specs.select! { |pair| pair.first && pair.first['href'] =~ /css|fxtf|fullscreen|svg/i && !pair.first['href'].include?('compat.spec') }
# ["Spec", "spec-REC"]
specs.map! { |pair| [pair.first.child.content, pair.second['class']] }
# sort by status
specs.sort_by! { |pair| [STATUSES[pair.second], pair.first] }
spec = specs.find { |pair| PRIORITY_SPECS.any? { |s| pair.first.start_with?(s) } && name != 'display' }
spec ||= specs.find { |pair| !pair.first.start_with?('CSS Level') && pair.second.in?(PRIORITY_STATUSES) }
spec ||= specs.find { |pair| pair.second == 'spec-WD' } if specs.count { |pair| pair.second == 'spec-WD' } == 1
spec ||= specs.first
spec.try(:first)
end
ADDITIONAL_ENTRIES = {
'shape' => [
%w(rect() Syntax) ],
'uri' => [
%w(url() The_url()_functional_notation) ],
'timing-function' => [
%w(cubic-bezier() The_cubic-bezier()_class_of_timing-functions),
%w(steps() The_steps()_class_of_timing-functions),
%w(linear linear),
%w(ease ease),
%w(ease-in ease-in),
%w(ease-in-out ease-in-out),
%w(ease-out ease-out),
%w(step-start step-start),
%w(step-end step-end) ],
'color_value' => [
%w(transparent transparent_keyword),
%w(currentColor currentColor_keyword),
%w(rgb() rgb()),
%w(hsl() hsl()),
%w(rgba() rgba()),
%w(hsla() hsla()) ]}
def additional_entries
ADDITIONAL_ENTRIES[slug] || []
end

@ -35,6 +35,8 @@ module Docs
/image()
/paged_media)
options[:skip] += %w(/mq-boolean) # bug
options[:skip_patterns] = [/\-webkit/, /\-moz/, /Extensions/, /Tools/]
options[:replace_paths] = {

@ -11,10 +11,12 @@ module Docs
options[:trailing_slash] = false
options[:skip_link] = ->(link) { link['title'].try(:include?, 'written'.freeze) }
options[:skip_link] = ->(link) {
link['title'].try(:include?, 'written'.freeze) && !link['href'].try(:include?, 'transform-function'.freeze)
}
options[:attribution] = <<-HTML
&copy; 2015 Mozilla Contributors<br>
&copy; 2016 Mozilla Contributors<br>
Licensed under the Creative Commons Attribution-ShareAlike License v2.5 or later.
HTML

Loading…
Cancel
Save