doc support for mixins.

This commit is contained in:
Chris Eppstein 2010-01-22 11:40:56 -08:00
parent 4afca420c3
commit d7a9864ee2
3 changed files with 48 additions and 1 deletions

View File

@ -12,3 +12,9 @@
- imports(@item).each do |import|
%li= import
%h2 Mixins
- mixins(@item).each do |mixin|
%h3= mixin_signature mixin
%pre= mixin.comment

View File

@ -26,3 +26,38 @@ def imports(item)
end
imports
end
def mixins(item)
sass_tree = tree(item)
mixins = []
comment = nil
sass_tree.children.each do |child|
if child.is_a?(Sass::Tree::MixinDefNode)
child.comment = comment
comment = nil
mixins << child
elsif child.is_a?(Sass::Tree::CommentNode)
comment ||= ""
comment << "\n" unless comment.empty?
comment << child.docstring
else
comment = nil
end
end
mixins
end
def mixin_signature(mixin)
signature = "+#{mixin.name}"
if mixin.args && mixin.args.any?
signature << "("
signature << mixin.args.map do |a|
var = a.first
default_value = a.last
"#{var.inspect}#{" = " + default_value.inspect if default_value}"
end.join(", ")
signature << ")"
end
signature
end

View File

@ -6,9 +6,15 @@ module Sass
class MixinDefNode < Node
attr_accessor :name unless method_defined? :name
attr_accessor :args unless method_defined? :args
attr_accessor :comment unless method_defined? :comment
end
class ImportNode < Node
class ImportNode < RootNode
attr_accessor :imported_filename unless method_defined? :imported_filename
end
class CommentNode < Node
def docstring
([value] + lines).join("\n")
end
end
end
end