Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Merge pull request #18 from heikki/master

sass support
  • Loading branch information...
commit 060821c099076440cc784c5772ac686fb75f37c8 2 parents fde61bc + 64e0bd5
@kneath authored
View
14 lib/kss/parser.rb
@@ -12,7 +12,11 @@ def initialize(base_path)
@sections = {}
Dir["#{base_path}/**/*.*"].each do |filename|
- root_node = Sass::SCSS::Parser.new(File.read(filename), filename).parse
+ if filename.match(/\.css$/)
+ root_node = Sass::SCSS::Parser.new(File.read(filename), filename).parse
+ else
+ root_node = Sass::Engine.for_file(filename, {}).to_tree
+ end
parse_node(root_node, filename)
end
@@ -24,7 +28,7 @@ def parse_node parent_node, filename
parse_node(node, filename) if node.has_children
next
end
- comment_text = self.class.clean_comments node.value[0]
+ comment_text = self.class.clean_comments node.to_scss
if self.class.kss_block? comment_text
base_name = File.basename(filename)
@@ -55,10 +59,14 @@ def self.kss_block?(cleaned_comment)
def self.clean_comments(text)
text.strip!
- # SASS generated comment syntax
+ # SASS generated multi-line comment syntax
text.gsub!(/(\/\* )?( \*\/)?/, '') # [/* + space] or [space + */]
text.gsub!(/\n\s\* ?/, "\n") # * in front of every line
+ # SASS generated single-line comment syntax
+ text.gsub!(/\/\/ /, '') # [// + space]
+ text.gsub!(/\/\/\n/, "\n") # [// + carriage return]
+
# Manual generated comment syntax
text.gsub!(/^\/\*/, '') # starting block
text.gsub!(/\*\/$/, '') # ending block
View
40 test/fixtures/sass/buttons.sass
@@ -0,0 +1,40 @@
+/* Your standard form button.
+ *
+ * :hover - Highlights when hovering.
+ * :disabled - Dims the button when disabled.
+ * .primary - Indicates button is the primary action.
+ * .smaller - A little bit smaller now.
+ *
+ * Styleguide 2.1.1. */
+button
+ padding: 5px 15px
+
+ &.primary, &.primary:hover
+ color: #fff
+
+ &.smaller
+ font-size: 11px
+
+ &:hover
+ color: #337797
+
+ &:disabled
+ opacity: 0.5
+
+// A button suitable for giving stars to someone.
+//
+// .star-given - A highlight indicating you've already given a star.
+// .disabled - Dims the button to indicate it cannot be used.
+//
+// Styleguide 2.2.1.
+a.button.star
+ display: inline-block
+
+ .star
+ font-size: 10px
+
+ &.star-given
+ color: #ae7e00
+
+ &.disabled
+ opacity: 0.5
View
10 test/fixtures/sass/nested.sass
@@ -0,0 +1,10 @@
+/* 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
31 test/parser_test.rb
@@ -4,6 +4,7 @@ class ParserTest < Kss::Test
def setup
@scss_parsed = Kss::Parser.new('test/fixtures/scss')
+ @sass_parsed = Kss::Parser.new('test/fixtures/sass')
@css_parsed = Kss::Parser.new('test/fixtures/css')
@css_comment = <<comment
@@ -26,13 +27,22 @@ def setup
* Styleguide 2.2.1. */
comment
+ @slashed_css_comment = <<comment
+// A button suitable for giving stars to someone.
+//
+// .star-given - A highlight indicating you've already given a star.
+// .disabled - Dims the button to indicate it cannot be used.
+//
+// Styleguide 2.2.1.
+comment
+
@indented_css_comment = <<comment
/*
A button suitable for giving stars to someone.
-
+
.star-given - A highlight indicating you've already given a star.
.disabled - Dims the button to indicate it cannot be used.
-
+
Styleguide 2.2.1.
*/
comment
@@ -54,6 +64,16 @@ def setup
@scss_parsed.section('2.1.1').description
end
+ test "parses KSS multi-line comments in SASS (/* ... */)" do
+ assert_equal 'Your standard form button.',
+ @sass_parsed.section('2.1.1').description
+ end
+
+ test "parses KSS single-line comments in SASS (// ... )" do
+ assert_equal 'A button suitable for giving stars to someone.',
+ @sass_parsed.section('2.2.1').description
+ end
+
test "parses KSS comments in CSS" do
assert_equal 'Your standard form button.',
@css_parsed.section('2.1.1').description
@@ -65,6 +85,8 @@ def setup
assert_equal @cleaned_css_comment,
Kss::Parser.clean_comments(@starred_css_comment)
assert_equal @cleaned_css_comment,
+ Kss::Parser.clean_comments(@slashed_css_comment)
+ assert_equal @cleaned_css_comment,
Kss::Parser.clean_comments(@indented_css_comment)
end
@@ -73,4 +95,9 @@ def setup
assert_equal "Your standard text input box.", @scss_parsed.section('3.0.1').description
end
+ test "parses nested SASS documents" do
+ assert_equal "Your standard form element.", @sass_parsed.section('3.0.0').description
+ assert_equal "Your standard text input box.", @sass_parsed.section('3.0.1').description
+ end
+
end
Please sign in to comment.
Something went wrong with that request. Please try again.