front-end-blender 0.6.1 → 0.8

Sign up to get free protection for your applications and to get access to all the features.
data/README CHANGED
@@ -35,7 +35,7 @@ Other examples:
35
35
  blend -f site/blender.yaml
36
36
  blend -t css
37
37
  blend -t css -d
38
- blend -F -- --preserve-semi
38
+ blend --yui='--preserve-semi'
39
39
 
40
40
  == Usage
41
41
 
@@ -45,12 +45,14 @@ For help use: blend -h
45
45
 
46
46
  == Options
47
47
 
48
- -h, --help Displays help message
49
- -v, --version Display the version, then exit
50
- -f <file>, --file <file> Use given Blendfile
51
- -t <css|js>, --type <css|js> Compress CSS or JavaScript only
52
- -d, --data Convert CSS url(image.ext) to url(data:) EXPERIMENTAL
53
- --force Force file minification when there are no new updates
48
+ -h, --help Displays help message
49
+ -v, --version Display the version
50
+ -f <file>, --file <file> Use given Blendfile
51
+ -t <css|js>, --type <css|js> Select file type to blend (css, js)
52
+ -d, --data Convert url(image.ext) to url(data:) in CSS files EXPERIMENTAL
53
+ --force Force blending when source files aren't newer than output files
54
+ --yui= Pass arguments to YUI Compressor
55
+ -g, --generate Generate a stub Blendfile
54
56
 
55
57
  == Installation
56
58
 
data/bin/blend CHANGED
@@ -17,24 +17,27 @@ require 'find'
17
17
 
18
18
  # TODO Move class to lib so other tools could potentially reuse it
19
19
  class Blender
20
- VERSION = '0.6.1'
20
+ VERSION = '0.8'
21
21
 
22
22
  attr_reader :options
23
23
 
24
24
  def initialize(arguments, stdin)
25
- @arguments = !arguments.include?('--') ? arguments : arguments[0...arguments.index('--')]
26
- @passthrough = !arguments.include?('--') ? '' : arguments[arguments.index('--')+1..-1]
25
+ @arguments = arguments
27
26
 
28
27
  # Set defaults
29
28
  @options = OpenStruct.new
30
29
  @options.blendfile = 'blender.yaml'
31
- @options.png = false
32
30
  @options.data = false
33
31
  @options.force = false
32
+ @options.generate = false
34
33
  end
35
34
 
36
35
  def blend
37
36
  if parsed_options?
37
+ if @options.generate
38
+ create_blendfile
39
+ end
40
+
38
41
  elapsed = Benchmark.realtime do
39
42
  unless File.exists? @options.blendfile
40
43
  puts "Couldn't find '#{@options.blendfile}'"
@@ -82,33 +85,28 @@ class Blender
82
85
  def parsed_options?
83
86
  opts = OptionParser.new
84
87
 
85
- opts.on('-v', '--version') { output_version ; exit 0 }
86
- opts.on('-h', '--help') { output_help }
87
-
88
- opts.on('-f FILE', '--file FILE', String, "Use given Blendfile") do |blendfile|
89
- @options.blendfile = blendfile
90
- end
91
-
92
- opts.on("-t [TYPE]", "--type [TYPE]", [:css, :js], "Select file type to minify (css, js)") do |t|
93
- @options.file_type = t
94
- end
88
+ opts.on('-h', '--help') { output_help }
89
+ opts.on('-v', '--version') { output_version; exit 0 }
90
+ opts.on('-f FILE', '--file FILE', String, "Use given Blendfile") {|f| @options.blendfile = f }
91
+ opts.on('-t TYPE', '--type TYPE', [:css, :js], "Select file type to blend (css, js)") {|t| @options.file_type = t }
92
+ opts.on('-d', '--data', String, "Convert url(image.ext) to url(data:) in CSS files EXPERIMENTAL") { @options.data = true }
93
+ opts.on( '--force', String, "Force blending when source files aren't newer than output files") { @options.force = true }
94
+ opts.on( '--yui=YUIOPTS', String, "Pass arguments to YUI Compressor") {|o| @options.yuiopts = o }
95
+ opts.on('-g', '--generate', String, "Generate a stub Blendfile") { @options.generate = true }
95
96
 
96
- opts.on("-d", "--data", String, "Change url(image.ext) to url(data:) in css files") { @options.data = true }
97
- opts.on("--force", String, "Force minification when source files aren't newer than output files") { @options.force = true }
98
- opts.on("--generate", String, "Generate a blendfile") { create_blendfile() }
99
97
  opts.parse!(@arguments) rescue return false
100
98
 
101
99
  true
102
100
  end
103
101
 
104
- def create_blendfile()
102
+ def create_blendfile
105
103
  if File.exists?(@options.blendfile) && !@options.force
106
104
  puts "'#{@options.blendfile}' already exists"
107
105
  exit 1
108
106
  end
109
-
107
+
110
108
  blend_files = Hash.new
111
-
109
+
112
110
  Find.find(Dir.getwd) do |f|
113
111
  if f.match /\.css$/
114
112
  key = File.dirname(f) + "-min.css"
@@ -118,7 +116,7 @@ class Blender
118
116
  blend_files[key] = [f]
119
117
  end
120
118
  end
121
-
119
+
122
120
  if f.match /\.js$/
123
121
  key = File.dirname(f) + "-min.js"
124
122
  if blend_files.has_key? key
@@ -127,8 +125,8 @@ class Blender
127
125
  blend_files[key] = [f]
128
126
  end
129
127
  end
130
-
131
- Find.prune if File.basename(f).index('.') == 0 # TODO Ignore all files in any dot folder
128
+
129
+ Find.prune if File.basename(f).index('.') == 0
132
130
  end
133
131
 
134
132
  File.open(@options.blendfile, 'w') { |f| YAML.dump(blend_files, f) }
@@ -140,24 +138,23 @@ class Blender
140
138
  def create_output(output_name, inputs, type)
141
139
  File.open(output_name, 'w') do |output_file|
142
140
  output = ''
141
+
143
142
  inputs.each do |i|
144
- output += IO.read(i)
143
+ output << IO.read(i)
145
144
  end
146
145
 
147
146
  # Compress
148
147
  real_file = File.symlink?(__FILE__) ? File.readlink(__FILE__) : __FILE__
149
148
 
150
- IO.popen("java -jar #{File.dirname(real_file)}/../lib/yuicompressor.jar #{@passthrough} --type #{type}", mode="r+") do |io|
149
+ IO.popen("java -jar #{File.dirname(real_file)}/../lib/yui/yuicompressor.jar #{@options.yuiopts} --type #{type}", mode="r+") do |io|
151
150
  io.write output
152
151
  io.close_write
153
152
 
154
153
  output = io.read
155
- # TODO Move this to before the file gets written
156
- # Workaround for YUI Compressor Bug #1938329 & Bug #1961175
154
+
157
155
  if output_name.match /\.css$/
158
-
159
- output.gsub! ' and(', ' and ('
160
- output.gsub! '/**/;}', '/**/}'
156
+ output.gsub! ' and(', ' and (' # Workaround for YUI Compressor Bug #1938329
157
+ output.gsub! '/**/;}', '/**/}' # Workaround for YUI Compressor Bug #1961175
161
158
 
162
159
  if @options.data
163
160
  output = output.gsub(/url\(['"]?([^?']+)['"]+\)/im) do
@@ -175,9 +172,9 @@ class Blender
175
172
  %Q!url("#{url_contents}")!
176
173
  end
177
174
  end
178
-
179
- output_file << output
180
175
  end
176
+
177
+ output_file << output
181
178
  end
182
179
  end
183
180
 
@@ -193,7 +190,7 @@ class Blender
193
190
  end
194
191
 
195
192
  def output_version
196
- puts "#{File.basename(__FILE__)} version #{VERSION}"
193
+ puts "Blender v#{VERSION}"
197
194
  end
198
195
 
199
196
  def output_help
data/lib/yui/LICENSE ADDED
@@ -0,0 +1,30 @@
1
+ Software License Agreement (BSD License)
2
+
3
+ Copyright (c) 2008, Yahoo! Inc.
4
+ All rights reserved.
5
+
6
+ Redistribution and use of this software in source and binary forms, with or without modification, are
7
+ permitted provided that the following conditions are met:
8
+
9
+ * Redistributions of source code must retain the above
10
+ copyright notice, this list of conditions and the
11
+ following disclaimer.
12
+
13
+ * Redistributions in binary form must reproduce the above
14
+ copyright notice, this list of conditions and the
15
+ following disclaimer in the documentation and/or other
16
+ materials provided with the distribution.
17
+
18
+ * Neither the name of Yahoo! Inc. nor the names of its
19
+ contributors may be used to endorse or promote products
20
+ derived from this software without specific prior
21
+ written permission of Yahoo! Inc.
22
+
23
+ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED
24
+ WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
25
+ PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
26
+ ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
27
+ LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
28
+ INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
29
+ TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
30
+ ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
File without changes
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: front-end-blender
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.6.1
4
+ version: "0.8"
5
5
  platform: ruby
6
6
  authors:
7
7
  - Blake Elshire & Chris Griego
@@ -33,7 +33,8 @@ files:
33
33
  - README
34
34
  - MIT-LICENSE
35
35
  - bin/blend
36
- - lib/yuicompressor.jar
36
+ - lib/yui/yuicompressor.jar
37
+ - lib/yui/LICENSE
37
38
  has_rdoc: false
38
39
  homepage: http://github.com/front-end/front-end-blender/tree/master
39
40
  post_install_message: