lib/hogan_assets/tilt.rb in hogan_assets-1.3.1 vs lib/hogan_assets/tilt.rb in hogan_assets-1.3.2
- old
+ new
@@ -9,12 +9,14 @@
rescue LoadError
# haml not available
end
def evaluate(scope, locals, &block)
- text = if scope.pathname.extname == '.hamstache'
- raise "Unable to complile #{scope.pathname} because haml is not available. Did you add the haml gem?" unless HoganAssets::Config.haml_available?
+ template_path = TemplatePath.new scope
+
+ text = if template_path.is_hamstache?
+ raise "Unable to complile #{template_path.full_path} because haml is not available. Did you add the haml gem?" unless HoganAssets::Config.haml_available?
Haml::Engine.new(data, @options).render
else
data
end
@@ -23,14 +25,39 @@
# Only emit the source template if we are using lambdas
text = '' unless HoganAssets::Config.lambda_support?
<<-TEMPLATE
this.HoganTemplates || (this.HoganTemplates = {});
- this.HoganTemplates[#{template_name}] = new Hogan.Template(#{compiled_template}, #{text.inspect}, Hogan, {});
+ this.HoganTemplates[#{template_path.name}] = new Hogan.Template(#{compiled_template}, #{text.inspect}, Hogan, {});
TEMPLATE
end
protected
def prepare; end
+
+ class TemplatePath
+ attr_accessor :full_path
+
+ def initialize(scope)
+ self.template_path = scope.logical_path
+ self.full_path = scope.pathname
+ end
+
+ def is_hamstache?
+ full_path.to_s.end_with? '.hamstache'
+ end
+
+ def name
+ @name ||= relative_path.dump
+ end
+
+ private
+
+ attr_accessor :template_path
+
+ def relative_path
+ @relative_path ||= template_path.gsub(/^#{HoganAssets::Config.path_prefix}\/(.*)$/i, "\\1")
+ end
+ end
end
end