front-end-blender 0.5.1
Sign up to get free protection for your applications and to get access to all the features.
- data/MIT-LICENSE +19 -0
- data/README +37 -0
- data/bin/blend +188 -0
- data/lib/yuicompressor.jar +0 -0
- metadata +56 -0
data/MIT-LICENSE
ADDED
@@ -0,0 +1,19 @@
|
|
1
|
+
Copyright (c) 2008 Chris Griego & Blake Elshire.
|
2
|
+
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
4
|
+
of this software and associated documentation files (the "Software"), to deal
|
5
|
+
in the Software without restriction, including without limitation the rights
|
6
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
7
|
+
copies of the Software, and to permit persons to whom the Software is
|
8
|
+
furnished to do so, subject to the following conditions:
|
9
|
+
|
10
|
+
The above copyright notice and this permission notice shall be included in
|
11
|
+
all copies or substantial portions of the Software.
|
12
|
+
|
13
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
14
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
15
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
16
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
17
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
18
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
19
|
+
THE SOFTWARE.
|
data/README
ADDED
@@ -0,0 +1,37 @@
|
|
1
|
+
== Synopsis
|
2
|
+
Blender is like Make or Ant for the front-end. It aggregates and compresses
|
3
|
+
CSS and/or JavaScript assets of a site into production-ready files.
|
4
|
+
|
5
|
+
== Examples
|
6
|
+
In your site directory run 'blend' to minify CSS and JavaScript.
|
7
|
+
blend
|
8
|
+
|
9
|
+
Other examples:
|
10
|
+
blend -f site/blender.yaml
|
11
|
+
blend -t css
|
12
|
+
blend -t css -d
|
13
|
+
|
14
|
+
== Usage
|
15
|
+
blend [options]
|
16
|
+
|
17
|
+
For help use: blend -h
|
18
|
+
|
19
|
+
== Options
|
20
|
+
-h, --help Displays help message
|
21
|
+
-v, --version Display the version, then exit
|
22
|
+
-f <file>, --file <file> Use given Blendfile
|
23
|
+
-t <css|js>, --type <css|js> Compress CSS or JavaScript only
|
24
|
+
-d, --data Convert CSS url(image.ext) to url(data:) EXPERIMENTAL
|
25
|
+
-F, --force Force file minification when there are no new updates
|
26
|
+
|
27
|
+
== Authors
|
28
|
+
Chris Griego & Blake Elshire
|
29
|
+
|
30
|
+
== Installation
|
31
|
+
To install the beta version, run the following at the command line:
|
32
|
+
sudo gem install front-end-blender --source=http://gems.github.com
|
33
|
+
|
34
|
+
== License
|
35
|
+
Copyright (c) 2008 Chris Griego & Blake Elshire.
|
36
|
+
Licensed under the MIT License:
|
37
|
+
http://www.opensource.org/licenses/mit-license.php
|
data/bin/blend
ADDED
@@ -0,0 +1,188 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
# == Synopsis
|
3
|
+
# Blender is like Make or Ant for the front-end. It aggregates and compresses
|
4
|
+
# CSS and/or JavaScript assets of a site into production-ready files.
|
5
|
+
#
|
6
|
+
# == Examples
|
7
|
+
# In your site directory run 'blend' to minify CSS and JavaScript.
|
8
|
+
# blend
|
9
|
+
#
|
10
|
+
# Other examples:
|
11
|
+
# blend -f site/blender.yaml
|
12
|
+
# blend -t css
|
13
|
+
# blend -t css -d
|
14
|
+
#
|
15
|
+
# == Usage
|
16
|
+
# blend [options]
|
17
|
+
#
|
18
|
+
# For help use: blend -h
|
19
|
+
#
|
20
|
+
# == Options
|
21
|
+
# -h, --help Displays help message
|
22
|
+
# -v, --version Display the version, then exit
|
23
|
+
# -f <file>, --file <file> Use given Blendfile
|
24
|
+
# -t <css|js>, --type <css|js> Compress CSS or JavaScript only
|
25
|
+
# -d, --data Convert CSS url(image.ext) to url(data:) EXPERIMENTAL
|
26
|
+
# -F, --force Force file minification when there are no new updates
|
27
|
+
#
|
28
|
+
# == Authors
|
29
|
+
# Chris Griego & Blake Elshire
|
30
|
+
#
|
31
|
+
# == Installation
|
32
|
+
# To install the beta version, run the following at the command line:
|
33
|
+
# sudo gem install front-end-blender --source=http://gems.github.com
|
34
|
+
#
|
35
|
+
# == License
|
36
|
+
# Copyright (c) 2008 Chris Griego & Blake Elshire.
|
37
|
+
# Licensed under the MIT License:
|
38
|
+
# http://www.opensource.org/licenses/mit-license.php
|
39
|
+
|
40
|
+
|
41
|
+
require 'yaml'
|
42
|
+
require 'optparse'
|
43
|
+
require 'rdoc/usage'
|
44
|
+
require 'ostruct'
|
45
|
+
require 'base64'
|
46
|
+
|
47
|
+
class Blender
|
48
|
+
VERSION = '0.5.1'
|
49
|
+
attr_reader :options
|
50
|
+
|
51
|
+
def initialize(arguments, stdin)
|
52
|
+
@arguments = arguments
|
53
|
+
# Set defaults
|
54
|
+
@options = OpenStruct.new
|
55
|
+
@options.blendfile = 'blender.yaml'
|
56
|
+
@options.png = false
|
57
|
+
@options.data = false
|
58
|
+
@options.force = false
|
59
|
+
end
|
60
|
+
|
61
|
+
def blend
|
62
|
+
if parsed_options?
|
63
|
+
unless File.exists? @options.blendfile
|
64
|
+
puts "Couldn't find '#{@options.blendfile}'"
|
65
|
+
exit 1
|
66
|
+
end
|
67
|
+
|
68
|
+
blender = YAML::load_file @options.blendfile
|
69
|
+
|
70
|
+
Dir.chdir(File.dirname(@options.blendfile))
|
71
|
+
|
72
|
+
blender.each do |output_name, inputs|
|
73
|
+
output_new = false
|
74
|
+
# Checks the type flag and if the current file meets the type requirements continues
|
75
|
+
if output_name.match "." + @options.file_type.to_s
|
76
|
+
|
77
|
+
file_type = output_name.match(/\.css/) ? "css" : "js"
|
78
|
+
|
79
|
+
# Checks if output file exists and checks the mtimes of the source files to the output file if new creates a new file
|
80
|
+
if File.exists? output_name
|
81
|
+
inputs.each do |i|
|
82
|
+
if File.mtime(i) > File.mtime(output_name)
|
83
|
+
output_new = true
|
84
|
+
break
|
85
|
+
end
|
86
|
+
end
|
87
|
+
|
88
|
+
if output_new || @options.force
|
89
|
+
create_output(output_name, inputs, file_type)
|
90
|
+
else
|
91
|
+
puts "Skipping: #{output_name}"
|
92
|
+
end
|
93
|
+
else
|
94
|
+
create_output(output_name, inputs, file_type)
|
95
|
+
end
|
96
|
+
end
|
97
|
+
end
|
98
|
+
end
|
99
|
+
end
|
100
|
+
|
101
|
+
protected
|
102
|
+
|
103
|
+
def parsed_options?
|
104
|
+
opts = OptionParser.new
|
105
|
+
opts.on('-v', '--version') { output_version ; exit 0 }
|
106
|
+
opts.on('-h', '--help') { output_help }
|
107
|
+
opts.on('-f FILE', '--file FILE', String, "Use given Blendfile") do |blendfile|
|
108
|
+
@options.blendfile = blendfile
|
109
|
+
end
|
110
|
+
opts.on("-t [TYPE]", "--type [TYPE]", [:css, :js], "Select file type to minify (css, js)") do |t|
|
111
|
+
@options.file_type = t
|
112
|
+
end
|
113
|
+
opts.on("-d", "--data", String, "Change url(image.ext) to url(data:) in css files") { @options.data = true }
|
114
|
+
opts.on("-F", "--force", String, "Force minification when source files aren't newer than min files") { @options.force = true }
|
115
|
+
|
116
|
+
opts.parse!(@arguments) rescue return false
|
117
|
+
true
|
118
|
+
end
|
119
|
+
|
120
|
+
# TODO Change to work with directory hashes (css/: [ colors.css, layout.css ])
|
121
|
+
def create_output(output_name, inputs, type)
|
122
|
+
File.open(output_name, 'w') do |output_file|
|
123
|
+
inputs.each do |i|
|
124
|
+
output_file << IO.read(i)
|
125
|
+
end
|
126
|
+
end
|
127
|
+
|
128
|
+
# Compress
|
129
|
+
IO.popen("java -jar #{File.dirname(__FILE__)}/../lib/yuicompressor.jar --type #{type}", mode="r+") do |io|
|
130
|
+
io.write IO.read(output_name)
|
131
|
+
io.close_write
|
132
|
+
File.open(output_name, 'w') do |output_file|
|
133
|
+
output_file << io.read
|
134
|
+
end
|
135
|
+
end
|
136
|
+
|
137
|
+
# Workaround for YUI Compressor Bug #1938329 & Bug #1961175
|
138
|
+
if output_name.match /\.css$/
|
139
|
+
output = IO.read(output_name)
|
140
|
+
output.gsub! ' and(', ' and ('
|
141
|
+
output.gsub! '/**/;}', '/**/}'
|
142
|
+
|
143
|
+
if @options.data
|
144
|
+
output = output.gsub(/url\(['"]?([^?']+)['"]+\)/im) {
|
145
|
+
uri = $1
|
146
|
+
mime_type = ''
|
147
|
+
|
148
|
+
# Make the URI absolute instead of relative. TODO Again seems kinda hacky is there a better way?
|
149
|
+
uri.gsub! "../", ""
|
150
|
+
|
151
|
+
# Figure out the mime type. TODO Seems hacky is there a way to read mime type built into Ruby?
|
152
|
+
IO.popen("file --mime #{uri}") do |io|
|
153
|
+
mime_type = io.read.split(": ")[1]
|
154
|
+
end
|
155
|
+
|
156
|
+
url_contents = make_data_uri(IO.read(uri), mime_type)
|
157
|
+
|
158
|
+
%Q!url("#{url_contents}")!
|
159
|
+
}
|
160
|
+
end
|
161
|
+
|
162
|
+
File.open(output_name, 'w') do |output_file|
|
163
|
+
output_file << output
|
164
|
+
end
|
165
|
+
end
|
166
|
+
puts output_name
|
167
|
+
end
|
168
|
+
|
169
|
+
def make_data_uri(content, content_type)
|
170
|
+
outuri = 'data:' + content_type + ';base64'
|
171
|
+
content = Base64.encode64(content)
|
172
|
+
outuri += ",#{content}"
|
173
|
+
return outuri.gsub("\n", '')
|
174
|
+
end
|
175
|
+
|
176
|
+
def output_version
|
177
|
+
puts "#{File.basename(__FILE__)} version #{VERSION}"
|
178
|
+
end
|
179
|
+
|
180
|
+
def output_help
|
181
|
+
output_version
|
182
|
+
RDoc::usage() #exits app
|
183
|
+
end
|
184
|
+
end
|
185
|
+
|
186
|
+
# Create and run the application
|
187
|
+
blender = Blender.new(ARGV, STDIN)
|
188
|
+
blender.blend
|
Binary file
|
metadata
ADDED
@@ -0,0 +1,56 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: front-end-blender
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.5.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Blake Elshire & Chris Griego
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
|
12
|
+
date: 2008-05-16 00:00:00 -07:00
|
13
|
+
default_executable:
|
14
|
+
dependencies: []
|
15
|
+
|
16
|
+
description: Blender is like Make or Ant for the front-end. It aggregates and compresses CSS and/or JavaScript assets of a site into production-ready files.
|
17
|
+
email: belshire@gmail.com
|
18
|
+
executables:
|
19
|
+
- blend
|
20
|
+
extensions: []
|
21
|
+
|
22
|
+
extra_rdoc_files: []
|
23
|
+
|
24
|
+
files:
|
25
|
+
- README
|
26
|
+
- MIT-LICENSE
|
27
|
+
- bin/blend
|
28
|
+
- lib/yuicompressor.jar
|
29
|
+
has_rdoc: false
|
30
|
+
homepage: http://github.com/front-end/front-end-blender/tree/master
|
31
|
+
post_install_message:
|
32
|
+
rdoc_options: []
|
33
|
+
|
34
|
+
require_paths:
|
35
|
+
- lib
|
36
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ">="
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: "0"
|
41
|
+
version:
|
42
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
43
|
+
requirements:
|
44
|
+
- - ">="
|
45
|
+
- !ruby/object:Gem::Version
|
46
|
+
version: "0"
|
47
|
+
version:
|
48
|
+
requirements: []
|
49
|
+
|
50
|
+
rubyforge_project:
|
51
|
+
rubygems_version: 1.0.1
|
52
|
+
signing_key:
|
53
|
+
specification_version: 2
|
54
|
+
summary: Blender gives you production-ready CSS and/or JavaScript assets.
|
55
|
+
test_files: []
|
56
|
+
|