Method: Stache::Handlebars::Handler#handlebars_class_from_template

Defined in:
lib/stache/handlebars/handler.rb

#handlebars_class_from_template(template) ⇒ Object

suss out a constant name for the given template



71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
# File 'lib/stache/handlebars/handler.rb', line 71

def handlebars_class_from_template(template)
  const_name = ActiveSupport::Inflector.camelize(template.virtual_path.to_s)
  const_name = "#{Stache.wrapper_module_name}::#{const_name}" if Stache.wrapper_module_name

  begin
    const_name.constantize
  rescue NameError, LoadError => e
    # Only rescue NameError/LoadError concerning our mustache_class
    if e.message.match(/#{const_name}$/)
      Stache::Handlebars::View
    else
      raise e
    end
  end
end