js-preflight 0.0.4 → 0.0.5

Sign up to get free protection for your applications and to get access to all the features.
Files changed (3) hide show
  1. data/bin/preflight +16 -14
  2. data/lib/js-preflight/version.rb +1 -1
  3. metadata +2 -2
data/bin/preflight CHANGED
@@ -166,25 +166,18 @@ if ARGV.length > 0
166
166
  file.rewind
167
167
  File.open(out_filename, "w+") do |outfile|
168
168
  while line = file.gets do
169
- match = line[js_regexp, 1]
170
- case
171
169
  # If this is a script tag, and we haven't packed it, make sure the file
172
170
  # is copied and the script tag is retained.
173
171
  # If it's a script tag and it matches the last of the packed .js files,
174
172
  # insert a script tag that links to our assets.js file.
175
- when match = line[js_regexp, 1]
173
+ match = line[js_regexp, 1]
174
+ if match
176
175
  if !js_files.include?(match)
177
176
  ::Js::Preflight::Instructions.ensure_copy(File.join(path.dirname, match), File.join(base_path, match))
178
177
  outfile << line
179
178
  elsif match == js_files.last
180
179
  outfile << %Q{<script src="js/assets.js" type="text/javascript" charset="utf-8"></script>}
181
- end
182
-
183
- # When a stylesheet link is encountered, ensure it is copied as well.
184
- when match = line[css_regexp, 1]
185
- ::Js::Preflight::Instructions.ensure_copy(File.join(path.dirname, match), File.join(base_path, match))
186
- outfile << line
187
-
180
+ end
188
181
  # If this isn't a script tag, just append to the target file.
189
182
  else
190
183
  outfile << line
@@ -194,15 +187,24 @@ if ARGV.length > 0
194
187
  end
195
188
  end
196
189
 
197
- # Finally, copy the packed file as assets.js, and the entire images directory
198
- # (if it exists), to build_path if we're doing that.
190
+ # Finally, copy the packed file as assets.js, and the entire contents of
191
+ # the images and css directories (if they exist), to build_path if we're doing that.
192
+ # The following relative paths will be tested:
193
+ # css, stylesheets, images, img
199
194
  if options[:build_path]
200
195
  js_output.rewind
196
+ STDERR.puts "Copying assets.js"
201
197
  File.open(File.join(options[:build_path], "js", "assets.js"), "w") do |assets|
202
198
  assets.write js_output.read
203
199
  end
204
- images_path = File.join(Pathname.new(ARGV[0]).dirname, "images")
205
- ::Js::Preflight::Instructions.ensure_copy(images_path, options[:build_path]) if Dir.exists?(images_path)
200
+ asset_paths = %w{css stylesheets images img}
201
+ asset_paths.each do |path|
202
+ asset_path = File.join(Pathname.new(ARGV[0]).dirname, path)
203
+ if Dir.exists?(asset_path)
204
+ STDERR.puts "Copying #{asset_path}"
205
+ ::Js::Preflight::Instructions.ensure_copy(asset_path, options[:build_path]) if Dir.exists?(asset_path)
206
+ end
207
+ end
206
208
  # or output the packed .js file as a file, if we're doing that
207
209
  elsif options[:js_file]
208
210
  js_output.close
@@ -1,5 +1,5 @@
1
1
  module Js
2
2
  module Preflight
3
- VERSION = "0.0.4"
3
+ VERSION = "0.0.5"
4
4
  end
5
5
  end
metadata CHANGED
@@ -5,8 +5,8 @@ version: !ruby/object:Gem::Version
5
5
  segments:
6
6
  - 0
7
7
  - 0
8
- - 4
9
- version: 0.0.4
8
+ - 5
9
+ version: 0.0.5
10
10
  platform: ruby
11
11
  authors:
12
12
  - Scott Burton