Class: Linner::Asset
- Inherits:
-
Object
- Object
- Linner::Asset
- Defined in:
- lib/linner/asset.rb
Defined Under Namespace
Classes: RenderError
Instance Attribute Summary collapse
-
#content(context = nil) ⇒ Object
Returns the value of attribute content.
-
#path ⇒ Object
Returns the value of attribute path.
Instance Method Summary collapse
- #compress ⇒ Object
- #digest_path ⇒ Object
- #eruby? ⇒ Boolean
- #extname ⇒ Object
-
#initialize(path) ⇒ Asset
constructor
A new instance of Asset.
- #javascript? ⇒ Boolean
- #logical_path ⇒ Object
- #mtime ⇒ Object
- #relative_digest_path ⇒ Object
- #revable? ⇒ Boolean
- #revision! ⇒ Object
- #stylesheet? ⇒ Boolean
- #template? ⇒ Boolean
- #wrap(source) ⇒ Object
- #wrappable? ⇒ Boolean
- #write ⇒ Object
Constructor Details
#initialize(path) ⇒ Asset
Returns a new instance of Asset.
9 10 11 12 |
# File 'lib/linner/asset.rb', line 9 def initialize(path) @path = path @mtime = File.mtime(path).to_i if File.exist?(path) end |
Instance Attribute Details
#content(context = nil) ⇒ Object
Returns the value of attribute content.
7 8 9 |
# File 'lib/linner/asset.rb', line 7 def content @content end |
#path ⇒ Object
Returns the value of attribute path.
7 8 9 |
# File 'lib/linner/asset.rb', line 7 def path @path end |
Instance Method Details
#compress ⇒ Object
94 95 96 |
# File 'lib/linner/asset.rb', line 94 def compress @content = Compressor.compress(self) end |
#digest_path ⇒ Object
22 23 24 25 |
# File 'lib/linner/asset.rb', line 22 def digest_path digest = Digest::MD5.hexdigest content path.chomp(extname) << "-#{digest}" << extname end |
#eruby? ⇒ Boolean
79 80 81 |
# File 'lib/linner/asset.rb', line 79 def eruby? Tilt[path] and Tilt[path].default_mime_type = "application/x-eruby" end |
#extname ⇒ Object
18 19 20 |
# File 'lib/linner/asset.rb', line 18 def extname @extname = File.extname path end |
#javascript? ⇒ Boolean
67 68 69 |
# File 'lib/linner/asset.rb', line 67 def javascript? Tilt[path] and Tilt[path].default_mime_type == "application/javascript" end |
#logical_path ⇒ Object
98 99 100 |
# File 'lib/linner/asset.rb', line 98 def logical_path @logical_path ||= @path.gsub(/^(#{Linner.env.paths.join("|")})\/?/, "") end |
#mtime ⇒ Object
14 15 16 |
# File 'lib/linner/asset.rb', line 14 def mtime @mtime end |
#relative_digest_path ⇒ Object
27 28 29 |
# File 'lib/linner/asset.rb', line 27 def relative_digest_path digest_path.gsub /#{Linner.env.public_folder}/, "" end |
#revable? ⇒ Boolean
31 32 33 |
# File 'lib/linner/asset.rb', line 31 def revable? javascript? or stylesheet? end |
#revision! ⇒ Object
35 36 37 |
# File 'lib/linner/asset.rb', line 35 def revision! File.rename path, digest_path end |
#stylesheet? ⇒ Boolean
71 72 73 |
# File 'lib/linner/asset.rb', line 71 def stylesheet? Tilt[path] and Tilt[path].default_mime_type == "text/css" end |
#template? ⇒ Boolean
75 76 77 |
# File 'lib/linner/asset.rb', line 75 def template? Tilt[path] and Tilt[path].default_mime_type == "text/template" end |
#wrap(source) ⇒ Object
55 56 57 58 59 60 61 62 63 64 65 |
# 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? ⇒ Boolean
83 84 85 |
# File 'lib/linner/asset.rb', line 83 def wrappable? !!(self.javascript? and !Linner.env.modules_ignored.include?(@path) or self.template?) end |
#write ⇒ Object
87 88 89 90 91 92 |
# 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 |