./lib/lux_assets/base.rb in lux_assets-0.2.1 vs ./lib/lux_assets/base.rb in lux_assets-0.2.2
- old
+ new
@@ -1,27 +1,7 @@
-# LuxAssets.configure do
-# asset :admin do
-# js do
-# add 'js/admin/js_vendor/*'
-# add 'js/admin/js/*'
-# add 'js/shared/*'
-# add 'js/admin/index.coffee'
-# end
-# css do
-# add 'css/admin/index.scss'
-# end
-# end
-# end
-# ...
+# Main assets module
-# LuxAssets.css('admin').files
-# LuxAssets.css(:admin).compile
-
-# LuxAssets.css(:admin).compile_all do |name, path|
-# puts "Compile #{name} -> #{path}"
-# end
-
module LuxAssets
extend self
CONFIG_PATH = Pathname.new ENV.fetch('ASSETS_CONFIG') { './config/assets.rb' }
@@ -37,11 +17,11 @@
@relative_root = name if name
@relative_root
end
def die text
- puts text
+ puts text.try(:red)
exit
end
def asset name
@name = name.to_s
@@ -106,14 +86,16 @@
raise ArgumentError.new('name not deinfed') if name.empty?
to_h[ext][name.to_s]
end
+ # compile single asset
def compile path
LuxAssets::Element.new(path).compile
end
+ # compile all assets
def compile_all
# generate master file for every resource
for ext in [:js, :css]
for name in to_h[ext].keys
path = LuxAssets.send(ext, name).compile
@@ -125,15 +107,16 @@
files = Dir['./public/assets/*.css'] + Dir['./public/assets/*.js']
files.each do |file|
LuxAssets.run 'gzip -k %s' % file unless File.exist?('%s.gz' % file)
end
- # touch all files reset timestamp
+ # touch all files and reset the timestamp
Dir['./public/assets/*']
.each { |file| system 'touch -t 201001010101 %s' % file }
end
+ # get all files as a hash
def to_h
unless @assets_loaded
die 'Assets file not found in %s' % CONFIG_PATH unless CONFIG_PATH.exist?
@assets_loaded = true
eval CONFIG_PATH.read
@@ -147,16 +130,24 @@
data = to_h.dup
data.each do |ext, value_hash|
puts ext.to_s.upcase.green
value_hash.each do |key, files|
puts ' %s' % key.green
+
+ total = 0
+
files.each_with_index do |file, i|
if File.exist?(file)
- puts ' %s kb - %s' % [(File.size(file)/1024.to_f).round(1).to_s.rjust(6), file]
+ size = File.size(file)
+ total += size
+ puts ' %s kB - %s' % [(size/1024.to_f).round(1).to_s.rjust(6), file]
else
puts ' %s' % file
end
end
+
+ total = '%s kB in total' % (total/1024.to_f).round(1).to_s
+ puts total.rjust(20)
end
end
end
def run what, cache_file=nil
\ No newline at end of file