lib/hogan_assets/tilt.rb in hogan_assets-1.3.4 vs lib/hogan_assets/tilt.rb in hogan_assets-1.4.0

- old
+ new

@@ -3,22 +3,24 @@ module HoganAssets class Tilt < Tilt::Template self.default_mime_type = 'application/javascript' def initialize_engine - require_template_library 'haml' - rescue LoadError - # haml not available + load_haml + load_slim end def evaluate(scope, locals, &block) template_path = TemplatePath.new scope template_namespace = HoganAssets::Config.template_namespace text = if template_path.is_hamstache? raise "Unable to compile #{template_path.full_path} because haml is not available. Did you add the haml gem?" unless HoganAssets::Config.haml_available? Haml::Engine.new(data, HoganAssets::Config.haml_options.merge(@options)).render + elsif template_path.is_slimstache? + raise "Unable to compile #{template_path.full_path} because slim is not available. Did you add the slim gem?" unless HoganAssets::Config.slim_available? + Slim::Template.new(HoganAssets::Config.slim_options.merge(@options)) { data }.render else data end compiled_template = Hogan.compile(text) @@ -32,10 +34,22 @@ TEMPLATE end protected + def load_haml + require 'haml' + rescue LoadError + # haml not available + end + + def load_slim + require 'slim' + rescue LoadError + # slim not available + end + def prepare; end class TemplatePath attr_accessor :full_path @@ -44,9 +58,13 @@ self.full_path = scope.pathname end def is_hamstache? full_path.to_s.end_with? '.hamstache' + end + + def is_slimstache? + full_path.to_s.end_with? '.slimstache' end def name @name ||= relative_path.dump end