Module: ActionView::Helpers::MustacheHelper

Extended by:
ActiveSupport::Concern
Defined in:
lib/action_view/helpers/mustache_helper.rb

Overview

Public: Standard helper mixed into ActionView context for constructing the Mustache View.

Instance Method Summary collapse

Instance Method Details

#load_mustache_view_class_name(klass_name) ⇒ Object

Internal: Load Mustache View class.

klass_name - Actual Class or String of class name.

Returns view class that is a subclass of ActionView::Mustache or raises an exception.



69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
# File 'lib/action_view/helpers/mustache_helper.rb', line 69

def load_mustache_view_class_name(klass_name)
  case klass_name
  when String
    klass_name = klass_name.camelize
    begin
      klass = klass_name.constantize
    rescue NameError => e
      load_path = ActiveSupport::Dependencies.autoload_paths.map { |p| "  #{p}\n" }.join
      raise NameError, "Couldn't find #{klass_name}\n#{load_path}"
    end
  when Class
    klass = klass_name
  else
    raise ArgumentError, "#{klass_name} isn't a Class"
  end

  unless klass < ActionView::Mustache
    raise TypeError, "#{klass} isn't a subclass of ActionView::Mustache"
  end
  klass
end

#mustache_viewObject

Public: Get or initialize Mustache View.

The view object is cached so partial renders will reuse the same instance.

Returns a Mustache View which is a subclass of ActionView::Mustache.



98
99
100
# File 'lib/action_view/helpers/mustache_helper.rb', line 98

def mustache_view
  @_mustache_view ||= mustache_view_class.new(self)
end

#mustache_view_classObject

Public: Get Mustache View Class for template.

Choose template class by camalizing the template path name and prefixing our view namespace.

The class must be a subclass of ActionView::Mustache otherwise a TypeError will be raised.

If the template is “anonymous” and has no path, which is the case for render(:inline), the default ActionView::Mustache base class will be returned.

Examples

"blog/show" => Blog::Show

Returns Class or raises a TypeError.



42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
# File 'lib/action_view/helpers/mustache_helper.rb', line 42

def mustache_view_class
  if @virtual_path
    begin
      klass = "#{mustache_view_namespace}/#{@virtual_path}"
      load_mustache_view_class_name(klass)
    rescue NameError => e
      if klass = mustache_default_view_class
        load_mustache_view_class_name(klass)
      else
        raise e
      end
    end
  else
    if klass = mustache_default_view_class
      load_mustache_view_class_name(klass)
    else
      ActionView::Mustache
    end
  end
end