def compile_mustache(view, options = {})
options[:templates] ||= settings.views if settings.respond_to?(:views)
options[:namespace] ||= self.class
unless options[:namespace].to_s.include? 'Views'
options[:namespace] = options[:namespace].const_get(:Views)
end
factory = Class.new(Mustache) do
self.view_namespace = options[:namespace]
self.view_path = options[:views]
end
if view.to_s.include?('.')
view, ext = view.to_s.split('.')
end
klass = factory.view_class(view)
klass.view_namespace = options[:namespace]
klass.view_path = options[:views]
if klass == Mustache
warn "No view class found for #{view} in #{factory.view_path}"
klass = factory
klass.template_name = view.to_s
elsif ext
if klass.const_defined?(ext_class = ext.capitalize)
klass = klass.const_get(ext_class)
else
new_class = Class.new(klass)
new_class.template_name = "#{view}.#{ext}"
klass.const_set(ext_class, new_class)
klass = new_class
end
end
klass.template_path = options[:templates] if options[:templates]
klass
end