css_compressor 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.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 30506eef39d768bf25ded0df758a6275c44d39fd
4
+ data.tar.gz: cd5202ef9a82da079ccb7d42d77fdf8373f94d19
5
+ SHA512:
6
+ metadata.gz: 99c8881d907cc7fad21bac9d69071c9e95885ce1f9b690bd64c4210d9fc9c0688459738689a653bfe7ec66de5cc22153ab7efb86b5594bb32fb623e56c8e94c1
7
+ data.tar.gz: 9b89d8d3777bbe2ade491872738afd1d26a2e120a95fc1e9178c14fb54464f9160030f5c97d707f321f501143dca821dd3357aaa72664e9b45c8158819534acb
@@ -0,0 +1,17 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
10
+ *.gem
11
+ *.bundle
12
+ *.so
13
+ *.o
14
+ *.a
15
+ mkmf.log
16
+ *.DS_Store
17
+ *.log
@@ -0,0 +1,8 @@
1
+ rvm:
2
+ - 2.0.0
3
+ - 2.1.1
4
+
5
+ install:
6
+ - "travis_retry bundle install"
7
+
8
+ script: "bundle exec rake"
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in css_compressor.gemspec
4
+ gemspec
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2014 Rodrigo Alves
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.
@@ -0,0 +1,47 @@
1
+ # CssCompressor
2
+
3
+ A Ruby gem for compressing CSS files
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ ```ruby
10
+ gem 'css_compressor'
11
+ ```
12
+
13
+ or install via Rubygems, directly:
14
+
15
+ ```shell
16
+ $ gem install css_compressor
17
+ ```
18
+
19
+ ## Usage
20
+
21
+ You can use this gem from your code:
22
+
23
+ ```ruby
24
+ require "css_compressor"
25
+
26
+ compressor = CssCompressor.new
27
+
28
+ # Pass a css file directly
29
+ compressor.compress("path/to/css_file.css")
30
+
31
+ # Pass the content of a css file instead
32
+ content = "
33
+ background-color: #fff;
34
+ border: 1px solid #ddd;
35
+ border-bottom-left-radius: 3px;
36
+ border-bottom-right-radius: 3px;
37
+ padding: 30px;
38
+ word-wrap: break-word;"
39
+
40
+ compressor.compress_raw(content)
41
+ ```
42
+
43
+ ## License
44
+
45
+ [MIT]
46
+
47
+ [MIT]: https://github.com/rodrigoalvesvieira/css_compressor/blob/master/LICENSE.txt
@@ -0,0 +1,12 @@
1
+ require "bundler/gem_tasks"
2
+ require 'rake/testtask'
3
+
4
+ Rake::TestTask.new(:test) do |t|
5
+ t.libs << 'lib'
6
+ t.libs << 'test'
7
+ t.pattern = 'test/**/*_test.rb'
8
+ t.verbose = true
9
+ end
10
+
11
+ desc "Run tests"
12
+ task default: :test
@@ -0,0 +1,22 @@
1
+ lib = File.expand_path('../lib', __FILE__)
2
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
3
+ require 'css_compressor/version'
4
+
5
+ Gem::Specification.new do |spec|
6
+ spec.name = "css_compressor"
7
+ spec.version = CssCompressor::VERSION
8
+ spec.authors = ["Rodrigo Alves"]
9
+ spec.email = ["rodrigovieira1994@gmail.com"]
10
+ spec.summary = %q{CSS file compressor in Ruby}
11
+ spec.description = %q{A Ruby gem for compressing CSS files}
12
+ spec.homepage = "https://github.com/rodrigoalvesvieira/css_compressor"
13
+ spec.license = "MIT"
14
+
15
+ spec.files = `git ls-files -z`.split("\x0")
16
+ spec.test_files = spec.files.grep(%r{^(test)/})
17
+ spec.require_paths = ["lib"]
18
+
19
+ spec.add_development_dependency "bundler", "~> 1.7"
20
+ spec.add_development_dependency "rake", "~> 10.0"
21
+ spec.add_development_dependency "minitest", "~> 5.4", ">= 5.4.2"
22
+ end
@@ -0,0 +1,32 @@
1
+ require "css_compressor/version"
2
+
3
+ class CssCompressor
4
+ def initialize
5
+ end
6
+
7
+ def compress_raw(css_input)
8
+ return _compress(css_input)
9
+ end
10
+
11
+ def compress(file_path)
12
+ css_input = File.read file_path
13
+ return _compress(css_input)
14
+ end
15
+
16
+ private
17
+
18
+ def _compress(css_input)
19
+ css_input.gsub!(/\/\*.*?\*\//m, "") # Remove comments
20
+ css_input.gsub!(/\n/, "") # Remove line breaks
21
+ css_input.gsub!(/\s+{/, "{") # Remove spaces before opening brackets
22
+ css_input.gsub!(/{\s+/, "{") # Remove spaces after opening brackets
23
+ css_input.gsub!(/\s+}/, "}") # Remove spaces before closing brackets
24
+ css_input.gsub!(/}\s+/, "}") # Remove spaces after closing brackets
25
+ css_input.gsub!(/;\s+/, ";") # Remove trailing spaces after ; (different properties)
26
+ css_input.gsub!(/:\s+/, ":") # Remove spaces between property name and value
27
+
28
+ css_input.strip!
29
+
30
+ return css_input
31
+ end
32
+ end
@@ -0,0 +1,3 @@
1
+ class CssCompressor
2
+ VERSION = "0.0.1"
3
+ end
@@ -0,0 +1,35 @@
1
+ require "test_helper"
2
+
3
+ class CssCompressorTest < MiniTest::Test
4
+ def setup
5
+ @@compressor = CssCompressor.new
6
+ end
7
+
8
+ def test_object_initialization
9
+ assert_equal @@compressor.class, CssCompressor
10
+ end
11
+
12
+ def test_compress_raw
13
+ content = "
14
+ background-color: #fff;
15
+ border: 1px solid #ddd;
16
+ border-bottom-left-radius: 3px;
17
+ border-bottom-right-radius: 3px;
18
+ padding: 30px;
19
+ word-wrap: break-word;"
20
+
21
+ compressed = "background-color:#fff;border:1px solid #ddd;border-bottom-left-radius:3px;border-bottom-right-radius:3px;padding:30px;word-wrap:break-word;"
22
+
23
+ result = @@compressor.compress_raw(content)
24
+ assert_equal result, compressed
25
+ end
26
+
27
+ def test_compress
28
+ css_file = File.dirname(__FILE__) + "/seeds/styles.css"
29
+
30
+ compressed_file = ".myElement{background-color:rgba(0,0,0,.2);background-clip:padding-box;border:solid transparent;border-width:1px 1px 1px 6px;min-height:28px;padding:100px 0 0;box-shadow:inset 1px 1px 0 rgba(0,0,0,.1),inset 0 -1px 0 rgba(0,0,0,.07);}.beautifilDiv{box-shadow:0 1px 0 rgba(0,0,0,.05);background-color:#427fed;background-image:-webkit-linear-gradient(top,transparent,transparent);background-image:linear-gradient(top,transparent,transparent);border:1px solid transparent;color:#fff;}"
31
+
32
+ result = @@compressor.compress css_file
33
+ assert_equal result, compressed_file
34
+ end
35
+ end
@@ -0,0 +1,18 @@
1
+ .myElement {
2
+ background-color: rgba(0,0,0,.2);
3
+ background-clip: padding-box;
4
+ border: solid transparent;
5
+ border-width: 1px 1px 1px 6px;
6
+ min-height: 28px;
7
+ padding: 100px 0 0;
8
+ box-shadow: inset 1px 1px 0 rgba(0,0,0,.1),inset 0 -1px 0 rgba(0,0,0,.07);
9
+ }
10
+
11
+ .beautifilDiv {
12
+ box-shadow: 0 1px 0 rgba(0,0,0,.05);
13
+ background-color: #427fed;
14
+ background-image: -webkit-linear-gradient(top,transparent,transparent);
15
+ background-image: linear-gradient(top,transparent,transparent);
16
+ border: 1px solid transparent;
17
+ color: #fff;
18
+ }
@@ -0,0 +1,5 @@
1
+ require 'minitest/autorun'
2
+ require 'minitest/pride'
3
+
4
+ $LOAD_PATH << File.dirname(__FILE__) + "/../lib"
5
+ require "css_compressor"
metadata ADDED
@@ -0,0 +1,107 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: css_compressor
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Rodrigo Alves
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2014-11-28 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '1.7'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.7'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '10.0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '10.0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: minitest
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '5.4'
48
+ - - ">="
49
+ - !ruby/object:Gem::Version
50
+ version: 5.4.2
51
+ type: :development
52
+ prerelease: false
53
+ version_requirements: !ruby/object:Gem::Requirement
54
+ requirements:
55
+ - - "~>"
56
+ - !ruby/object:Gem::Version
57
+ version: '5.4'
58
+ - - ">="
59
+ - !ruby/object:Gem::Version
60
+ version: 5.4.2
61
+ description: A Ruby gem for compressing CSS files
62
+ email:
63
+ - rodrigovieira1994@gmail.com
64
+ executables: []
65
+ extensions: []
66
+ extra_rdoc_files: []
67
+ files:
68
+ - ".gitignore"
69
+ - ".travis.yml"
70
+ - Gemfile
71
+ - LICENSE.txt
72
+ - README.md
73
+ - Rakefile
74
+ - css_compressor.gemspec
75
+ - lib/css_compressor.rb
76
+ - lib/css_compressor/version.rb
77
+ - test/css_compressor_test.rb
78
+ - test/seeds/styles.css
79
+ - test/test_helper.rb
80
+ homepage: https://github.com/rodrigoalvesvieira/css_compressor
81
+ licenses:
82
+ - MIT
83
+ metadata: {}
84
+ post_install_message:
85
+ rdoc_options: []
86
+ require_paths:
87
+ - lib
88
+ required_ruby_version: !ruby/object:Gem::Requirement
89
+ requirements:
90
+ - - ">="
91
+ - !ruby/object:Gem::Version
92
+ version: '0'
93
+ required_rubygems_version: !ruby/object:Gem::Requirement
94
+ requirements:
95
+ - - ">="
96
+ - !ruby/object:Gem::Version
97
+ version: '0'
98
+ requirements: []
99
+ rubyforge_project:
100
+ rubygems_version: 2.2.2
101
+ signing_key:
102
+ specification_version: 4
103
+ summary: CSS file compressor in Ruby
104
+ test_files:
105
+ - test/css_compressor_test.rb
106
+ - test/seeds/styles.css
107
+ - test/test_helper.rb