front-end-blender 0.5.1 → 0.5.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (4) hide show
  1. data/MIT-LICENSE +2 -1
  2. data/README +31 -25
  3. data/bin/blend +92 -111
  4. metadata +16 -8
data/MIT-LICENSE CHANGED
@@ -1,4 +1,5 @@
1
- Copyright (c) 2008 Chris Griego & Blake Elshire.
1
+ Copyright (c) 2008 Chris Griego
2
+ (c) 2008 Blake Elshire
2
3
 
3
4
  Permission is hereby granted, free of charge, to any person obtaining a copy
4
5
  of this software and associated documentation files (the "Software"), to deal
data/README CHANGED
@@ -1,37 +1,43 @@
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.
1
+ == What is Blender?
2
+
3
+ Blender is like ant or make for the front-end. It aggregates and compresses
4
+ CSS and/or JavaScript assets for a site into efficient, production-ready files.
4
5
 
5
6
  == Examples
6
- In your site directory run 'blend' to minify CSS and JavaScript.
7
- blend
8
7
 
9
- Other examples:
10
- blend -f site/blender.yaml
11
- blend -t css
12
- blend -t css -d
8
+ In your site directory run 'blend' to minify CSS and JavaScript.
9
+ blend
10
+
11
+ Other examples:
12
+ blend -f site/blender.yaml
13
+ blend -t css
14
+ blend -t css -d
15
+ blend -F -- --preserve-semi
16
+
17
+ == Usage
13
18
 
14
- == Usage
15
- blend [options]
19
+ blend [options] [-- yui-compressor-options]
16
20
 
17
- For help use: blend -h
21
+ For help use: blend -h
18
22
 
19
23
  == 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
24
 
27
- == Authors
28
- Chris Griego & Blake Elshire
25
+ -h, --help Displays help message
26
+ -v, --version Display the version, then exit
27
+ -f <file>, --file <file> Use given Blendfile
28
+ -t <css|js>, --type <css|js> Compress CSS or JavaScript only
29
+ -d, --data Convert CSS url(image.ext) to url(data:) EXPERIMENTAL
30
+ -F, --force Force file minification when there are no new updates
29
31
 
30
32
  == 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
+ To install the beta gem, run the following at the command line:
35
+ sudo gem install front-end-blender --source=http://gems.github.com
33
36
 
34
37
  == License
35
- Copyright (c) 2008 Chris Griego & Blake Elshire.
36
- Licensed under the MIT License:
37
- http://www.opensource.org/licenses/mit-license.php
38
+
39
+ Copyright (c) 2008 Chris Griego
40
+ (c) 2008 Blake Elshire
41
+
42
+ Blender is freely distributable under the terms of an MIT-style license.
43
+ For details, see http://www.opensource.org/licenses/mit-license.php
data/bin/blend CHANGED
@@ -1,55 +1,28 @@
1
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
2
 
3
+ # Copyright (c) 2008 Chris Griego
4
+ # (c) 2008 Blake Elshire
5
+ #
6
+ # Blender is freely distributable under the terms of an MIT-style license.
7
+ # For details, see http://www.opensource.org/licenses/mit-license.php
40
8
 
41
9
  require 'yaml'
42
10
  require 'optparse'
43
11
  require 'rdoc/usage'
44
12
  require 'ostruct'
45
13
  require 'base64'
14
+ require 'mime/types'
46
15
 
16
+ # TODO Move class to lib so other tools could potentially reuse it
47
17
  class Blender
48
- VERSION = '0.5.1'
18
+ VERSION = '0.5.2'
19
+
49
20
  attr_reader :options
50
21
 
51
22
  def initialize(arguments, stdin)
52
- @arguments = arguments
23
+ @arguments = !arguments.include?('--') ? arguments : arguments[0...arguments.index('--')]
24
+ @passthrough = !arguments.include?('--') ? '' : arguments[arguments.index('--')+1..-1]
25
+
53
26
  # Set defaults
54
27
  @options = OpenStruct.new
55
28
  @options.blendfile = 'blender.yaml'
@@ -71,9 +44,9 @@ class Blender
71
44
 
72
45
  blender.each do |output_name, inputs|
73
46
  output_new = false
47
+
74
48
  # Checks the type flag and if the current file meets the type requirements continues
75
49
  if output_name.match "." + @options.file_type.to_s
76
-
77
50
  file_type = output_name.match(/\.css/) ? "css" : "js"
78
51
 
79
52
  # Checks if output file exists and checks the mtimes of the source files to the output file if new creates a new file
@@ -86,12 +59,12 @@ class Blender
86
59
  end
87
60
 
88
61
  if output_new || @options.force
89
- create_output(output_name, inputs, file_type)
62
+ create_output(output_name, inputs, file_type)
90
63
  else
91
- puts "Skipping: #{output_name}"
64
+ puts "Skipping: #{output_name}"
92
65
  end
93
66
  else
94
- create_output(output_name, inputs, file_type)
67
+ create_output(output_name, inputs, file_type)
95
68
  end
96
69
  end
97
70
  end
@@ -100,87 +73,95 @@ class Blender
100
73
 
101
74
  protected
102
75
 
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
76
+ def parsed_options?
77
+ opts = OptionParser.new
78
+
79
+ opts.on('-v', '--version') { output_version ; exit 0 }
80
+ opts.on('-h', '--help') { output_help }
81
+
82
+ opts.on('-f FILE', '--file FILE', String, "Use given Blendfile") do |blendfile|
83
+ @options.blendfile = blendfile
84
+ end
85
+
86
+ opts.on("-t [TYPE]", "--type [TYPE]", [:css, :js], "Select file type to minify (css, js)") do |t|
87
+ @options.file_type = t
88
+ end
89
+
90
+ opts.on("-d", "--data", String, "Change url(image.ext) to url(data:) in css files") { @options.data = true }
91
+ opts.on("-F", "--force", String, "Force minification when source files aren't newer than min files") { @options.force = true }
92
+
93
+ opts.parse!(@arguments) rescue return false
94
+
95
+ true
96
+ end
97
+
98
+ # TODO Change to work with directory hashes (css/: [ colors.css, layout.css ])
99
+ def create_output(output_name, inputs, type)
100
+ File.open(output_name, 'w') do |output_file|
101
+ inputs.each do |i|
102
+ output_file << IO.read(i)
112
103
  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
104
  end
119
105
 
120
- # TODO Change to work with directory hashes (css/: [ colors.css, layout.css ])
121
- def create_output(output_name, inputs, type)
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
+
122
111
  File.open(output_name, 'w') do |output_file|
123
- inputs.each do |i|
124
- output_file << IO.read(i)
125
- end
112
+ output_file << io.read
126
113
  end
114
+ end
115
+
116
+ # TODO Move this to before the file gets written
117
+ # Workaround for YUI Compressor Bug #1938329 & Bug #1961175
118
+ if output_name.match /\.css$/
119
+ output = IO.read(output_name)
127
120
 
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
121
+ output.gsub! ' and(', ' and ('
122
+ output.gsub! '/**/;}', '/**/}'
123
+
124
+ if @options.data
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}")!
134
138
  end
135
139
  end
136
140
 
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
141
+ File.open(output_name, 'w') do |output_file|
142
+ output_file << output
165
143
  end
166
- puts output_name
167
144
  end
168
145
 
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
146
+ puts output_name
147
+ end
148
+
149
+ def make_data_uri(content, content_type)
150
+ outuri = 'data:' + content_type + ';base64'
151
+ content = Base64.encode64(content)
152
+ outuri += ",#{content}"
179
153
 
180
- def output_help
181
- output_version
182
- RDoc::usage() #exits app
183
- end
154
+ outuri.gsub("\n", '')
155
+ end
156
+
157
+ def output_version
158
+ puts "#{File.basename(__FILE__)} version #{VERSION}"
159
+ end
160
+
161
+ def output_help
162
+ output_version
163
+ RDoc::usage() #exits app
164
+ end
184
165
  end
185
166
 
186
167
  # Create and run the application
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.5.1
4
+ version: 0.5.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Blake Elshire & Chris Griego
@@ -9,11 +9,19 @@ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
 
12
- date: 2008-05-16 00:00:00 -07:00
12
+ date: 2008-05-17 00:00:00 -07:00
13
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.
14
+ dependencies:
15
+ - !ruby/object:Gem::Dependency
16
+ name: mime-types
17
+ version_requirement:
18
+ version_requirements: !ruby/object:Gem::Requirement
19
+ requirements:
20
+ - - ">="
21
+ - !ruby/object:Gem::Version
22
+ version: "1.15"
23
+ version:
24
+ description: Blender is like ant or make for the front-end. It aggregates and compresses CSS and/or JavaScript assets for a site into efficient, production-ready files.
17
25
  email: belshire@gmail.com
18
26
  executables:
19
27
  - blend
@@ -45,12 +53,12 @@ required_rubygems_version: !ruby/object:Gem::Requirement
45
53
  - !ruby/object:Gem::Version
46
54
  version: "0"
47
55
  version:
48
- requirements: []
49
-
56
+ requirements:
57
+ - Java, v1.4 or greater
50
58
  rubyforge_project:
51
59
  rubygems_version: 1.0.1
52
60
  signing_key:
53
61
  specification_version: 2
54
- summary: Blender gives you production-ready CSS and/or JavaScript assets.
62
+ summary: Blender gives you efficient, production-ready CSS and/or JavaScript assets.
55
63
  test_files: []
56
64