kss 0.1.1 → 0.1.2
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/README.md +60 -5
- data/lib/kss.coffee +38 -0
- data/lib/kss/parser.rb +22 -10
- data/lib/kss/version.rb +1 -1
- data/test/fixtures/scss/nested.scss +12 -0
- data/test/parser_test.rb +19 -1
- metadata +7 -5
data/README.md
CHANGED
@@ -1,19 +1,74 @@
|
|
1
1
|
# Knyle Style Sheets
|
2
2
|
|
3
|
-
|
3
|
+
Inspired by [TomDoc](http://tomdoc.org), KSS attempts to provide a methodology for writing maintainable, documented CSS within a team. Specifically, KSS is a documentation specification and styleguide format. It is **not** a preprocessor, CSS framework, naming convention, or specificity guideline.
|
4
4
|
|
5
|
-
|
5
|
+
* **[The Spec (What KSS is)](https://github.com/kneath/kss/blob/master/SPEC.md)**
|
6
|
+
* **[Example living styleguide](https://github.com/kneath/kss/tree/master/example)**
|
6
7
|
|
7
|
-
##
|
8
|
+
## KSS in a nutshell
|
8
9
|
|
9
|
-
|
10
|
+
The methodology and ideas behind Knyle Style Sheets are contained in [SPEC.md](https://github.com/kneath/kss/blob/master/SPEC.md). At it's core, KSS is a documenting syntax for CSS.
|
11
|
+
|
12
|
+
```css
|
13
|
+
/*
|
14
|
+
A button suitable for giving stars to someone.
|
15
|
+
|
16
|
+
:hover - Subtle hover highlight.
|
17
|
+
.stars-given - A highlight indicating you've already given a star.
|
18
|
+
.stars-given:hover - Subtle hover highlight on top of stars-given styling.
|
19
|
+
.disabled - Dims the button to indicate it cannot be used.
|
20
|
+
|
21
|
+
Styleguide 2.1.3.
|
22
|
+
*/
|
23
|
+
a.button.star{
|
24
|
+
...
|
25
|
+
}
|
26
|
+
a.button.star.stars-given{
|
27
|
+
...
|
28
|
+
}
|
29
|
+
a.button.star.disabled{
|
30
|
+
...
|
31
|
+
}
|
32
|
+
```
|
10
33
|
|
11
34
|
## Ruby Library
|
12
35
|
|
13
|
-
This repository includes a ruby library suitable for parsing SASS, SCSS, and CSS documented with KSS guidelines.
|
36
|
+
This repository includes a ruby library suitable for parsing SASS, SCSS, and CSS documented with KSS guidelines. To use the library, include it in your project as a gem from <https://rubygems.org/gems/kss>. Then, create a parser and explore your KSS.
|
37
|
+
|
38
|
+
```ruby
|
39
|
+
styleguide = Kss::Parser.new("#{RACK_ROOT}public/stylesheets")
|
40
|
+
|
41
|
+
styleguide.section('2.1.1')
|
42
|
+
# => <Kss::Section>
|
43
|
+
|
44
|
+
styleguide.section('2.1.1').description
|
45
|
+
# => "A button suitable for giving stars to someone."
|
46
|
+
|
47
|
+
styleguide.section('2.1.1').modifiers.first
|
48
|
+
# => <Kss::Modifier>
|
49
|
+
|
50
|
+
styleguide.section('2.1.1').modifiers.first.name
|
51
|
+
# => ':hover'
|
52
|
+
|
53
|
+
styleguide.section('2.1.1').modifiers.first.class_name
|
54
|
+
# => 'pseudo-class-hover'
|
55
|
+
|
56
|
+
styleguide.section('2.1.1').modifiers.first.first.description
|
57
|
+
# => 'Subtle hover highlight'
|
58
|
+
|
59
|
+
```
|
14
60
|
|
15
61
|
The library is also fully TomDoc'd, completing the circle of life.
|
16
62
|
|
63
|
+
## Generating styleguides
|
64
|
+
|
65
|
+
The documenting syntax and ruby library are intended to generate styleguides automatically. To do this, you'll need to leverage a small javascript library that generates class styles for pseudo-class styles (`:hover`, `:disabled`, etc).
|
66
|
+
|
67
|
+
* [kss.coffee](https://github.com/kneath/kss/blob/master/lib/kss.coffee)
|
68
|
+
* [kss.js](https://github.com/kneath/kss/blob/master/lib/kss.js) (compiled js)
|
69
|
+
|
70
|
+
For an example of how to generate a styleguide, check out the [`example`](https://github.com/kneath/kss/tree/master/example) sinatra application.
|
71
|
+
|
17
72
|
## Development
|
18
73
|
|
19
74
|
To hack on KSS, you'll need to install dependencies with `bundle install`. Run tests with `rake`.
|
data/lib/kss.coffee
ADDED
@@ -0,0 +1,38 @@
|
|
1
|
+
# This class scans your stylesheets for pseudo classes, then inserts a new CSS
|
2
|
+
# rule with the same properties, but named 'psuedo-class-{{name}}'.
|
3
|
+
#
|
4
|
+
# Supported pseudo classes: hover, disabled.
|
5
|
+
#
|
6
|
+
# Example:
|
7
|
+
#
|
8
|
+
# a:hover{ color:blue; }
|
9
|
+
# => a.pseudo-class-hover{ color:blue; }
|
10
|
+
class KssStateGenerator
|
11
|
+
constructor: ->
|
12
|
+
hover = /:hover/
|
13
|
+
disabled = /:disabled/
|
14
|
+
|
15
|
+
try
|
16
|
+
for stylesheet in document.styleSheets
|
17
|
+
idxs = []
|
18
|
+
for rule, idx in stylesheet.cssRules
|
19
|
+
if rule.type is CSSRule.STYLE_RULE and (hover.test(rule.selectorText) or disabled.test(rule.selectorText))
|
20
|
+
@insertRule(rule.cssText.replace(':', '.pseudo-class-'))
|
21
|
+
|
22
|
+
# Takes a given style and attaches it to the current page.
|
23
|
+
#
|
24
|
+
# rule - A CSS rule String (ex: ".test{ display:none; }").
|
25
|
+
#
|
26
|
+
# Returns nothing.
|
27
|
+
insertRule: (rule) ->
|
28
|
+
headEl = document.getElementsByTagName('head')[0]
|
29
|
+
styleEl = document.createElement('style')
|
30
|
+
styleEl.type = 'text/css'
|
31
|
+
if styleEl.styleSheet
|
32
|
+
styleEl.styleSheet.cssText = rule
|
33
|
+
else
|
34
|
+
styleEl.appendChild(document.createTextNode(rule))
|
35
|
+
|
36
|
+
headEl.appendChild(styleEl)
|
37
|
+
|
38
|
+
new KssStateGenerator
|
data/lib/kss/parser.rb
CHANGED
@@ -13,17 +13,27 @@ module Kss
|
|
13
13
|
|
14
14
|
Dir["#{base_path}/**/*.*"].each do |filename|
|
15
15
|
root_node = Sass::SCSS::Parser.new(File.read(filename), filename).parse
|
16
|
-
root_node
|
17
|
-
next unless node.is_a? Sass::Tree::CommentNode
|
18
|
-
comment_text = self.class.clean_comments node.value[0]
|
16
|
+
parse_node(root_node, filename)
|
19
17
|
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
def parse_node parent_node, filename
|
22
|
+
parent_node.children.each do |node|
|
23
|
+
unless node.is_a? Sass::Tree::CommentNode
|
24
|
+
parse_node(node, filename) if node.has_children
|
25
|
+
next
|
26
|
+
end
|
27
|
+
comment_text = self.class.clean_comments node.value[0]
|
28
|
+
|
29
|
+
if self.class.kss_block? comment_text
|
30
|
+
base_name = File.basename(filename)
|
31
|
+
section = Section.new(comment_text, base_name)
|
32
|
+
@sections[section.section] = section
|
25
33
|
end
|
26
34
|
end
|
35
|
+
|
36
|
+
parent_node
|
27
37
|
end
|
28
38
|
|
29
39
|
# Public: Takes a cleaned (no comment syntax like // or /* */) comment
|
@@ -34,7 +44,7 @@ module Kss
|
|
34
44
|
return false unless cleaned_comment.is_a? String
|
35
45
|
|
36
46
|
possible_reference = cleaned_comment.split("\n\n").last
|
37
|
-
possible_reference =~ /Styleguide \d/
|
47
|
+
possible_reference =~ /Styleguide \d/
|
38
48
|
end
|
39
49
|
|
40
50
|
# Takes the raw comment text including comment syntax and strips all
|
@@ -53,11 +63,13 @@ module Kss
|
|
53
63
|
text.gsub!(/^\/\*/, '') # starting block
|
54
64
|
text.gsub!(/\*\/$/, '') # ending block
|
55
65
|
|
66
|
+
text.gsub!(/^[ \t]+/, '') # remove leading whitespace
|
67
|
+
|
56
68
|
text.strip!
|
57
69
|
text
|
58
70
|
end
|
59
71
|
|
60
|
-
# Finds the Section for a given styleguide reference
|
72
|
+
# Public: Finds the Section for a given styleguide reference.
|
61
73
|
#
|
62
74
|
# Returns a Section for a reference, or a blank Section if none found.
|
63
75
|
def section(reference)
|
data/lib/kss/version.rb
CHANGED
data/test/parser_test.rb
CHANGED
@@ -26,6 +26,17 @@ comment
|
|
26
26
|
* Styleguide 2.2.1. */
|
27
27
|
comment
|
28
28
|
|
29
|
+
@indented_css_comment = <<comment
|
30
|
+
/*
|
31
|
+
A button suitable for giving stars to someone.
|
32
|
+
|
33
|
+
.star-given - A highlight indicating you've already given a star.
|
34
|
+
.disabled - Dims the button to indicate it cannot be used.
|
35
|
+
|
36
|
+
Styleguide 2.2.1.
|
37
|
+
*/
|
38
|
+
comment
|
39
|
+
|
29
40
|
@cleaned_css_comment = <<comment
|
30
41
|
A button suitable for giving stars to someone.
|
31
42
|
|
@@ -53,6 +64,13 @@ comment
|
|
53
64
|
Kss::Parser.clean_comments(@css_comment)
|
54
65
|
assert_equal @cleaned_css_comment,
|
55
66
|
Kss::Parser.clean_comments(@starred_css_comment)
|
67
|
+
assert_equal @cleaned_css_comment,
|
68
|
+
Kss::Parser.clean_comments(@indented_css_comment)
|
69
|
+
end
|
70
|
+
|
71
|
+
test "parses nested SCSS documents" do
|
72
|
+
assert_equal "Your standard form element.", @scss_parsed.section('3.0.0').description
|
73
|
+
assert_equal "Your standard text input box.", @scss_parsed.section('3.0.1').description
|
56
74
|
end
|
57
75
|
|
58
|
-
end
|
76
|
+
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: 31
|
5
5
|
prerelease:
|
6
6
|
segments:
|
7
7
|
- 0
|
8
8
|
- 1
|
9
|
-
-
|
10
|
-
version: 0.1.
|
9
|
+
- 2
|
10
|
+
version: 0.1.2
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- Kyle Neath
|
@@ -15,11 +15,10 @@ autorequire:
|
|
15
15
|
bindir: bin
|
16
16
|
cert_chain: []
|
17
17
|
|
18
|
-
date: 2011-12-
|
18
|
+
date: 2011-12-07 00:00:00 -08:00
|
19
19
|
default_executable:
|
20
20
|
dependencies:
|
21
21
|
- !ruby/object:Gem::Dependency
|
22
|
-
name: sass
|
23
22
|
prerelease: false
|
24
23
|
requirement: &id001 !ruby/object:Gem::Requirement
|
25
24
|
none: false
|
@@ -32,6 +31,7 @@ dependencies:
|
|
32
31
|
- 1
|
33
32
|
version: "3.1"
|
34
33
|
type: :runtime
|
34
|
+
name: sass
|
35
35
|
version_requirements: *id001
|
36
36
|
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
37
|
email: kneath@gmail.com
|
@@ -49,9 +49,11 @@ files:
|
|
49
49
|
- lib/kss/parser.rb
|
50
50
|
- lib/kss/section.rb
|
51
51
|
- lib/kss/version.rb
|
52
|
+
- lib/kss.coffee
|
52
53
|
- lib/kss.rb
|
53
54
|
- test/fixtures/css/buttons.css
|
54
55
|
- test/fixtures/scss/buttons.scss
|
56
|
+
- test/fixtures/scss/nested.scss
|
55
57
|
- test/helper.rb
|
56
58
|
- test/parser_test.rb
|
57
59
|
- test/section_test.rb
|