class Asset::Item
Attributes
app[RW]
key[RW]
kpath[RW]
modified[RW]
name[RW]
path[RW]
type[RW]
Public Class Methods
new(*args)
click to toggle source
Init
# File lib/assets/item.rb, line 7 def initialize(*args) @path, @type, @key, @modified = args @app = !!(@path =~ /^bundle\.(js|css)$/) @name = @path.rpartition('.')[0] @kpath = "#{@name}-#{kext}" end
Public Instance Methods
cache_path()
click to toggle source
Cache path
# File lib/assets/item.rb, line 50 def cache_path @cache_path ||= File.join(::Asset.cache, kext) end
cached()
click to toggle source
The cached content
# File lib/assets/item.rb, line 35 def cached @cached ||= (read_cache || write_cache) end
compressed()
click to toggle source
Compressed joined files
# File lib/assets/item.rb, line 60 def compressed @compressed ||= case @type when 'css' Sass::Engine.new(joined, :syntax => :scss, :cache => false, :style => :compressed).render rescue joined when 'js' Uglifier.compile(joined, :mangle => false, :comments => :none) rescue joined end end
content(compress = p?)
click to toggle source
Get the content, will be compressed in production typically.
# File lib/assets/item.rb, line 30 def content(compress = p?) compress ? cached : joined end
files(bundle = true)
click to toggle source
Get the files for this item
# File lib/assets/item.rb, line 15 def files(bundle = true) (@app and bundle) ? ::Asset.bundle[@type] : [@path] end
joined()
click to toggle source
All files joined
# File lib/assets/item.rb, line 70 def joined @joined ||= files.map{|f| File.read(File.join(::Asset.path, @type, f))}.join end
kext()
click to toggle source
Key and extension
# File lib/assets/item.rb, line 55 def kext @kext ||= %{#{@key}.#{@type}} end
print()
click to toggle source
Print data
# File lib/assets/item.rb, line 75 def print [:path, :type, :key, :name, :modified, :files, :content].map{|r| "#{r.upcase}: #{send(r).inspect}"}.join("\n") end
read_cache()
click to toggle source
Read cache
# File lib/assets/item.rb, line 40 def read_cache File.read(cache_path) rescue nil end
sources()
click to toggle source
Get the sources for this item
# File lib/assets/item.rb, line 20 def sources files(!p?) end
src()
click to toggle source
Get the full path
# File lib/assets/item.rb, line 25 def src File.join('/assets', @type, (p? ? @kpath : @path)) end
write_cache()
click to toggle source
Store in cache
# File lib/assets/item.rb, line 45 def write_cache compressed.tap{|c| File.atomic_write(cache_path){|f| f.write(c)}} end
Private Instance Methods
p?()
click to toggle source
Production mode?
# File lib/assets/item.rb, line 82 def p? ::Asset::Util.p? end