smart_asset 0.2.3 → 0.3.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/lib/smart_asset.rb +40 -43
- data/lib/smart_asset/version.rb +1 -1
- metadata +3 -3
data/lib/smart_asset.rb
CHANGED
@@ -32,48 +32,53 @@ class SmartAsset
|
|
32
32
|
ext = ext_from_type type
|
33
33
|
FileUtils.mkdir_p dest
|
34
34
|
(@config[type] || {}).each do |package, files|
|
35
|
-
create_package = false
|
36
|
-
compressed = {}
|
37
35
|
if files
|
36
|
+
# Retrieve list of Git modified timestamps
|
37
|
+
modified = []
|
38
38
|
files.each do |file|
|
39
|
-
if File.exists?(
|
40
|
-
|
41
|
-
if
|
42
|
-
modified
|
39
|
+
if File.exists?("#{dir}/#{file}.#{ext}")
|
40
|
+
mod = `cd #{@root} && git log --pretty=format:%cd -n 1 --date=iso #{@config['public']}/#{@sources[type]}/#{file}.#{ext}`
|
41
|
+
if mod.strip.empty?
|
42
|
+
modified << Time.now.utc.strftime("%Y%m%d%H%M%S")
|
43
43
|
else
|
44
|
-
modified
|
44
|
+
modified << Time.parse(mod).utc.strftime("%Y%m%d%H%M%S")
|
45
45
|
end
|
46
|
-
file = file.to_s.gsub('/', '_')
|
47
|
-
unless File.exists?(destination = "#{dest}/#{modified}_#{package}_#{file}.#{ext}")
|
48
|
-
create_package = true
|
49
|
-
Dir["#{dest}/*[0-9]_#{package}_#{file}.#{ext}"].each do |old|
|
50
|
-
FileUtils.rm old
|
51
|
-
end
|
52
|
-
puts "\nCompressing #{source}..."
|
53
|
-
if ext == 'js'
|
54
|
-
warning = ENV['WARN'] ? nil : " --warning_level QUIET"
|
55
|
-
cmd = "java -jar #{CLOSURE_COMPILER} --js #{source} --js_output_file #{destination}#{warning}"
|
56
|
-
elsif ext == 'css'
|
57
|
-
cmd = "java -jar #{YUI_COMPRESSOR} #{source} -o #{destination}"
|
58
|
-
end
|
59
|
-
puts cmd if ENV['DEBUG']
|
60
|
-
`#{cmd}`
|
61
|
-
end
|
62
|
-
compressed[destination] = modified
|
63
46
|
end
|
64
47
|
end
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
48
|
+
modified = modified.sort.last
|
49
|
+
next unless modified
|
50
|
+
|
51
|
+
unless File.exists?(output = "#{dest}/#{modified}_#{package}.#{ext}")
|
52
|
+
data = []
|
53
|
+
|
54
|
+
# Join files in package
|
55
|
+
files.each do |file|
|
56
|
+
if File.exists?(source = "#{dir}/#{file}.#{ext}")
|
57
|
+
data << File.read(source)
|
74
58
|
end
|
75
|
-
File.open(package, 'w') { |f| f.write(data.join) }
|
76
59
|
end
|
60
|
+
|
61
|
+
# Delete old package
|
62
|
+
Dir["#{dest}/*[0-9]_#{package}.#{ext}"].each do |old|
|
63
|
+
FileUtils.rm old
|
64
|
+
end
|
65
|
+
|
66
|
+
# Don't create new compressed file if no data
|
67
|
+
next if data.empty?
|
68
|
+
|
69
|
+
# Compress joined files
|
70
|
+
tmp = "#{dest}/tmp.#{ext}"
|
71
|
+
File.open(tmp, 'w') { |f| f.write(data.join) }
|
72
|
+
puts "\nCreating #{output}..."
|
73
|
+
if ext == 'js'
|
74
|
+
warning = ENV['WARN'] ? nil : " --warning_level QUIET"
|
75
|
+
cmd = "java -jar #{CLOSURE_COMPILER} --js #{tmp} --js_output_file #{output}#{warning}"
|
76
|
+
elsif ext == 'css'
|
77
|
+
cmd = "java -jar #{YUI_COMPRESSOR} #{tmp} -o #{output}"
|
78
|
+
end
|
79
|
+
puts cmd if ENV['DEBUG']
|
80
|
+
`#{cmd}`
|
81
|
+
FileUtils.rm tmp
|
77
82
|
end
|
78
83
|
end
|
79
84
|
end
|
@@ -129,9 +134,8 @@ class SmartAsset
|
|
129
134
|
ext = ext_from_type type
|
130
135
|
|
131
136
|
if @envs.include?(@env.to_s)
|
132
|
-
match = match.gsub('/', '_')
|
133
137
|
@cache[type][match] =
|
134
|
-
if result = Dir["#{dest}/*_#{match}.#{ext}"].sort.last
|
138
|
+
if result = Dir["#{dest}/*[0-9]_#{match}.#{ext}"].sort.last
|
135
139
|
[ result.gsub(@pub, '') ]
|
136
140
|
else
|
137
141
|
[]
|
@@ -143,13 +147,6 @@ class SmartAsset
|
|
143
147
|
file = "/#{@sources[type]}/#{file}.#{ext}"
|
144
148
|
file if File.exists?("#{@pub}/#{file}")
|
145
149
|
end
|
146
|
-
elsif files
|
147
|
-
files.collect do |file|
|
148
|
-
if file.to_s == match
|
149
|
-
file = "/#{@sources[type]}/#{file}.#{ext}"
|
150
|
-
file if File.exists?("#{@pub}/#{file}")
|
151
|
-
end
|
152
|
-
end
|
153
150
|
end
|
154
151
|
end
|
155
152
|
result.flatten.compact.uniq
|
data/lib/smart_asset/version.rb
CHANGED
metadata
CHANGED
@@ -4,9 +4,9 @@ version: !ruby/object:Gem::Version
|
|
4
4
|
prerelease: false
|
5
5
|
segments:
|
6
6
|
- 0
|
7
|
-
- 2
|
8
7
|
- 3
|
9
|
-
|
8
|
+
- 1
|
9
|
+
version: 0.3.1
|
10
10
|
platform: ruby
|
11
11
|
authors:
|
12
12
|
- Winton Welsh
|
@@ -14,7 +14,7 @@ autorequire:
|
|
14
14
|
bindir: bin
|
15
15
|
cert_chain: []
|
16
16
|
|
17
|
-
date: 2010-12-
|
17
|
+
date: 2010-12-08 00:00:00 -08:00
|
18
18
|
default_executable:
|
19
19
|
dependencies:
|
20
20
|
- !ruby/object:Gem::Dependency
|