class Pannier::Asset
Attributes
basename[RW]
content[RW]
dirname[RW]
Public Class Methods
new(basename, dirname, package)
click to toggle source
# File lib/pannier/asset.rb, line 10 def initialize(basename, dirname, package) @basename, @dirname, @package = basename, dirname, package @content = original_content end
Public Instance Methods
<=>(other)
click to toggle source
# File lib/pannier/asset.rb, line 32 def <=>(other) path <=> other.path end
copy_to(to_dirname)
click to toggle source
# File lib/pannier/asset.rb, line 36 def copy_to(to_dirname) copy = self.dup copy.content = content.dup if content copy.dirname = to_dirname copy end
eql?(other)
click to toggle source
# File lib/pannier/asset.rb, line 24 def eql?(other) path == other.path end
hash()
click to toggle source
# File lib/pannier/asset.rb, line 28 def hash path.hash end
modify!(modifier)
click to toggle source
# File lib/pannier/asset.rb, line 43 def modify!(modifier) modified = modifier.call(content, basename) self.content, self.basename = modified end
original_content()
click to toggle source
# File lib/pannier/asset.rb, line 19 def original_content return unless File.exists?(path) @original_content ||= File.read(path) end
path()
click to toggle source
# File lib/pannier/asset.rb, line 15 def path File.join(@dirname, @basename) end
serve_from(app)
click to toggle source
# File lib/pannier/mounted/asset.rb, line 6 def serve_from(app) asset_path = Pathname.new(path) app_output_path = Pathname.new(app.output_path) relative_path = asset_path.relative_path_from(app_output_path) File.join(*['/', app.mount_path, relative_path.to_s].compact) end
write_file!()
click to toggle source
# File lib/pannier/asset.rb, line 48 def write_file! FileUtils.mkdir_p(@dirname) File.open(path, 'w+') do |file| file << content end end