front-end-blender 0.5.2 → 0.6.0
Sign up to get free protection for your applications and to get access to all the features.
- data/README +26 -1
- data/bin/blend +102 -68
- metadata +2 -2
data/README
CHANGED
@@ -3,6 +3,29 @@
|
|
3
3
|
Blender is like ant or make for the front-end. It aggregates and compresses
|
4
4
|
CSS and/or JavaScript assets for a site into efficient, production-ready files.
|
5
5
|
|
6
|
+
== Blendfile
|
7
|
+
|
8
|
+
The Blendfile, named blender.yaml by default, is the configuration file that
|
9
|
+
tells Blender which input files are combined into which output files. The
|
10
|
+
file uses the YAML format. The output file is listed as hash key and input
|
11
|
+
files are the hash values as an array. Here is a sample Blendfile:
|
12
|
+
|
13
|
+
# blender.yaml for boldpx.com
|
14
|
+
_behavior/_global-min.js:
|
15
|
+
- _vendor/jquery/jquery.js
|
16
|
+
- _vendor/shadowbox/src/js/adapter/shadowbox-jquery.js
|
17
|
+
- _vendor/shadowbox/src/js/shadowbox.js
|
18
|
+
- _behavior/_global.js
|
19
|
+
|
20
|
+
_style/_global-min.css:
|
21
|
+
- _vendor/shadowbox/src/css/shadowbox.css
|
22
|
+
- _style/_global/typography.css
|
23
|
+
- _style/_global/typography-print.css
|
24
|
+
- _style/_global/colors.css
|
25
|
+
- _style/_global/colors-print.css
|
26
|
+
- _style/_global/layout-screen.css
|
27
|
+
- _style/_global/layout-print.css
|
28
|
+
|
6
29
|
== Examples
|
7
30
|
|
8
31
|
In your site directory run 'blend' to minify CSS and JavaScript.
|
@@ -32,7 +55,9 @@ For help use: blend -h
|
|
32
55
|
== Installation
|
33
56
|
|
34
57
|
To install the beta gem, run the following at the command line:
|
35
|
-
sudo gem install
|
58
|
+
sudo gem install frontendblender
|
59
|
+
|
60
|
+
Java, v1.4 or greater is required
|
36
61
|
|
37
62
|
== License
|
38
63
|
|
data/bin/blend
CHANGED
@@ -11,11 +11,13 @@ require 'optparse'
|
|
11
11
|
require 'rdoc/usage'
|
12
12
|
require 'ostruct'
|
13
13
|
require 'base64'
|
14
|
+
require 'benchmark'
|
14
15
|
require 'mime/types'
|
16
|
+
require 'find'
|
15
17
|
|
16
18
|
# TODO Move class to lib so other tools could potentially reuse it
|
17
19
|
class Blender
|
18
|
-
VERSION = '0.5.
|
20
|
+
VERSION = '0.5.3'
|
19
21
|
|
20
22
|
attr_reader :options
|
21
23
|
|
@@ -33,41 +35,45 @@ class Blender
|
|
33
35
|
|
34
36
|
def blend
|
35
37
|
if parsed_options?
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
blender.each do |output_name, inputs|
|
46
|
-
output_new = false
|
38
|
+
elapsed = Benchmark.realtime do
|
39
|
+
unless File.exists? @options.blendfile
|
40
|
+
puts "Couldn't find '#{@options.blendfile}'"
|
41
|
+
exit 1
|
42
|
+
end
|
43
|
+
|
44
|
+
blender = YAML::load_file @options.blendfile
|
45
|
+
|
46
|
+
Dir.chdir(File.dirname(@options.blendfile))
|
47
47
|
|
48
|
-
|
49
|
-
|
50
|
-
file_type = output_name.match(/\.css/) ? "css" : "js"
|
48
|
+
blender.each do |output_name, inputs|
|
49
|
+
output_new = false
|
51
50
|
|
52
|
-
# Checks
|
53
|
-
if
|
54
|
-
|
55
|
-
if File.mtime(i) > File.mtime(output_name)
|
56
|
-
output_new = true
|
57
|
-
break
|
58
|
-
end
|
59
|
-
end
|
51
|
+
# Checks the type flag and if the current file meets the type requirements continues
|
52
|
+
if output_name.match "." + @options.file_type.to_s
|
53
|
+
file_type = output_name.match(/\.css/) ? "css" : "js"
|
60
54
|
|
61
|
-
if
|
62
|
-
|
55
|
+
# Checks if output file exists and checks the mtimes of the source files to the output file if new creates a new file
|
56
|
+
if File.exists? output_name
|
57
|
+
inputs.each do |i|
|
58
|
+
if File.mtime(i) > File.mtime(output_name)
|
59
|
+
output_new = true
|
60
|
+
break
|
61
|
+
end
|
62
|
+
end
|
63
|
+
|
64
|
+
if output_new || @options.force
|
65
|
+
create_output(output_name, inputs, file_type)
|
66
|
+
else
|
67
|
+
puts "Skipping: #{output_name}"
|
68
|
+
end
|
63
69
|
else
|
64
|
-
|
70
|
+
create_output(output_name, inputs, file_type)
|
65
71
|
end
|
66
|
-
else
|
67
|
-
create_output(output_name, inputs, file_type)
|
68
72
|
end
|
69
73
|
end
|
70
74
|
end
|
75
|
+
|
76
|
+
puts sprintf("%.5f", elapsed) + " seconds"
|
71
77
|
end
|
72
78
|
end
|
73
79
|
|
@@ -89,57 +95,85 @@ class Blender
|
|
89
95
|
|
90
96
|
opts.on("-d", "--data", String, "Change url(image.ext) to url(data:) in css files") { @options.data = true }
|
91
97
|
opts.on("-F", "--force", String, "Force minification when source files aren't newer than min files") { @options.force = true }
|
92
|
-
|
98
|
+
opts.on("--generate", String, "Generate a blendfile") { create_blendfile() }
|
93
99
|
opts.parse!(@arguments) rescue return false
|
94
100
|
|
95
101
|
true
|
96
102
|
end
|
97
103
|
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
104
|
+
def create_blendfile()
|
105
|
+
blend_files = Hash.new
|
106
|
+
Find.find(Dir.getwd) do |f|
|
107
|
+
if f.match /\.css$/
|
108
|
+
key = File.dirname(f) + "-min.css"
|
109
|
+
if blend_files.has_key? key
|
110
|
+
blend_files[key] << f
|
111
|
+
else
|
112
|
+
blend_files[key] = [f]
|
113
|
+
end
|
103
114
|
end
|
104
|
-
end
|
105
|
-
|
106
|
-
# Compress
|
107
|
-
IO.popen("java -jar #{File.dirname(__FILE__)}/../lib/yuicompressor.jar #{@passthrough} --type #{type}", mode="r+") do |io|
|
108
|
-
io.write IO.read(output_name)
|
109
|
-
io.close_write
|
110
115
|
|
111
|
-
|
112
|
-
|
116
|
+
if f.match /\.js$/
|
117
|
+
key = File.dirname(f) + "-min.js"
|
118
|
+
if blend_files.has_key? key
|
119
|
+
blend_files[key] << f
|
120
|
+
else
|
121
|
+
blend_files[key] = [f]
|
122
|
+
end
|
113
123
|
end
|
124
|
+
|
125
|
+
Find.prune if f=~ /.svn/
|
126
|
+
end
|
127
|
+
|
128
|
+
if !File.exists? 'blender.yaml' || @options.force
|
129
|
+
File.open('blender.yaml', 'w') {|f| YAML.dump(blend_files, f)}
|
114
130
|
end
|
115
131
|
|
116
|
-
|
117
|
-
|
118
|
-
|
119
|
-
|
120
|
-
|
121
|
-
|
122
|
-
output
|
123
|
-
|
124
|
-
|
125
|
-
output = output.gsub(/url\(['"]?([^?']+)['"]+\)/im) do
|
126
|
-
uri = $1
|
127
|
-
mime_type = ''
|
128
|
-
|
129
|
-
# Make the URI absolute instead of relative. TODO Seems kinda hacky is there a better way?
|
130
|
-
uri.gsub! "../", ""
|
131
|
-
|
132
|
-
# Figure out the mime type.
|
133
|
-
mime_type = MIME::Types.type_for(uri)
|
134
|
-
|
135
|
-
url_contents = make_data_uri(IO.read(uri), mime_type)
|
136
|
-
|
137
|
-
%Q!url("#{url_contents}")!
|
138
|
-
end
|
132
|
+
exit 0
|
133
|
+
end
|
134
|
+
|
135
|
+
# TODO Change to work with directory hashes (css/: [ colors.css, layout.css ])
|
136
|
+
def create_output(output_name, inputs, type)
|
137
|
+
File.open(output_name, 'w') do |output_file|
|
138
|
+
output = ''
|
139
|
+
inputs.each do |i|
|
140
|
+
output += IO.read(i)
|
139
141
|
end
|
140
|
-
|
141
|
-
|
142
|
-
|
142
|
+
|
143
|
+
# Compress
|
144
|
+
real_file = File.symlink?(__FILE__) ? File.readlink(__FILE__) : __FILE__
|
145
|
+
|
146
|
+
IO.popen("java -jar #{File.dirname(real_file)}/../lib/yuicompressor.jar #{@passthrough} --type #{type}", mode="r+") do |io|
|
147
|
+
io.write output
|
148
|
+
io.close_write
|
149
|
+
|
150
|
+
output = io.read
|
151
|
+
# TODO Move this to before the file gets written
|
152
|
+
# Workaround for YUI Compressor Bug #1938329 & Bug #1961175
|
153
|
+
if output_name.match /\.css$/
|
154
|
+
|
155
|
+
output.gsub! ' and(', ' and ('
|
156
|
+
output.gsub! '/**/;}', '/**/}'
|
157
|
+
|
158
|
+
if @options.data
|
159
|
+
output = output.gsub(/url\(['"]?([^?']+)['"]+\)/im) do
|
160
|
+
uri = $1
|
161
|
+
mime_type = ''
|
162
|
+
|
163
|
+
# Make the URI absolute instead of relative. TODO Seems kinda hacky is there a better way?
|
164
|
+
uri.gsub! "../", ""
|
165
|
+
|
166
|
+
# Figure out the mime type.
|
167
|
+
mime_type = MIME::Types.type_for(uri)
|
168
|
+
|
169
|
+
url_contents = make_data_uri(IO.read(uri), mime_type[0])
|
170
|
+
|
171
|
+
%Q!url("#{url_contents}")!
|
172
|
+
end
|
173
|
+
end
|
174
|
+
|
175
|
+
output_file << output
|
176
|
+
end
|
143
177
|
end
|
144
178
|
end
|
145
179
|
|
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.
|
4
|
+
version: 0.6.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Blake Elshire & Chris Griego
|
@@ -9,7 +9,7 @@ autorequire:
|
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
11
|
|
12
|
-
date: 2008-05-
|
12
|
+
date: 2008-05-21 00:00:00 -07:00
|
13
13
|
default_executable:
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|