lib/linner/asset.rb in linner-0.2.0 vs lib/linner/asset.rb in linner-0.3.0

- old
+ new

@@ -3,23 +3,47 @@ attr_accessor :path, :content def initialize(path) @path = path - @content ||= begin + if File.exist? @path + @mtime ||= File.mtime(path).to_i + end + end + + def mtime + @mtime + end + + def content + return @content if @content + source = begin File.exist?(path) ? Tilt.new(path, :default_encoding => "UTF-8").render : "" rescue RuntimeError File.read(path) end + if wrappable? + @content = wrap(source) + else + @content = source + end end - def wrap - Wrapper.wrap(logical_path.chomp(File.extname logical_path), @content) + def wrap(source) + Wrapper.wrap(logical_path.chomp(File.extname logical_path), source) end + def javascript? + Tilt[path] and Tilt[path].default_mime_type == "application/javascript" + end + + def stylesheet? + Tilt[path] and Tilt[path].default_mime_type == "text/css" + end + def wrappable? - !!(@path.include? Linner.environment.app_folder and Template.template_for_script?(@path)) + !!(self.javascript? and !Linner.env.modules_ignored.include?(@path)) end def write FileUtils.mkdir_p File.dirname(@path) File.open @path, "w" do |file| @@ -30,9 +54,9 @@ def compress @content = Compressor.compress(self) end def logical_path - @logical_path ||= @path.gsub(/#{Linner.environment.app_folder}\/\w*\//, "") + @logical_path ||= @path.gsub(/#{Linner.env.paths.join("\/|")}/, "") end end end