Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

traverse nested scss trees for comment nodes

  • Loading branch information...
commit 4b5ee396bd1970b7ae168940f755f18e0545a24f 1 parent a1996a5
Chris Beer authored
View
26 lib/kss/parser.rb
@@ -13,17 +13,27 @@ def initialize(base_path)
Dir["#{base_path}/**/*.*"].each do |filename|
root_node = Sass::SCSS::Parser.new(File.read(filename), filename).parse
- root_node.children.each do |node|
- next unless node.is_a? Sass::Tree::CommentNode
- comment_text = self.class.clean_comments node.value[0]
+ parse_node(root_node, filename)
- if self.class.kss_block? comment_text
- base_name = File.basename(filename)
- section = Section.new(comment_text, base_name)
- @sections[section.section] = section
- end
+ end
+ end
+
+ def parse_node parent_node, filename
+ parent_node.children.each do |node|
+ unless node.is_a? Sass::Tree::CommentNode
+ parse_node(node, filename) if node.has_children
+ next
+ end
+ comment_text = self.class.clean_comments node.value[0]
+
+ if self.class.kss_block? comment_text
+ base_name = File.basename(filename)
+ section = Section.new(comment_text, base_name)
+ @sections[section.section] = section
end
end
+
+ parent_node
end
# Public: Takes a cleaned (no comment syntax like // or /* */) comment
View
12 test/fixtures/scss/nested.scss
@@ -0,0 +1,12 @@
+// Your standard form element.
+//
+// Styleguide 3.0.0
+form {
+
+ // Your standard text input box.
+ //
+ // Styleguide 3.0.1
+ input[type="text"] {
+ border: 1px solid #ccc;
+ }
+}
View
5 test/parser_test.rb
@@ -68,4 +68,9 @@ def setup
Kss::Parser.clean_comments(@indented_css_comment)
end
+ test "parses nested SCSS documents" do
+ assert_equal "Your standard form element.", @scss_parsed.section('3.0.0').description
+ assert_equal "Your standard text input box.", @scss_parsed.section('3.0.1').description
+ end
+
end
Please sign in to comment.
Something went wrong with that request. Please try again.