chunky_css 0.0.2 → 0.0.3

Sign up to get free protection for your applications and to get access to all the features.
data/README.md CHANGED
@@ -25,6 +25,8 @@ splitter = ChunkyCSS.split(css_str)
25
25
  splitter.media # e.g ["all", "screen and (max-width: 1000px)"]
26
26
  splitter.css_for_media("all") # e.g. "body { color:..."
27
27
 
28
+
29
+ css = ChunkyCSS.group(css_str)
28
30
  ```
29
31
 
30
32
 
data/lib/chunky_css.rb CHANGED
@@ -3,24 +3,15 @@ require "strscan"
3
3
 
4
4
  module ChunkyCSS
5
5
  def self.split(css)
6
- return Splitter.new(css)
6
+ Splitter.new(css)
7
7
  end
8
8
 
9
- class Splitter
10
- def initialize(css)
11
- @buckets = parse(css)
12
- end
13
-
14
- def media
15
- @buckets.keys
16
- end
17
-
18
- def css_for_media(media)
19
- @buckets[media]
20
- end
9
+ def self.group(css)
10
+ Grouper.new(css).grouped_css
11
+ end
21
12
 
22
- private
23
13
 
14
+ module Parser
24
15
  def parse(css)
25
16
  buckets = {}
26
17
 
@@ -57,4 +48,28 @@ module ChunkyCSS
57
48
  return buckets
58
49
  end
59
50
  end
51
+
52
+ class Splitter
53
+ include Parser
54
+
55
+ def initialize(css)
56
+ @buckets = parse(css)
57
+ end
58
+
59
+ def media
60
+ @buckets.keys
61
+ end
62
+
63
+ def css_for_media(media)
64
+ @buckets[media]
65
+ end
66
+ end
67
+
68
+ class Grouper < Splitter
69
+ def grouped_css
70
+ [@buckets["all"]].concat(@buckets.keys.reject{|key| key=="all"}.map {|key|
71
+ "@media %s{%s}"%[key, @buckets[key]]
72
+ }).join("\n")
73
+ end
74
+ end
60
75
  end
@@ -1,3 +1,3 @@
1
1
  module ChunkyCSS
2
- VERSION = "0.0.2"
2
+ VERSION = "0.0.3"
3
3
  end
@@ -37,3 +37,22 @@ describe ChunkyCSS::Splitter do
37
37
  end
38
38
  end
39
39
  end
40
+
41
+ describe ChunkyCSS::Grouper do
42
+ context "simple-compressed.css" do
43
+ grouper = ChunkyCSS::Grouper.new(fixture("simple-compressed.css"))
44
+ css = grouper.grouped_css
45
+
46
+ it "starts with global rules without @media" do
47
+ css.should start_with(".rule1{color: red;}.rule2{color: red;}.rule7{color: red;}")
48
+ end
49
+
50
+ it "has a 'screen' entry" do
51
+ css.should include("@media screen{")
52
+ end
53
+
54
+ it "has a 'screen and max-width' entry" do
55
+ css.should include("@media screen and (max-width: 100px){")
56
+ end
57
+ end
58
+ end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: chunky_css
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.2
4
+ version: 0.0.3
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-05-15 00:00:00.000000000 Z
12
+ date: 2012-05-16 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rspec