chunky_css 0.0.1

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/.gitignore ADDED
@@ -0,0 +1,17 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ Gemfile.lock
7
+ InstalledFiles
8
+ _yardoc
9
+ coverage
10
+ doc/
11
+ lib/bundler/man
12
+ pkg
13
+ rdoc
14
+ spec/reports
15
+ test/tmp
16
+ test/version_tmp
17
+ tmp
data/.rspec ADDED
File without changes
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in chunky_css.gemspec
4
+ gemspec
data/LICENSE ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2012 Kristofer Walters
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,37 @@
1
+ # ChunkyCSS
2
+
3
+ Split CSS into chunks by @media.
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ gem 'chunky_css'
10
+
11
+ And then execute:
12
+
13
+ $ bundle
14
+
15
+ Or install it yourself as:
16
+
17
+ $ gem install chunky_css
18
+
19
+ ## Usage
20
+
21
+ ```ruby
22
+ require 'chunky_css'
23
+
24
+ splitter = ChunkyCSS.split(css_str)
25
+ splitter.media # e.g ["all", "screen and (max-width: 1000px)"]
26
+ splitter.css_for_media("all") # e.g. "body { color:..."
27
+
28
+ ```
29
+
30
+
31
+ ## Contributing
32
+
33
+ 1. Fork it
34
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
35
+ 3. Commit your changes (`git commit -am 'Added some feature'`)
36
+ 4. Push to the branch (`git push origin my-new-feature`)
37
+ 5. Create new Pull Request
data/Rakefile ADDED
@@ -0,0 +1,7 @@
1
+ #!/usr/bin/env rake
2
+ require "bundler/gem_tasks"
3
+ require "rspec/core/rake_task"
4
+
5
+ RSpec::Core::RakeTask.new do |t|
6
+ t.ruby_opts = "-w"
7
+ end
@@ -0,0 +1,21 @@
1
+ # -*- encoding: utf-8 -*-
2
+ require File.expand_path('../lib/chunky_css/version', __FILE__)
3
+
4
+ Gem::Specification.new do |gem|
5
+ gem.authors = ["Kristofer Walters"]
6
+ gem.email = ["kris@wltrs.org"]
7
+ gem.description = %q{Splits css into chunks by @media}
8
+ gem.summary = %q{Splits css into chunks by @media}
9
+ gem.homepage = "https://github.com/kwltrs/chunky_css"
10
+
11
+ gem.rubyforge_project = "chunky_css"
12
+
13
+ gem.files = `git ls-files`.split($\)
14
+ gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
15
+ gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
16
+ gem.name = "chunky_css"
17
+ gem.require_paths = ["lib"]
18
+ gem.version = ChunkyCSS::VERSION
19
+
20
+ gem.add_development_dependency "rspec"
21
+ end
@@ -0,0 +1,3 @@
1
+ module ChunkyCSS
2
+ VERSION = "0.0.1"
3
+ end
data/lib/chunky_css.rb ADDED
@@ -0,0 +1,60 @@
1
+ require "chunky_css/version"
2
+ require "strscan"
3
+
4
+ module ChunkyCSS
5
+ def self.split(css)
6
+ return Splitter.new(css)
7
+ end
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
21
+
22
+ private
23
+
24
+ def parse(css)
25
+ buckets = {}
26
+
27
+ scanner = StringScanner.new(css)
28
+
29
+ current_bucket = "all"
30
+ indent = 0
31
+ inside_media = false
32
+
33
+ while !scanner.eos? do
34
+ if scanner.scan(/@media (.*?){/)
35
+ current_bucket = scanner[1].chop
36
+ indent += 1
37
+ inside_media = true
38
+ end
39
+
40
+ char = scanner.getch
41
+
42
+ if char == "{"
43
+ indent += 1
44
+ elsif char == "}"
45
+ indent -= 1
46
+ if indent == 0 && inside_media
47
+ inside_media = false
48
+ current_bucket = "all"
49
+ char = ""
50
+ end
51
+ end
52
+
53
+ buckets[current_bucket] ||= ""
54
+ buckets[current_bucket] += char
55
+ end
56
+
57
+ return buckets
58
+ end
59
+ end
60
+ end
@@ -0,0 +1,38 @@
1
+ require "chunky_css"
2
+
3
+ def fixture(fname)
4
+ File.read( File.join(File.dirname(__FILE__), "fixtures", fname) )
5
+ end
6
+
7
+ describe ChunkyCSS::Splitter do
8
+ context "simple.css" do
9
+ splitter = ChunkyCSS::Splitter.new(fixture("simple.css"))
10
+
11
+ it "has 3 media queries" do
12
+ splitter.media.length.should eq(3)
13
+ end
14
+
15
+ expectations = {
16
+ "all" => [1,2,7],
17
+ "screen" => [3,4],
18
+ "screen and (max-width: 100px)" => [5,6]
19
+ }
20
+
21
+ expectations.keys.each do |media|
22
+ it "has a '#{media}' entry" do
23
+ splitter.media.should include(media)
24
+ end
25
+
26
+ context "css for @media '#{media}'" do
27
+ css = splitter.css_for_media(media)
28
+
29
+ expectations[media].each do |rule_number|
30
+ it "contains css rule for .rule#{rule_number}" do
31
+ css.should include(".rule#{rule_number}")
32
+ end
33
+ end
34
+ end
35
+ end
36
+
37
+ end
38
+ end
@@ -0,0 +1,15 @@
1
+ .rule1 { color: red; }
2
+ .rule2 { color: red; }
3
+
4
+ @media screen {
5
+ .rule3 { color: green; }
6
+ .rule4 { color: green; }
7
+ }
8
+
9
+ @media screen and (max-width: 100px) {
10
+ .rule5 { color: blue; }
11
+ .rule6 { color: blue; }
12
+ }
13
+
14
+ .rule7 { color: red; }
15
+
metadata ADDED
@@ -0,0 +1,75 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: chunky_css
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Kristofer Walters
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2012-05-15 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: rspec
16
+ requirement: !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ! '>='
20
+ - !ruby/object:Gem::Version
21
+ version: '0'
22
+ type: :development
23
+ prerelease: false
24
+ version_requirements: !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ! '>='
28
+ - !ruby/object:Gem::Version
29
+ version: '0'
30
+ description: Splits css into chunks by @media
31
+ email:
32
+ - kris@wltrs.org
33
+ executables: []
34
+ extensions: []
35
+ extra_rdoc_files: []
36
+ files:
37
+ - .gitignore
38
+ - .rspec
39
+ - Gemfile
40
+ - LICENSE
41
+ - README.md
42
+ - Rakefile
43
+ - chunky_css.gemspec
44
+ - lib/chunky_css.rb
45
+ - lib/chunky_css/version.rb
46
+ - spec/chunky_css_spec.rb
47
+ - spec/fixtures/simple.css
48
+ homepage: https://github.com/kwltrs/chunky_css
49
+ licenses: []
50
+ post_install_message:
51
+ rdoc_options: []
52
+ require_paths:
53
+ - lib
54
+ required_ruby_version: !ruby/object:Gem::Requirement
55
+ none: false
56
+ requirements:
57
+ - - ! '>='
58
+ - !ruby/object:Gem::Version
59
+ version: '0'
60
+ required_rubygems_version: !ruby/object:Gem::Requirement
61
+ none: false
62
+ requirements:
63
+ - - ! '>='
64
+ - !ruby/object:Gem::Version
65
+ version: '0'
66
+ requirements: []
67
+ rubyforge_project: chunky_css
68
+ rubygems_version: 1.8.23
69
+ signing_key:
70
+ specification_version: 3
71
+ summary: Splits css into chunks by @media
72
+ test_files:
73
+ - spec/chunky_css_spec.rb
74
+ - spec/fixtures/simple.css
75
+ has_rdoc: