98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
|
# File 'lib/assette/cli.rb', line 98
def compile
files = []
all_files = []
Assette.config.compiling = true
unless File.exist?('assets')
Dir.mkdir('assets')
end
sha = Assette.config.cachebuster_string.call
Assette.config.sha = sha
Assette.config.file_paths.each do |path|
all_files |= Dir[File.join(path,'**',"*")]
Assette::Reader::ALL.keys.each do |extension|
files |= Dir[File.join(path,'**',"*.#{extension}")]
end
end
not_compiled = all_files - files
files.delete_if {|f| f =~ /\/_/}
container = if Assette.config.cache_method.to_s == 'path'
File.join(Assette.config.build_target,sha)
else
Assette.config.build_target
end
made_dirs = []
say "Compiling all asset files to #{container}"
files_to_minify = []
files.each do |file_path|
Assette::File.open(file_path) do |file|
if file.minify?
files_to_minify.push(file_path)
else
unless options.minified? || options.static_min?
target_path = file.relative_target_path
Assette.config.file_paths.each do |p|
end
new_path = File.join(container,target_path)
Assette.logger.debug("Compiling file") {"#{file.path} -> #{new_path}"}
create_file(new_path, file.all_code, :verbose => !options.not_verbose?)
end
end
end
end
Assette.config.minifying do
say "\nCreating minified versions of files" unless files_to_minify.empty?
files_to_minify.each do |file_path|
Assette::File.open(file_path) do |file|
target_path = file.relative_target_path
new_path = File.join(container,target_path).sub(/(\.[A-Za-z0-9]{2,10})$/,'.min\1')
Assette.logger.debug("Compiling minified file") {"#{file.path} -> #{new_path}"}
create_file(new_path, file.all_code, :verbose => !options.not_verbose?)
end
end
end
say "\nCopying all non-compiled assets to #{container}"
not_compiled.each do |file|
next if File.directory?(file)
next if options.minified?
target_path = file.dup
Assette.config.file_paths.each do |p|
target_path.gsub!(Regexp.new(p+'/'),'')
end
new_path = File.join(container,target_path)
Assette.logger.debug("Copying file") {"#{file} -> #{new_path}"}
copy_file(file,new_path, :verbose => !options.not_verbose?)
end
version_file = Assette.config.asset_version_file
File.delete(version_file) if File.exist?(version_file)
create_file(version_file,sha)
Assette.config.after_compile.call(sha)
end
|