cssmin-cli 1.0.0

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,15 @@
1
+ *.gem
2
+ *.rbc
3
+ /.config
4
+ /coverage/
5
+ /InstalledFiles
6
+ /pkg/
7
+ /spec/reports/
8
+ /test/tmp/
9
+ /test/version_tmp
10
+ /tmp/
11
+ /doc/
12
+
13
+ /.bundle/
14
+
15
+ .rvmrc
data/.travis.yml ADDED
@@ -0,0 +1,6 @@
1
+ language: ruby
2
+ rvm:
3
+ - 2.1.0
4
+ - 1.9.3
5
+ - 1.8.7
6
+ - jruby-19mode
data/Gemfile ADDED
@@ -0,0 +1,9 @@
1
+ source "https://rubygems.org"
2
+
3
+ gem 'cssmin'
4
+ gem 'mercenary'
5
+
6
+ group :development, :test do
7
+ gem 'minitest'
8
+ gem 'rake'
9
+ end
data/Gemfile.lock ADDED
@@ -0,0 +1,17 @@
1
+ GEM
2
+ remote: https://rubygems.org/
3
+ specs:
4
+ cssmin (1.0.3)
5
+ mercenary
6
+ mercenary (0.3.2)
7
+ minitest (5.3.3)
8
+ rake (10.3.1)
9
+
10
+ PLATFORMS
11
+ ruby
12
+
13
+ DEPENDENCIES
14
+ cssmin
15
+ mercenary
16
+ minitest
17
+ rake
data/LICENSE.md ADDED
@@ -0,0 +1,26 @@
1
+ Copyright (c) 2014, Jan Ferko <jan.ferko3@gmail.com>
2
+ All rights reserved.
3
+
4
+ Redistribution and use in source and binary forms, with or without modification,
5
+ are permitted provided that the following conditions are met:
6
+
7
+ 1. Redistributions of source code must retain the above copyright notice,
8
+ this list of conditions and the following disclaimer.
9
+
10
+ 2. Redistributions in binary form must reproduce the above copyright notice,
11
+ this list of conditions and the following disclaimer in the documentation
12
+ and/or other materials provided with the distribution.
13
+
14
+ 3. Neither the name of copyright holder nor the names of its contributors
15
+ may be used to endorse or promote products derived from this software
16
+ without specific prior written permission.
17
+
18
+ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
19
+ AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
20
+ THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
21
+ PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS
22
+ BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
23
+ DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
24
+ LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
25
+ THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
26
+ ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
data/README.md ADDED
File without changes
data/Rakefile ADDED
@@ -0,0 +1,18 @@
1
+ require 'rake/testtask'
2
+ require 'rdoc/task'
3
+
4
+ RDoc::Task.new do |rd|
5
+ rd.main = 'CSSMin-cli'
6
+ rd.title = 'CSSMin-cli'
7
+ rd.rdoc_dir = 'doc'
8
+
9
+ rd.rdoc_files.include('lib/**/*.rb')
10
+ end
11
+
12
+ Rake::TestTask.new do |t|
13
+ t.libs.push 'lib'
14
+ t.test_files = FileList['test/*_test.rb']
15
+ t.verbose = true
16
+ end
17
+
18
+ task :default => [:test]
data/bin/cssmin ADDED
@@ -0,0 +1,27 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ $LOAD_PATH.unshift(File.dirname(__FILE__), "../lib")
4
+
5
+ require 'cssmin_cli'
6
+ require 'mercenary'
7
+
8
+ Mercenary.program(:cssmin_cli) do |p|
9
+ p.description "Command line tool for minifying CSS."
10
+ p.syntax "cssmin [options]"
11
+
12
+ p.option "source", "-s", "--source FILE",
13
+ "CSS source file. Is required if input is not provided."
14
+ p.option "inline", "-i", "--inline CSS",
15
+ "CSS string. Is required if source isn't provided."
16
+ p.option "destination", "-d", "--destination [FILE]", "Destination file (defaults to stdout)"
17
+
18
+ p.action do |_, options|
19
+ opts = Hash[options.map { |k, v| [k.to_sym, v]}]
20
+
21
+ unless opts[:source] || opts[:inline]
22
+ return puts p
23
+ end
24
+ CSSMinCli::run(opts)
25
+ puts "\n" unless opts[:destination]
26
+ end
27
+ end
@@ -0,0 +1,28 @@
1
+ Gem::Specification.new do |s|
2
+ s.name = "cssmin-cli"
3
+ s.version = "1.0.0"
4
+ s.date = "2014-04-24"
5
+ s.summary = "Command line tool for minifying CSS."
6
+ s.description = "Command line tool for minifying CSS. Based on CSSMin library."
7
+
8
+ s.authors = ["Jan Ferko"]
9
+ s.email = "jan.ferko3@gmail.com"
10
+ s.license = "BSD"
11
+
12
+ s.homepage = "http://github.com/iref/cssmin-cli"
13
+
14
+ s.files = `git ls-files`.split($/)
15
+ s.test_files = s.files.grep(%r{^test/})
16
+ s.executables << 'cssmin'
17
+ s.require_path = 'lib'
18
+ s.has_rdoc = true
19
+
20
+ s.required_ruby_version = ">= 1.8.6"
21
+
22
+ s.add_runtime_dependency "cssmin"
23
+ s.add_runtime_dependency "mercenary"
24
+
25
+ s.add_development_dependency "rake"
26
+ s.add_development_dependency "minitest"
27
+
28
+ end
data/lib/cssmin_cli.rb ADDED
@@ -0,0 +1,94 @@
1
+ # Copyright (c) 2014, Jan Ferko <jan.ferko3@gmail.com>
2
+ # All rights reserved.
3
+ #
4
+ # Redistribution and use in source and binary forms, with or without modification,
5
+ # are permitted provided that the following conditions are met:
6
+ #
7
+ # 1. Redistributions of source code must retain the above copyright notice,
8
+ # this list of conditions and the following disclaimer.
9
+ #
10
+ # 2. Redistributions in binary form must reproduce the above copyright notice,
11
+ # this list of conditions and the following disclaimer in the documentation
12
+ # and/or other materials provided with the distribution.
13
+ #
14
+ # 3. Neither the name of copyright holder nor the names of its contributors
15
+ # may be used to endorse or promote products derived from this software
16
+ # without specific prior written permission.
17
+ #
18
+ # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
19
+ # AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
20
+ # THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
21
+ # PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS
22
+ # BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
23
+ # DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
24
+ # LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
25
+ # THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
26
+ # ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27
+
28
+ require 'cssmin'
29
+
30
+ # = CSSMinCli
31
+ #
32
+ # Command line runner for CSSMin library.
33
+ # For more details on CSSMin, please check http://github.com/rgrove/cssmin
34
+ #
35
+ # Author:: Jan Ferko (mailto: jan.ferko3@gmail.com)
36
+ # Version:: 1.0 (2014-04-24)
37
+ # Copyright:: Copyright (c) 2014 Jan Ferko. All rights reserved.
38
+ # License:: New BSD License (http://opensource.org/licenses/BSD-3-Clause)
39
+ # Website:: http://github.com/iref/cssmin-cli
40
+ #
41
+ module CSSMinCli
42
+
43
+ # Runs minifier for given options.
44
+ #
45
+ # Currently supported options are:
46
+ # source - CSS source file
47
+ # inline - String containing CSS
48
+ # destination - File, where to store minified CSS. Default is stdout.
49
+ #
50
+ # Returns true if css was successfully minified and stored,
51
+ # otherwise false.
52
+ def self.run(options)
53
+ destination = resolve_destination(options[:destination])
54
+ source = resolve_source(options)
55
+
56
+ return false unless source
57
+
58
+ minified = CSSMin::minify(source)
59
+
60
+ destination.write(minified)
61
+ destination.close
62
+
63
+ return true
64
+ end
65
+
66
+ # Resolves CSS source for given options.
67
+ # Inline option has precedence over source option.
68
+ #
69
+ # Supported options are:
70
+ # source - Path to CSS source file
71
+ # inline - String containing CSS
72
+ #
73
+ # Returns string, that contains loaded css from source or
74
+ # nil if invalid options hash was provided.
75
+ def self.resolve_source(options)
76
+ if options[:inline]
77
+ options[:inline]
78
+ elsif options[:source]
79
+ IO.read(options[:source])
80
+ end
81
+ end
82
+
83
+ # Resolves destination where minified CSS
84
+ # should be stored.
85
+ #
86
+ # Params:
87
+ # destination - path to file, where minified css should be stored. Defaults to STDOUT
88
+ #
89
+ # Returns opened IO object.
90
+ def self.resolve_destination(destination)
91
+ return $stdout unless destination
92
+ File.open(destination, "w")
93
+ end
94
+ end
@@ -0,0 +1,64 @@
1
+ require 'minitest/autorun'
2
+
3
+ require 'stringio'
4
+ require 'cssmin_cli'
5
+
6
+ describe CSSMinCli do
7
+ subject { CSSMinCli.run(options) }
8
+
9
+ describe "returns false if source or inline is not in options" do
10
+ let (:options) { {} }
11
+
12
+ it { subject.must_equal false }
13
+ end
14
+
15
+ describe "prints minified css to stdout if destination is not provided" do
16
+ let (:options) do
17
+ {:source => "test/fixtures/simple.css"}
18
+ end
19
+
20
+ let(:expected_minified_css) { IO.read("test/fixtures/simple.min.css").strip }
21
+
22
+ it { Proc.new {subject}.must_output expected_minified_css }
23
+ end
24
+
25
+ describe "reads css from inline option" do
26
+ let (:options) do
27
+ {:inline => IO.read("test/fixtures/simple.css")}
28
+ end
29
+
30
+ let (:expected_minified_css) do
31
+ IO.read("test/fixtures/simple.min.css").strip
32
+ end
33
+
34
+ it { Proc.new { subject }.must_output expected_minified_css }
35
+ end
36
+
37
+ describe "reads css from source option" do
38
+ let (:options) do
39
+ {:source => "test/fixtures/simple.css"}
40
+ end
41
+
42
+ let (:expected_minified_css) do
43
+ IO.read("test/fixtures/simple.min.css").strip
44
+ end
45
+
46
+ it { Proc.new { subject }.must_output expected_minified_css }
47
+ end
48
+
49
+ describe "prints minified css to file if destination is provided" do
50
+ let (:options) do
51
+ {:inline => IO.read("test/fixtures/simple.css"),
52
+ :destination => "test_result.min.css"}
53
+ end
54
+
55
+ after do
56
+ File.delete("test_result.min.css")
57
+ end
58
+
59
+ it do
60
+ subject
61
+ File.exists?("test_result.min.css").must_equal true
62
+ end
63
+ end
64
+ end
@@ -0,0 +1,5 @@
1
+ .octocat {
2
+ /* octocat class */
3
+ background: #fff;
4
+ border: 1px solid #000;
5
+ }
@@ -0,0 +1 @@
1
+ .octocat{background:#fff;border:1px solid #000}
metadata ADDED
@@ -0,0 +1,126 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: cssmin-cli
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.0.0
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Jan Ferko
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2014-04-24 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: cssmin
16
+ requirement: !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ! '>='
20
+ - !ruby/object:Gem::Version
21
+ version: '0'
22
+ type: :runtime
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
+ - !ruby/object:Gem::Dependency
31
+ name: mercenary
32
+ requirement: !ruby/object:Gem::Requirement
33
+ none: false
34
+ requirements:
35
+ - - ! '>='
36
+ - !ruby/object:Gem::Version
37
+ version: '0'
38
+ type: :runtime
39
+ prerelease: false
40
+ version_requirements: !ruby/object:Gem::Requirement
41
+ none: false
42
+ requirements:
43
+ - - ! '>='
44
+ - !ruby/object:Gem::Version
45
+ version: '0'
46
+ - !ruby/object:Gem::Dependency
47
+ name: rake
48
+ requirement: !ruby/object:Gem::Requirement
49
+ none: false
50
+ requirements:
51
+ - - ! '>='
52
+ - !ruby/object:Gem::Version
53
+ version: '0'
54
+ type: :development
55
+ prerelease: false
56
+ version_requirements: !ruby/object:Gem::Requirement
57
+ none: false
58
+ requirements:
59
+ - - ! '>='
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ - !ruby/object:Gem::Dependency
63
+ name: minitest
64
+ requirement: !ruby/object:Gem::Requirement
65
+ none: false
66
+ requirements:
67
+ - - ! '>='
68
+ - !ruby/object:Gem::Version
69
+ version: '0'
70
+ type: :development
71
+ prerelease: false
72
+ version_requirements: !ruby/object:Gem::Requirement
73
+ none: false
74
+ requirements:
75
+ - - ! '>='
76
+ - !ruby/object:Gem::Version
77
+ version: '0'
78
+ description: Command line tool for minifying CSS. Based on CSSMin library.
79
+ email: jan.ferko3@gmail.com
80
+ executables:
81
+ - cssmin
82
+ extensions: []
83
+ extra_rdoc_files: []
84
+ files:
85
+ - .gitignore
86
+ - .travis.yml
87
+ - Gemfile
88
+ - Gemfile.lock
89
+ - LICENSE.md
90
+ - README.md
91
+ - Rakefile
92
+ - bin/cssmin
93
+ - cssmin-cli.gemspec
94
+ - lib/cssmin_cli.rb
95
+ - test/cssmin_cli_test.rb
96
+ - test/fixtures/simple.css
97
+ - test/fixtures/simple.min.css
98
+ homepage: http://github.com/iref/cssmin-cli
99
+ licenses:
100
+ - BSD
101
+ post_install_message:
102
+ rdoc_options: []
103
+ require_paths:
104
+ - lib
105
+ required_ruby_version: !ruby/object:Gem::Requirement
106
+ none: false
107
+ requirements:
108
+ - - ! '>='
109
+ - !ruby/object:Gem::Version
110
+ version: 1.8.6
111
+ required_rubygems_version: !ruby/object:Gem::Requirement
112
+ none: false
113
+ requirements:
114
+ - - ! '>='
115
+ - !ruby/object:Gem::Version
116
+ version: '0'
117
+ requirements: []
118
+ rubyforge_project:
119
+ rubygems_version: 1.8.23
120
+ signing_key:
121
+ specification_version: 3
122
+ summary: Command line tool for minifying CSS.
123
+ test_files:
124
+ - test/cssmin_cli_test.rb
125
+ - test/fixtures/simple.css
126
+ - test/fixtures/simple.min.css