class Linner::Asset
Attributes
content[RW]
path[RW]
Public Class Methods
new(path)
click to toggle source
# File lib/linner/asset.rb, line 9 def initialize(path) @path = path @mtime = File.mtime(path).to_i if File.exist?(path) end
Public Instance Methods
compress()
click to toggle source
# File lib/linner/asset.rb, line 94 def compress @content = Compressor.compress(self) end
digest_path()
click to toggle source
# File lib/linner/asset.rb, line 22 def digest_path digest = Digest::MD5.hexdigest content path.chomp(extname) << "-#{digest}" << extname end
eruby?()
click to toggle source
# File lib/linner/asset.rb, line 79 def eruby? Tilt[path] and Tilt[path].default_mime_type = "application/x-eruby" end
extname()
click to toggle source
# File lib/linner/asset.rb, line 18 def extname @extname = File.extname path end
javascript?()
click to toggle source
# File lib/linner/asset.rb, line 67 def javascript? Tilt[path] and Tilt[path].default_mime_type == "application/javascript" end
logical_path()
click to toggle source
# File lib/linner/asset.rb, line 98 def logical_path @logical_path ||= @path.gsub(/^(#{Linner.env.paths.join("|")})\/?/, "") end
mtime()
click to toggle source
# File lib/linner/asset.rb, line 14 def mtime @mtime end
relative_digest_path()
click to toggle source
# File lib/linner/asset.rb, line 27 def relative_digest_path digest_path.gsub /#{Linner.env.public_folder}/, "" end
revable?()
click to toggle source
# File lib/linner/asset.rb, line 31 def revable? javascript? or stylesheet? end
revision!()
click to toggle source
# File lib/linner/asset.rb, line 35 def revision! File.rename path, digest_path end
stylesheet?()
click to toggle source
# File lib/linner/asset.rb, line 71 def stylesheet? Tilt[path] and Tilt[path].default_mime_type == "text/css" end
template?()
click to toggle source
# File lib/linner/asset.rb, line 75 def template? Tilt[path] and Tilt[path].default_mime_type == "text/template" end
wrap(source)
click to toggle source
# File lib/linner/asset.rb, line 55 def wrap(source) if javascript? Wrapper::Module.wrap(logical_path.chomp(File.extname logical_path), source) elsif template? if File.basename(path).start_with?("_") Wrapper::Template.partial_wrap(logical_path.chomp(File.extname logical_path), source) else Wrapper::Template.wrap(logical_path.chomp(File.extname logical_path), source) end end end
wrappable?()
click to toggle source
# File lib/linner/asset.rb, line 83 def wrappable? !!(self.javascript? and !Linner.env.modules_ignored.include?(@path) or self.template?) end
write()
click to toggle source
# File lib/linner/asset.rb, line 87 def write FileUtils.mkdir_p File.dirname(@path) File.open @path, "w" do |file| file.write @content end end