kss 0.1.3 → 0.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/lib/kss.rb +2 -0
- data/lib/kss/parser.rb +59 -10
- data/lib/kss/version.rb +1 -1
- data/test/fixtures/less/_label.less +10 -0
- data/test/fixtures/less/buttons.less +51 -0
- data/test/fixtures/less/mixins.less +8 -0
- data/test/fixtures/less/nested.less +17 -0
- data/test/fixtures/sass/buttons.sass +40 -0
- data/test/fixtures/sass/nested.sass +10 -0
- data/test/parser_test.rb +40 -2
- metadata +26 -5
data/lib/kss.rb
CHANGED
data/lib/kss/parser.rb
CHANGED
@@ -12,30 +12,75 @@ module Kss
|
|
12
12
|
@sections = {}
|
13
13
|
|
14
14
|
Dir["#{base_path}/**/*.*"].each do |filename|
|
15
|
-
|
16
|
-
|
15
|
+
if File.extname(filename) == ".less"
|
16
|
+
tree = Less::Parser.new(:paths => [base_path], :filename => filename).
|
17
|
+
# HACK: get the internal JS tree object
|
18
|
+
parse(File.read(filename)).instance_variable_get "@tree"
|
17
19
|
|
20
|
+
# inject less.js into a new V8 context
|
21
|
+
less = Less.instance_variable_get "@less"
|
22
|
+
cxt = V8::Context.new
|
23
|
+
cxt['less'] = less
|
24
|
+
|
25
|
+
# parse node tree for comments
|
26
|
+
parse_v8_node(cxt, tree, filename)
|
27
|
+
else
|
28
|
+
if filename.match(/\.css$/)
|
29
|
+
root_node = Sass::SCSS::Parser.new(File.read(filename), filename).parse
|
30
|
+
else
|
31
|
+
root_node = Sass::Engine.for_file(filename, {}).to_tree
|
32
|
+
end
|
33
|
+
parse_sass_node(root_node, filename)
|
34
|
+
end
|
18
35
|
end
|
19
36
|
end
|
20
37
|
|
21
|
-
|
38
|
+
# Given a Sass::Tree::Node, find all CommentNodes and populate @sections
|
39
|
+
# with parsed Section objects.
|
40
|
+
#
|
41
|
+
# parent_node - A Sass::Tree::Node to start at.
|
42
|
+
# filename - The filename String this node is found at.
|
43
|
+
#
|
44
|
+
# Returns the Sass::Tree::Node given.
|
45
|
+
def parse_sass_node parent_node, filename
|
22
46
|
parent_node.children.each do |node|
|
23
47
|
unless node.is_a? Sass::Tree::CommentNode
|
24
|
-
|
48
|
+
parse_sass_node(node, filename) if node.has_children
|
25
49
|
next
|
26
50
|
end
|
27
|
-
comment_text = self.class.clean_comments node.
|
51
|
+
comment_text = self.class.clean_comments node.to_scss
|
52
|
+
add_section node.to_scss, filename
|
53
|
+
end
|
54
|
+
parent_node
|
55
|
+
end
|
56
|
+
|
57
|
+
def parse_v8_node cxt, parent_node, filename
|
58
|
+
parent_node.rules.each do |node|
|
59
|
+
# inject the current to into JS context
|
60
|
+
cxt['node'] = node
|
28
61
|
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
62
|
+
unless cxt.eval "node instanceof less.tree.Comment"
|
63
|
+
parse_v8_node(cxt, node, filename) if cxt.eval 'node.rules != null'
|
64
|
+
|
65
|
+
next
|
33
66
|
end
|
67
|
+
|
68
|
+
add_section node.value, filename
|
34
69
|
end
|
35
70
|
|
36
71
|
parent_node
|
37
72
|
end
|
38
73
|
|
74
|
+
def add_section comment, filename
|
75
|
+
comment_text = self.class.clean_comments comment
|
76
|
+
|
77
|
+
if self.class.kss_block? comment_text
|
78
|
+
base_name = File.basename(filename)
|
79
|
+
section = Section.new(comment_text, base_name)
|
80
|
+
@sections[section.section] = section
|
81
|
+
end
|
82
|
+
end
|
83
|
+
|
39
84
|
# Public: Takes a cleaned (no comment syntax like // or /* */) comment
|
40
85
|
# block and determines whether it is a KSS documentation block.
|
41
86
|
#
|
@@ -55,10 +100,14 @@ module Kss
|
|
55
100
|
def self.clean_comments(text)
|
56
101
|
text.strip!
|
57
102
|
|
58
|
-
# SASS generated comment syntax
|
103
|
+
# SASS generated multi-line comment syntax
|
59
104
|
text.gsub!(/(\/\* )?( \*\/)?/, '') # [/* + space] or [space + */]
|
60
105
|
text.gsub!(/\n\s\* ?/, "\n") # * in front of every line
|
61
106
|
|
107
|
+
# SASS generated single-line comment syntax
|
108
|
+
text.gsub!(/\/\/ /, '') # [// + space]
|
109
|
+
text.gsub!(/\/\/\n/, "\n") # [// + carriage return]
|
110
|
+
|
62
111
|
# Manual generated comment syntax
|
63
112
|
text.gsub!(/^\/\*/, '') # starting block
|
64
113
|
text.gsub!(/\*\/$/, '') # ending block
|
data/lib/kss/version.rb
CHANGED
@@ -0,0 +1,51 @@
|
|
1
|
+
/*
|
2
|
+
Your standard form button.
|
3
|
+
|
4
|
+
:hover - Highlights when hovering.
|
5
|
+
:disabled - Dims the button when disabled.
|
6
|
+
.primary - Indicates button is the primary action.
|
7
|
+
.smaller - A little bit smaller now.
|
8
|
+
|
9
|
+
Styleguide 2.1.1.
|
10
|
+
*/
|
11
|
+
button, .button {
|
12
|
+
padding:5px 15px;
|
13
|
+
|
14
|
+
&.primary, &.primary:hover{
|
15
|
+
color:#fff;
|
16
|
+
}
|
17
|
+
|
18
|
+
&.smaller{
|
19
|
+
font-size:9px;
|
20
|
+
}
|
21
|
+
|
22
|
+
&:hover{
|
23
|
+
color:#337797;
|
24
|
+
}
|
25
|
+
|
26
|
+
&:disabled{
|
27
|
+
opacity:0.5;
|
28
|
+
}
|
29
|
+
}
|
30
|
+
|
31
|
+
/*
|
32
|
+
A button suitable for giving stars to someone.
|
33
|
+
|
34
|
+
.star-given - A highlight indicating you've already given a star.
|
35
|
+
.disabled - Dims the button to indicate it cannot be used.
|
36
|
+
|
37
|
+
Styleguide 2.2.1.
|
38
|
+
*/
|
39
|
+
a.button.star{
|
40
|
+
display:inline-block;
|
41
|
+
|
42
|
+
.star{ font-size:10px; }
|
43
|
+
|
44
|
+
&.star-given{
|
45
|
+
color:#ae7e00;
|
46
|
+
}
|
47
|
+
|
48
|
+
&.disabled{
|
49
|
+
opacity:0.5;
|
50
|
+
}
|
51
|
+
}
|
@@ -0,0 +1,40 @@
|
|
1
|
+
/* Your standard form button.
|
2
|
+
*
|
3
|
+
* :hover - Highlights when hovering.
|
4
|
+
* :disabled - Dims the button when disabled.
|
5
|
+
* .primary - Indicates button is the primary action.
|
6
|
+
* .smaller - A little bit smaller now.
|
7
|
+
*
|
8
|
+
* Styleguide 2.1.1. */
|
9
|
+
button
|
10
|
+
padding: 5px 15px
|
11
|
+
|
12
|
+
&.primary, &.primary:hover
|
13
|
+
color: #fff
|
14
|
+
|
15
|
+
&.smaller
|
16
|
+
font-size: 11px
|
17
|
+
|
18
|
+
&:hover
|
19
|
+
color: #337797
|
20
|
+
|
21
|
+
&:disabled
|
22
|
+
opacity: 0.5
|
23
|
+
|
24
|
+
// A button suitable for giving stars to someone.
|
25
|
+
//
|
26
|
+
// .star-given - A highlight indicating you've already given a star.
|
27
|
+
// .disabled - Dims the button to indicate it cannot be used.
|
28
|
+
//
|
29
|
+
// Styleguide 2.2.1.
|
30
|
+
a.button.star
|
31
|
+
display: inline-block
|
32
|
+
|
33
|
+
.star
|
34
|
+
font-size: 10px
|
35
|
+
|
36
|
+
&.star-given
|
37
|
+
color: #ae7e00
|
38
|
+
|
39
|
+
&.disabled
|
40
|
+
opacity: 0.5
|
data/test/parser_test.rb
CHANGED
@@ -4,7 +4,9 @@ class ParserTest < Kss::Test
|
|
4
4
|
|
5
5
|
def setup
|
6
6
|
@scss_parsed = Kss::Parser.new('test/fixtures/scss')
|
7
|
+
@sass_parsed = Kss::Parser.new('test/fixtures/sass')
|
7
8
|
@css_parsed = Kss::Parser.new('test/fixtures/css')
|
9
|
+
@less_parsed = Kss::Parser.new('test/fixtures/less')
|
8
10
|
|
9
11
|
@css_comment = <<comment
|
10
12
|
/*
|
@@ -26,13 +28,22 @@ comment
|
|
26
28
|
* Styleguide 2.2.1. */
|
27
29
|
comment
|
28
30
|
|
31
|
+
@slashed_css_comment = <<comment
|
32
|
+
// A button suitable for giving stars to someone.
|
33
|
+
//
|
34
|
+
// .star-given - A highlight indicating you've already given a star.
|
35
|
+
// .disabled - Dims the button to indicate it cannot be used.
|
36
|
+
//
|
37
|
+
// Styleguide 2.2.1.
|
38
|
+
comment
|
39
|
+
|
29
40
|
@indented_css_comment = <<comment
|
30
41
|
/*
|
31
42
|
A button suitable for giving stars to someone.
|
32
|
-
|
43
|
+
|
33
44
|
.star-given - A highlight indicating you've already given a star.
|
34
45
|
.disabled - Dims the button to indicate it cannot be used.
|
35
|
-
|
46
|
+
|
36
47
|
Styleguide 2.2.1.
|
37
48
|
*/
|
38
49
|
comment
|
@@ -54,6 +65,21 @@ comment
|
|
54
65
|
@scss_parsed.section('2.1.1').description
|
55
66
|
end
|
56
67
|
|
68
|
+
test "parsers KSS comments in LESS" do
|
69
|
+
assert_equal 'Your standard form button.',
|
70
|
+
@less_parsed.section('2.1.1').description
|
71
|
+
end
|
72
|
+
|
73
|
+
test "parses KSS multi-line comments in SASS (/* ... */)" do
|
74
|
+
assert_equal 'Your standard form button.',
|
75
|
+
@sass_parsed.section('2.1.1').description
|
76
|
+
end
|
77
|
+
|
78
|
+
test "parses KSS single-line comments in SASS (// ... )" do
|
79
|
+
assert_equal 'A button suitable for giving stars to someone.',
|
80
|
+
@sass_parsed.section('2.2.1').description
|
81
|
+
end
|
82
|
+
|
57
83
|
test "parses KSS comments in CSS" do
|
58
84
|
assert_equal 'Your standard form button.',
|
59
85
|
@css_parsed.section('2.1.1').description
|
@@ -64,6 +90,8 @@ comment
|
|
64
90
|
Kss::Parser.clean_comments(@css_comment)
|
65
91
|
assert_equal @cleaned_css_comment,
|
66
92
|
Kss::Parser.clean_comments(@starred_css_comment)
|
93
|
+
assert_equal @cleaned_css_comment,
|
94
|
+
Kss::Parser.clean_comments(@slashed_css_comment)
|
67
95
|
assert_equal @cleaned_css_comment,
|
68
96
|
Kss::Parser.clean_comments(@indented_css_comment)
|
69
97
|
end
|
@@ -73,4 +101,14 @@ comment
|
|
73
101
|
assert_equal "Your standard text input box.", @scss_parsed.section('3.0.1').description
|
74
102
|
end
|
75
103
|
|
104
|
+
test "parses nested LESS documents" do
|
105
|
+
assert_equal "Your standard form element.", @less_parsed.section('3.0.0').description
|
106
|
+
assert_equal "Your standard text input box.", @less_parsed.section('3.0.1').description
|
107
|
+
end
|
108
|
+
|
109
|
+
test "parses nested SASS documents" do
|
110
|
+
assert_equal "Your standard form element.", @sass_parsed.section('3.0.0').description
|
111
|
+
assert_equal "Your standard text input box.", @sass_parsed.section('3.0.1').description
|
112
|
+
end
|
113
|
+
|
76
114
|
end
|
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: kss
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
4
|
+
hash: 23
|
5
5
|
prerelease:
|
6
6
|
segments:
|
7
7
|
- 0
|
8
|
-
-
|
9
|
-
-
|
10
|
-
version: 0.
|
8
|
+
- 2
|
9
|
+
- 0
|
10
|
+
version: 0.2.0
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- Kyle Neath
|
@@ -15,7 +15,7 @@ autorequire:
|
|
15
15
|
bindir: bin
|
16
16
|
cert_chain: []
|
17
17
|
|
18
|
-
date:
|
18
|
+
date: 2012-01-22 00:00:00 -08:00
|
19
19
|
default_executable:
|
20
20
|
dependencies:
|
21
21
|
- !ruby/object:Gem::Dependency
|
@@ -33,6 +33,21 @@ dependencies:
|
|
33
33
|
version: "3.1"
|
34
34
|
type: :runtime
|
35
35
|
version_requirements: *id001
|
36
|
+
- !ruby/object:Gem::Dependency
|
37
|
+
name: less
|
38
|
+
prerelease: false
|
39
|
+
requirement: &id002 !ruby/object:Gem::Requirement
|
40
|
+
none: false
|
41
|
+
requirements:
|
42
|
+
- - ">="
|
43
|
+
- !ruby/object:Gem::Version
|
44
|
+
hash: 3
|
45
|
+
segments:
|
46
|
+
- 2
|
47
|
+
- 0
|
48
|
+
version: "2.0"
|
49
|
+
type: :runtime
|
50
|
+
version_requirements: *id002
|
36
51
|
description: " Inspired by TomDoc, KSS attempts to provide a methodology for writing\n maintainable, documented CSS within a team. Specifically, KSS is a CSS\n structure, documentation specification, and styleguide format.\n\n This is a ruby library for parsing KSS documented CSS and generating\n styleguides.\n"
|
37
52
|
email: kneath@gmail.com
|
38
53
|
executables: []
|
@@ -52,6 +67,12 @@ files:
|
|
52
67
|
- lib/kss.coffee
|
53
68
|
- lib/kss.rb
|
54
69
|
- test/fixtures/css/buttons.css
|
70
|
+
- test/fixtures/less/_label.less
|
71
|
+
- test/fixtures/less/buttons.less
|
72
|
+
- test/fixtures/less/mixins.less
|
73
|
+
- test/fixtures/less/nested.less
|
74
|
+
- test/fixtures/sass/buttons.sass
|
75
|
+
- test/fixtures/sass/nested.sass
|
55
76
|
- test/fixtures/scss/buttons.scss
|
56
77
|
- test/fixtures/scss/nested.scss
|
57
78
|
- test/helper.rb
|