From ea28759fa6c59202e93d1f8376c53ad63a3ac344 Mon Sep 17 00:00:00 2001 From: Chris Eppstein Date: Tue, 13 Mar 2012 09:21:05 -0700 Subject: [PATCH] Document selectors in compass modules. This is mostly for upcoming placeholder selectors. --- .../layouts/partials/reference/selectors.haml | 13 ++++++++++ doc-src/layouts/reference.haml | 2 ++ doc-src/lib/stylesheets.rb | 25 +++++++++++++++++++ doc-src/lib/stylesheets/sass_extensions.rb | 14 +++++++++++ 4 files changed, 54 insertions(+) create mode 100644 doc-src/layouts/partials/reference/selectors.haml diff --git a/doc-src/layouts/partials/reference/selectors.haml b/doc-src/layouts/partials/reference/selectors.haml new file mode 100644 index 00000000..3f27f017 --- /dev/null +++ b/doc-src/layouts/partials/reference/selectors.haml @@ -0,0 +1,13 @@ +- if (sels = selectors(@item)).any? + %h2 Selectors + + - sels.each do |selector| + %a{:href=>"#selector-#{selector.identifier}-source", :rel => "view source"} view source + %h3.selector{:id=>"selector-#{selector.identifier}"} + %a.permalink{:href => "#selector-#{selector.identifier}"}= selector.name + .selector-source{:id=>"selector-#{selector.identifier}-source"} + %pre.source-code.sass= selector.to_sass + %pre.source-code.scss= selector.to_scss + + .source-documentation + = format_doc(selector.comment) diff --git a/doc-src/layouts/reference.haml b/doc-src/layouts/reference.haml index 67694fee..8dd47216 100644 --- a/doc-src/layouts/reference.haml +++ b/doc-src/layouts/reference.haml @@ -23,3 +23,5 @@ = render "partials/reference/functions" = render "partials/reference/mixins" + += render "partials/reference/selectors" diff --git a/doc-src/lib/stylesheets.rb b/doc-src/lib/stylesheets.rb index 4bd2e6f1..6b36de5e 100644 --- a/doc-src/lib/stylesheets.rb +++ b/doc-src/lib/stylesheets.rb @@ -118,6 +118,31 @@ def mixins(item) mixins.reject{|m| m.comment =~ /@private/} end +def selectors(item) + sass_tree = tree(item) + # Visitors::CheckNesting.visit(sass_tree) + # sass_tree = Visitors::Perform.visit(sass_tree) + selectors = [] + comment = nil + sass_tree.children.each do |child| + case child + when Sass::Tree::RuleNode + child.comment = comment && Sass::Tree::CommentNode.clean(comment) + comment = nil + selectors << child + when Sass::Tree::CommentNode + comment ||= "" + comment << "\n" unless comment.empty? + comment << child.docstring + else + comment = nil + end + end + selectors.reject!{|s| s.comment =~ /@private/} + # selectors.select!{|s| s.comment.strip.size > 0} # this would cause only documented selectors to be output + selectors +end + def functions(item) sass_tree = tree(item) functions = [] diff --git a/doc-src/lib/stylesheets/sass_extensions.rb b/doc-src/lib/stylesheets/sass_extensions.rb index 67bafbd8..a6103842 100644 --- a/doc-src/lib/stylesheets/sass_extensions.rb +++ b/doc-src/lib/stylesheets/sass_extensions.rb @@ -1,6 +1,20 @@ require 'sass' module Sass module Tree + class RuleNode + attr_accessor :comment unless method_defined? :comment + def identifier + @identifier ||= begin + id = name.gsub(/[^a-zA-Z]+/,"-").downcase + id = id[1..-1] if id[0..0] == "-" + id = id[0..-2] if id[-1..-1] == "-" + id + end + end + def name + @name ||= rule.map{|part| Sass::Script::Node === part ? "\#{#{part.to_sass}}" : part}.join('') + end + end class VariableNode < Node attr_accessor :name unless method_defined? :name attr_accessor :expr unless method_defined? :expr