Document Sass Functions
This commit is contained in:
parent
d67a43ad4b
commit
48e3825053
@ -8,7 +8,7 @@ GIT
|
|||||||
PATH
|
PATH
|
||||||
remote: ..
|
remote: ..
|
||||||
specs:
|
specs:
|
||||||
compass (0.11.alpha.4.e11f103)
|
compass (0.11.alpha.4.d67a43a)
|
||||||
chunky_png (~> 0.10.3)
|
chunky_png (~> 0.10.3)
|
||||||
sass (>= 3.1.0.alpha.50)
|
sass (>= 3.1.0.alpha.50)
|
||||||
|
|
||||||
|
@ -109,7 +109,7 @@ $('document').ready(function(){
|
|||||||
changeTheme();
|
changeTheme();
|
||||||
event.preventDefault();
|
event.preventDefault();
|
||||||
|
|
||||||
// View source for mixins
|
// View source for mixins & functions
|
||||||
} else if (target.attr("rel") == "view source") {
|
} else if (target.attr("rel") == "view source") {
|
||||||
$(target.attr("href")).toggle();
|
$(target.attr("href")).toggle();
|
||||||
event.preventDefault();
|
event.preventDefault();
|
||||||
|
18
doc-src/content/index/functions.haml
Normal file
18
doc-src/content/index/functions.haml
Normal file
@ -0,0 +1,18 @@
|
|||||||
|
---
|
||||||
|
title: Compass Documentation | All Functions
|
||||||
|
crumb: Docs
|
||||||
|
body_id: home
|
||||||
|
---
|
||||||
|
%article
|
||||||
|
%h1#logo Sass Based Functions
|
||||||
|
|
||||||
|
- all_functions.sort_by{|i| i.first.identifier}.each do |item, functions|
|
||||||
|
%h3= link_to item[:title], item
|
||||||
|
%ul
|
||||||
|
- functions.sort_by{|f| f.name}.each do |f|
|
||||||
|
%li= f.sass_signature(:html)
|
||||||
|
|
||||||
|
%h1#logo All Ruby Based Functions
|
||||||
|
%ul
|
||||||
|
- Sass::Script::Functions.public_instance_methods.sort_by{|m| m.to_s}.each do |m|
|
||||||
|
%li= m.to_s.gsub("_","-")
|
@ -10,5 +10,5 @@ body_id: home
|
|||||||
%h3= link_to item[:title], item
|
%h3= link_to item[:title], item
|
||||||
%ul
|
%ul
|
||||||
- mixins.sort_by{|m| m.name}.each do |m|
|
- mixins.sort_by{|m| m.name}.each do |m|
|
||||||
%li= mixin_signature(m)
|
%li= m.sass_signature(:none, :html)
|
||||||
|
|
||||||
|
@ -1,18 +1,18 @@
|
|||||||
//html.sass .mixin-source .scss, html.scss .mixin-source .sass { @extend .hide;}
|
//html.sass .mixin-source .scss, html.scss .mixin-source .sass { @extend .hide;}
|
||||||
.mixin-source, .example-source {
|
.mixin-source, .example-source, .function-source {
|
||||||
position: relative; @extend .fixed-font;
|
position: relative; @extend .fixed-font;
|
||||||
.syntaxhighlighter, pre {
|
.syntaxhighlighter, pre {
|
||||||
&.scss, &.sass, &.css, &.haml, &.html { display: none; } } }
|
&.scss, &.sass, &.css, &.haml, &.html { display: none; } } }
|
||||||
|
|
||||||
html.sass { .mixin-source .syntaxhighlighter.sass, .example-source .syntaxhighlighter.sass { display: block; } }
|
html.sass { .mixin-source, .example-source, .function-source { .syntaxhighlighter.sass { display: block; } } }
|
||||||
html.scss { .mixin-source .syntaxhighlighter.scss, .example-source .syntaxhighlighter.scss { display: block; } }
|
html.scss { .mixin-source, .example-source, .function-source { .syntaxhighlighter.scss { display: block; } } }
|
||||||
html.css .example-source .syntaxhighlighter.css { display: block; }
|
html.css .example-source .syntaxhighlighter.css { display: block; }
|
||||||
html.html .example-source .syntaxhighlighter.html { display: block; }
|
html.html .example-source .syntaxhighlighter.html { display: block; }
|
||||||
html.haml .example-source .syntaxhighlighter.haml { display: block; }
|
html.haml .example-source .syntaxhighlighter.haml { display: block; }
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
.mixin-source { display: none; }
|
.mixin-source, .function-source { display: none; }
|
||||||
|
|
||||||
html.light .syntaxhighlighter, html.dark .syntaxhighlighter {
|
html.light .syntaxhighlighter, html.dark .syntaxhighlighter {
|
||||||
margin: 0 0 2px;
|
margin: 0 0 2px;
|
||||||
@ -59,7 +59,7 @@ h3 { @include round-corners;
|
|||||||
a { text-decoration: none;}
|
a { text-decoration: none;}
|
||||||
code, .arg { font-weight: normal; }
|
code, .arg { font-weight: normal; }
|
||||||
}
|
}
|
||||||
h3.mixin { @include round-top-corners; margin-bottom: 2px;}
|
h3.mixin, h3.function { @include round-top-corners; margin-bottom: 2px;}
|
||||||
.arg {
|
.arg {
|
||||||
display: inline-block;
|
display: inline-block;
|
||||||
padding: 0 2px;
|
padding: 0 2px;
|
||||||
|
@ -74,7 +74,7 @@
|
|||||||
&.sass a[rel=sass], &.scss a[rel=scss], &.css a[rel=css], &.html a[rel=html], &.haml a[rel=haml] { color: $heading; color: rgba($heading, .7); @extend .round-corners-em; @extend .inset-panel-#{$theme}; }
|
&.sass a[rel=sass], &.scss a[rel=scss], &.css a[rel=css], &.html a[rel=html], &.haml a[rel=haml] { color: $heading; color: rgba($heading, .7); @extend .round-corners-em; @extend .inset-panel-#{$theme}; }
|
||||||
|
|
||||||
#version { color: rgba($heading, .3); a { color: rgba($nav-link, .7); } }
|
#version { color: rgba($heading, .3); a { color: rgba($nav-link, .7); } }
|
||||||
.mixin-source, .example-source { @extend .mixin-panel-#{$theme};
|
.mixin-source, .example-source, .function-source { @extend .mixin-panel-#{$theme};
|
||||||
.container textarea { color: $code; }
|
.container textarea { color: $code; }
|
||||||
}
|
}
|
||||||
h2 a.help { color: $heading;}
|
h2 a.help { color: $heading;}
|
||||||
|
19
doc-src/layouts/partials/reference/functions.haml
Normal file
19
doc-src/layouts/partials/reference/functions.haml
Normal file
@ -0,0 +1,19 @@
|
|||||||
|
- if (functions = functions(@item)).any?
|
||||||
|
%h2 Functions
|
||||||
|
|
||||||
|
- functions.each do |function|
|
||||||
|
%a{:href=>"#function-#{function.name}-source", :rel => "view source"} view source
|
||||||
|
%h3.function{:id=>"function-#{function.name}"}
|
||||||
|
%a.permalink{:href => "#function-#{function.name}"}= function.sass_signature(:html)
|
||||||
|
.function-source{:id=>"function-#{function.name}-source"}
|
||||||
|
%pre.source-code.sass= function.to_sass
|
||||||
|
%pre.source-code.scss= function.to_scss
|
||||||
|
|
||||||
|
.source-documentation
|
||||||
|
= format_doc(function.comment)
|
||||||
|
- if (examples = examples(@item, function)).any?
|
||||||
|
%dl.examples
|
||||||
|
- examples.each do |example|
|
||||||
|
%dt= link_to example.item[:title], example
|
||||||
|
- if example.item[:description]
|
||||||
|
%dd= example.item[:description]
|
@ -4,7 +4,7 @@
|
|||||||
- mixin_defs.each do |mixin|
|
- mixin_defs.each do |mixin|
|
||||||
%a{:href=>"#mixin-#{mixin.name}-source", :rel => "view source"} view source
|
%a{:href=>"#mixin-#{mixin.name}-source", :rel => "view source"} view source
|
||||||
%h3.mixin{:id=>"mixin-#{mixin.name}"}
|
%h3.mixin{:id=>"mixin-#{mixin.name}"}
|
||||||
%a.permalink{:href => "#mixin-#{mixin.name}"}= mixin_signature(mixin)
|
%a.permalink{:href => "#mixin-#{mixin.name}"}= mixin.sass_signature(:none, :html)
|
||||||
.mixin-source{:id=>"mixin-#{mixin.name}-source"}
|
.mixin-source{:id=>"mixin-#{mixin.name}-source"}
|
||||||
%pre.source-code.sass= mixin.to_sass
|
%pre.source-code.sass= mixin.to_sass
|
||||||
%pre.source-code.scss= mixin.to_scss
|
%pre.source-code.scss= mixin.to_scss
|
||||||
|
@ -20,4 +20,6 @@
|
|||||||
|
|
||||||
= render "partials/reference/constants"
|
= render "partials/reference/constants"
|
||||||
|
|
||||||
|
= render "partials/reference/functions"
|
||||||
|
|
||||||
= render "partials/reference/mixins"
|
= render "partials/reference/mixins"
|
||||||
|
@ -118,6 +118,26 @@ def mixins(item)
|
|||||||
mixins.reject{|m| m.comment =~ /@private/}
|
mixins.reject{|m| m.comment =~ /@private/}
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def functions(item)
|
||||||
|
sass_tree = tree(item)
|
||||||
|
functions = []
|
||||||
|
comment = nil
|
||||||
|
sass_tree.children.each do |child|
|
||||||
|
if child.is_a?(Sass::Tree::FunctionNode)
|
||||||
|
child.comment = comment && Sass::Tree::CommentNode.clean(comment)
|
||||||
|
comment = nil
|
||||||
|
functions << child
|
||||||
|
elsif child.is_a?(Sass::Tree::CommentNode)
|
||||||
|
comment ||= ""
|
||||||
|
comment << "\n" unless comment.empty?
|
||||||
|
comment << child.docstring
|
||||||
|
else
|
||||||
|
comment = nil
|
||||||
|
end
|
||||||
|
end
|
||||||
|
functions.reject{|m| m.comment =~ /@private/}
|
||||||
|
end
|
||||||
|
|
||||||
def constants(item)
|
def constants(item)
|
||||||
sass_tree = tree(item)
|
sass_tree = tree(item)
|
||||||
constants = []
|
constants = []
|
||||||
@ -165,8 +185,17 @@ def all_mixins
|
|||||||
all_mixins
|
all_mixins
|
||||||
end
|
end
|
||||||
|
|
||||||
def mixin_signature(mixin, format = :html)
|
def all_functions
|
||||||
mixin.sass_signature(:none, format)
|
all_functions = []
|
||||||
|
@items.each do |item|
|
||||||
|
next unless item.identifier =~ %r{/reference}
|
||||||
|
next unless item[:stylesheet]
|
||||||
|
fns = functions(item)
|
||||||
|
if fns.any?
|
||||||
|
all_functions << [item, fns]
|
||||||
|
end
|
||||||
|
end
|
||||||
|
all_functions
|
||||||
end
|
end
|
||||||
|
|
||||||
def example_items
|
def example_items
|
||||||
|
@ -19,18 +19,9 @@ module Sass
|
|||||||
class VariableNode < Node
|
class VariableNode < Node
|
||||||
attr_accessor :comment unless method_defined? :comment
|
attr_accessor :comment unless method_defined? :comment
|
||||||
end
|
end
|
||||||
class MixinDefNode < Node
|
module HasSignature
|
||||||
attr_accessor :name unless method_defined? :name
|
def sass_signature(format = :text)
|
||||||
attr_accessor :args unless method_defined? :args
|
"#{name}#{arglist_to_sass(format)}"
|
||||||
attr_accessor :comment unless method_defined? :comment
|
|
||||||
def sass_signature(mode = :definition, format = :text)
|
|
||||||
prefix = case mode
|
|
||||||
when :definition
|
|
||||||
"="
|
|
||||||
when :include
|
|
||||||
"+"
|
|
||||||
end
|
|
||||||
"#{prefix}#{name}#{arglist_to_sass(format)}"
|
|
||||||
end
|
end
|
||||||
|
|
||||||
private
|
private
|
||||||
@ -57,6 +48,30 @@ module Sass
|
|||||||
sass_str
|
sass_str
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
class MixinDefNode < Node
|
||||||
|
attr_accessor :name unless method_defined? :name
|
||||||
|
attr_accessor :args unless method_defined? :args
|
||||||
|
attr_accessor :comment unless method_defined? :comment
|
||||||
|
unless included_modules.include?(HasSignature)
|
||||||
|
include HasSignature
|
||||||
|
alias sass_signature_without_prefix sass_signature
|
||||||
|
def sass_signature(mode = :definition, format = :text)
|
||||||
|
prefix = case mode
|
||||||
|
when :definition
|
||||||
|
"="
|
||||||
|
when :include
|
||||||
|
"+"
|
||||||
|
end
|
||||||
|
"#{prefix}#{sass_signature_without_prefix(format)}"
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
class FunctionNode < Node
|
||||||
|
attr_accessor :name unless method_defined? :name
|
||||||
|
attr_accessor :args unless method_defined? :args
|
||||||
|
attr_accessor :comment unless method_defined? :comment
|
||||||
|
include HasSignature unless included_modules.include?(HasSignature)
|
||||||
|
end
|
||||||
class ImportNode < RootNode
|
class ImportNode < RootNode
|
||||||
attr_accessor :imported_filename unless method_defined? :imported_filename
|
attr_accessor :imported_filename unless method_defined? :imported_filename
|
||||||
end
|
end
|
||||||
|
@ -1,11 +1,10 @@
|
|||||||
module Compass::SassExtensions::Functions::Colors
|
module Compass::SassExtensions::Functions::Colors
|
||||||
include Compass::Util
|
|
||||||
|
|
||||||
# a genericized version of lighten/darken so that negative values can be used.
|
# a genericized version of lighten/darken so that negative values can be used.
|
||||||
def adjust_lightness(color, amount)
|
def adjust_lightness(color, amount)
|
||||||
assert_type color, :Color
|
assert_type color, :Color
|
||||||
assert_type amount, :Number
|
assert_type amount, :Number
|
||||||
color.with(:lightness => restrict(color.lightness + amount.value, 0..100))
|
color.with(:lightness => Compass::Util.restrict(color.lightness + amount.value, 0..100))
|
||||||
end
|
end
|
||||||
|
|
||||||
# Scales a color's lightness by some percentage.
|
# Scales a color's lightness by some percentage.
|
||||||
@ -21,7 +20,7 @@ module Compass::SassExtensions::Functions::Colors
|
|||||||
def adjust_saturation(color, amount)
|
def adjust_saturation(color, amount)
|
||||||
assert_type color, :Color
|
assert_type color, :Color
|
||||||
assert_type amount, :Number
|
assert_type amount, :Number
|
||||||
color.with(:saturation => restrict(color.saturation + amount.value, 0..100))
|
color.with(:saturation => Compass::Util.restrict(color.saturation + amount.value, 0..100))
|
||||||
end
|
end
|
||||||
|
|
||||||
# Scales a color's saturation by some percentage.
|
# Scales a color's saturation by some percentage.
|
||||||
|
Loading…
Reference in New Issue
Block a user