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 +2 -0
- data/lib/chunky_css.rb +29 -14
- data/lib/chunky_css/version.rb +1 -1
- data/spec/chunky_css_spec.rb +19 -0
- metadata +2 -2
data/README.md
CHANGED
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
|
-
|
6
|
+
Splitter.new(css)
|
7
7
|
end
|
8
8
|
|
9
|
-
|
10
|
-
|
11
|
-
|
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
|
data/lib/chunky_css/version.rb
CHANGED
data/spec/chunky_css_spec.rb
CHANGED
@@ -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.
|
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-
|
12
|
+
date: 2012-05-16 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: rspec
|