roger_yuicompressor 1.0.1 → 1.1.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.
- checksums.yaml +8 -8
- data/.travis.yml +12 -0
- data/CHANGELOG.md +3 -0
- data/Gemfile +5 -0
- data/Gemfile.lock +32 -0
- data/Rakefile +9 -0
- data/lib/roger_yuicompressor/processor.rb +76 -37
- data/roger_yuicompressor.gemspec +1 -1
- data/test/unit/processor_test.rb +58 -0
- metadata +9 -3
checksums.yaml
CHANGED
@@ -1,15 +1,15 @@
|
|
1
1
|
---
|
2
2
|
!binary "U0hBMQ==":
|
3
3
|
metadata.gz: !binary |-
|
4
|
-
|
4
|
+
MjhlYzQ2NjU5MGU1NTI4MGI5YzE3NzdjMzFiZmY3OTgzMGE2NmViOQ==
|
5
5
|
data.tar.gz: !binary |-
|
6
|
-
|
6
|
+
NzJiZWFjZTJhOWVmNTQwNDg1OTFkYTA5YWUxNDhlOWI2YjEwMDgwNQ==
|
7
7
|
SHA512:
|
8
8
|
metadata.gz: !binary |-
|
9
|
-
|
10
|
-
|
11
|
-
|
9
|
+
MTUxNDcxOTI0NDQ2OWE3MzcyYTkyMmUzMWFmNTcxNjk1OGYzZTQ4NTY3MTc2
|
10
|
+
N2M5N2IyYTdhMjIwZDU0NDcxOWJjZTQ1NGY2MmMyYjRjODAxZWUzM2RiODhh
|
11
|
+
MGZjMjY5MWY3ODFmZWY4NTQ3M2Q4NDRhYTljMDJjODI4MzY2MmI=
|
12
12
|
data.tar.gz: !binary |-
|
13
|
-
|
14
|
-
|
15
|
-
|
13
|
+
YjE2NzFhM2I3YTVkMmY2ZjRlNjg2ZTkxZTZhMTJhMjMwOTk1OTUxODRjYThl
|
14
|
+
YWJkNDhjNzI4ZmQyNWYxMWUzYjYzYTJmNmM1YTBhMWNkNzA0ZjcyYTcwNTI5
|
15
|
+
MGY0YTc4MzE1ZmY4ZjI4ZWJmMGU0OGMyMzkwNTFmNjk1OTU2OGY=
|
data/.travis.yml
ADDED
data/CHANGELOG.md
CHANGED
data/Gemfile
ADDED
data/Gemfile.lock
ADDED
@@ -0,0 +1,32 @@
|
|
1
|
+
PATH
|
2
|
+
remote: .
|
3
|
+
specs:
|
4
|
+
roger_yuicompressor (1.0.1)
|
5
|
+
roger (>= 0.11.0)
|
6
|
+
yui-compressor
|
7
|
+
|
8
|
+
GEM
|
9
|
+
remote: https://rubygems.org/
|
10
|
+
specs:
|
11
|
+
hpricot (0.8.6)
|
12
|
+
mime-types (2.3)
|
13
|
+
rack (1.5.2)
|
14
|
+
rake (10.3.2)
|
15
|
+
redcarpet (3.1.2)
|
16
|
+
roger (0.12.2)
|
17
|
+
hpricot (>= 0.6.4)
|
18
|
+
mime-types (~> 2.2)
|
19
|
+
rack (>= 1.0.0)
|
20
|
+
redcarpet (>= 3.1.1)
|
21
|
+
thor (~> 0.16.0)
|
22
|
+
tilt (~> 2.0.1)
|
23
|
+
thor (0.16.0)
|
24
|
+
tilt (2.0.1)
|
25
|
+
yui-compressor (0.12.0)
|
26
|
+
|
27
|
+
PLATFORMS
|
28
|
+
ruby
|
29
|
+
|
30
|
+
DEPENDENCIES
|
31
|
+
rake
|
32
|
+
roger_yuicompressor!
|
data/Rakefile
ADDED
@@ -1,5 +1,23 @@
|
|
1
|
+
require 'roger/release'
|
2
|
+
require 'yui/compressor'
|
3
|
+
|
1
4
|
module RogerYuicompressor
|
2
|
-
class Yuicompressor < Roger::Release::Processors::Base
|
5
|
+
class Yuicompressor < ::Roger::Release::Processors::Base
|
6
|
+
|
7
|
+
attr_reader :options
|
8
|
+
|
9
|
+
def initialize(options={})
|
10
|
+
@options = {
|
11
|
+
:match => ["**/*.{css,js}"],
|
12
|
+
:skip => [/javascripts\/vendor\/.*\.js\Z/, /_doc\/.*/],
|
13
|
+
:delimiter => Regexp.escape("/* -------------------------------------------------------------------------------- */"),
|
14
|
+
:suffix => nil
|
15
|
+
}.update(options)
|
16
|
+
|
17
|
+
compressor_options = {:line_break => 80}
|
18
|
+
@css_compressor = YUI::CssCompressor.new(compressor_options)
|
19
|
+
@js_compressor = YUI::JavaScriptCompressor.new(compressor_options)
|
20
|
+
end
|
3
21
|
|
4
22
|
# Compresses all JS and CSS files, it will keep all lines before
|
5
23
|
#
|
@@ -10,48 +28,69 @@ module RogerYuicompressor
|
|
10
28
|
# @options options [Array] match Files to match, default to ["**/*.{css,js}"]
|
11
29
|
# @options options [Regexp] :delimiter An array of header delimiters. Defaults to the one above. The delimiter will be removed from the output.
|
12
30
|
# @options options [Array[Regexp]] :skip An array of file regular expressions to specifiy which files to skip. Defaults to [/javascripts\/vendor\/.\*.js\Z/, /_doc\/.*/]
|
31
|
+
# @options options [Nil|string] :suffix A string that will be added to the filename of the minified file, if set to nil will overwrite the existing file. Defaults to nil.
|
32
|
+
# (example: test.js => test.min.js where :suffix => '.min').
|
13
33
|
def call(release, options={})
|
14
|
-
options
|
15
|
-
|
16
|
-
:skip => [/javascripts\/vendor\/.*\.js\Z/, /_doc\/.*/],
|
17
|
-
:delimiter => Regexp.escape("/* -------------------------------------------------------------------------------- */")
|
18
|
-
}.update(options)
|
19
|
-
|
20
|
-
compressor_options = {:line_break => 80}
|
21
|
-
css_compressor = YUI::CssCompressor.new(compressor_options)
|
22
|
-
js_compressor = YUI::JavaScriptCompressor.new(compressor_options)
|
23
|
-
|
34
|
+
@options.update(options)
|
35
|
+
|
24
36
|
release.log self, "Minifying #{options[:match].inspect}"
|
25
|
-
|
37
|
+
|
38
|
+
raise(RuntimeError, "The given suffix #{@options[:suffix]} is invalid.") unless valid_suffix?(@options[:sufix])
|
39
|
+
|
26
40
|
# Add version numbers and minify the files
|
27
|
-
release.get_files(options[:match], options[:skip]).each do |
|
28
|
-
|
41
|
+
release.get_files(options[:match], options[:skip]).each do |filename|
|
42
|
+
minify_file(filename, release)
|
43
|
+
end
|
44
|
+
end
|
45
|
+
|
46
|
+
# Retrieve the type of the file (based on extension)
|
47
|
+
#
|
48
|
+
# @param [String] The name of the file incl. extension
|
49
|
+
def get_file_type(filename)
|
50
|
+
filename[/\.([^.]+)\Z/, 1]
|
51
|
+
end
|
52
|
+
|
53
|
+
# Check if a valid suffix is given
|
54
|
+
def valid_suffix?(suffix = nil)
|
55
|
+
suffix === nil || suffix.kind_of?(String)
|
56
|
+
end
|
57
|
+
|
58
|
+
# Read and minfiy the given file
|
59
|
+
def minify_file(file, release)
|
60
|
+
data = File.read(file);
|
61
|
+
type = get_file_type(file)
|
62
|
+
|
63
|
+
if @options[:suffix] != nil
|
64
|
+
output_file = file.sub(".#{type}", "") + @options[:suffix] + ".#{type}"
|
65
|
+
else
|
66
|
+
output_file = file
|
67
|
+
end
|
68
|
+
|
69
|
+
File.open(output_file, "w") do |fh|
|
29
70
|
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
else
|
45
|
-
release.warn self, "Error minifying: encountered unknown type \"#{type}\""
|
46
|
-
minified << data
|
47
|
-
end
|
48
|
-
|
49
|
-
fh.write minified.join("\n")
|
71
|
+
# Extract header and store for later use
|
72
|
+
header = data[/\A(.+?)\n#{options[:delimiter]}\s*\n/m,1]
|
73
|
+
minified = [header]
|
74
|
+
|
75
|
+
# Actual minification
|
76
|
+
# release.debug self, "Minifying #{file}"
|
77
|
+
case type
|
78
|
+
when "css"
|
79
|
+
minified << @css_compressor.compress(data)
|
80
|
+
when "js"
|
81
|
+
minified << @js_compressor.compress(data)
|
82
|
+
else
|
83
|
+
# release.warn self, "Error minifying: encountered unknown type \"#{type}\""
|
84
|
+
minified << data
|
50
85
|
end
|
51
|
-
|
52
|
-
|
86
|
+
|
87
|
+
fh.write minified.join("\n")
|
88
|
+
end
|
89
|
+
|
90
|
+
output_file
|
53
91
|
end
|
92
|
+
|
54
93
|
end
|
55
94
|
end
|
56
95
|
|
57
|
-
Roger::Release::Processors.register(:yuicompressor, RogerYuicompressor::Yuicompressor)
|
96
|
+
::Roger::Release::Processors.register(:yuicompressor, RogerYuicompressor::Yuicompressor)
|
data/roger_yuicompressor.gemspec
CHANGED
@@ -0,0 +1,58 @@
|
|
1
|
+
require File.dirname(__FILE__) + "/../../lib/roger_yuicompressor/processor"
|
2
|
+
require "test/unit"
|
3
|
+
|
4
|
+
class ProcessorTest < Test::Unit::TestCase
|
5
|
+
|
6
|
+
def setup
|
7
|
+
@processor = RogerYuicompressor::Yuicompressor.new
|
8
|
+
@tmp_file = 'file.css'
|
9
|
+
|
10
|
+
# TEMP file creation
|
11
|
+
File.open(@tmp_file, 'w') do |tmp_file|
|
12
|
+
tmp_file.write('.selector { background: green; }')
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
16
|
+
# Just make sure we're dealing with the correct class
|
17
|
+
def test_setup
|
18
|
+
assert_kind_of(RogerYuicompressor::Yuicompressor, @processor, "Not initialized the correct class.")
|
19
|
+
end
|
20
|
+
|
21
|
+
# When no suffix is given, there is no suffix and
|
22
|
+
# this default behaviour should be valid
|
23
|
+
def test_default_valid_suffix
|
24
|
+
assert(@processor.valid_suffix?, "The given suffix (#{@processor.options[:suffix]}) is not valid.")
|
25
|
+
end
|
26
|
+
|
27
|
+
# When the suffix '.min' is given it should be valid
|
28
|
+
def test_valid_suffix
|
29
|
+
assert(@processor.valid_suffix?(".min"), "Suffix '.min' should be valid.")
|
30
|
+
assert(@processor.valid_suffix?("-test"), "Suffix '-test' should be valid.")
|
31
|
+
end
|
32
|
+
|
33
|
+
# Test that extension of file get correct extracted
|
34
|
+
def test_extracting_extension
|
35
|
+
assert_equal('rb', @processor.get_file_type('file.rb'))
|
36
|
+
assert_equal('js', @processor.get_file_type('file.min.js'))
|
37
|
+
assert_equal('css', @processor.get_file_type('file.css'))
|
38
|
+
assert_not_equal('min.js', @processor.get_file_type('file.min.js'))
|
39
|
+
end
|
40
|
+
|
41
|
+
# Test default behaviour that minfied data is put in the original file
|
42
|
+
def test_default_behaviour_processor_minify
|
43
|
+
assert_equal('file.css', @processor.minify_file(@tmp_file, nil))
|
44
|
+
end
|
45
|
+
|
46
|
+
def test_behaviour_processor_minify
|
47
|
+
processor = RogerYuicompressor::Yuicompressor.new({:suffix => '.min'})
|
48
|
+
assert_equal('file.min.css', processor.minify_file(@tmp_file, nil))
|
49
|
+
|
50
|
+
assert(File.exists?('file.min.css'))
|
51
|
+
assert(File.exists?('file.css'))
|
52
|
+
end
|
53
|
+
|
54
|
+
def teardown
|
55
|
+
File.delete('file.css') if File.exists?('file.css')
|
56
|
+
File.delete('file.min.css') if File.exists?('file.min.css')
|
57
|
+
end
|
58
|
+
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: roger_yuicompressor
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.0
|
4
|
+
version: 1.1.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Flurin Egger
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-
|
11
|
+
date: 2014-07-04 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: roger
|
@@ -46,12 +46,17 @@ executables: []
|
|
46
46
|
extensions: []
|
47
47
|
extra_rdoc_files: []
|
48
48
|
files:
|
49
|
+
- .travis.yml
|
49
50
|
- CHANGELOG.md
|
51
|
+
- Gemfile
|
52
|
+
- Gemfile.lock
|
50
53
|
- LICENSE
|
51
54
|
- README.md
|
55
|
+
- Rakefile
|
52
56
|
- lib/roger_yuicompressor.rb
|
53
57
|
- lib/roger_yuicompressor/processor.rb
|
54
58
|
- roger_yuicompressor.gemspec
|
59
|
+
- test/unit/processor_test.rb
|
55
60
|
homepage: http://github.com/digitpaint/roger_yuicompressor
|
56
61
|
licenses:
|
57
62
|
- MIT
|
@@ -76,4 +81,5 @@ rubygems_version: 2.1.5
|
|
76
81
|
signing_key:
|
77
82
|
specification_version: 4
|
78
83
|
summary: Processor for using yuicompressor to minify CSS/JS
|
79
|
-
test_files:
|
84
|
+
test_files:
|
85
|
+
- test/unit/processor_test.rb
|