Class: ActionView::Template
- Inherits:
-
Object
- Object
- ActionView::Template
- Extended by:
- Handlers, ActiveSupport::Autoload
- Defined in:
- lib/action_view/template.rb,
lib/action_view/template/text.rb,
lib/action_view/template/error.rb,
lib/action_view/template/handler.rb,
lib/action_view/template/handlers.rb,
lib/action_view/template/handlers/erb.rb
Overview
Action View Template Handlers
Defined Under Namespace
Modules: Handlers Classes: Error, Handler, Text
Constant Summary collapse
- Finalizer =
proc do |method_name, mod| proc do mod.module_eval do remove_possible_method method_name end end end
Instance Attribute Summary collapse
-
#formats ⇒ Object
readonly
Returns the value of attribute formats.
-
#handler ⇒ Object
readonly
Returns the value of attribute handler.
-
#identifier ⇒ Object
readonly
Returns the value of attribute identifier.
-
#original_encoding ⇒ Object
readonly
Returns the value of attribute original_encoding.
-
#source ⇒ Object
readonly
Returns the value of attribute source.
-
#virtual_path ⇒ Object
readonly
Returns the value of attribute virtual_path.
Instance Method Summary collapse
- #counter_name ⇒ Object
-
#initialize(source, identifier, handler, details) ⇒ Template
constructor
A new instance of Template.
- #inspect ⇒ Object
- #mime_type ⇒ Object
- #render(view, locals, &block) ⇒ Object
- #variable_name ⇒ Object
Methods included from Handlers
extended, extensions, handler_class_for_extension, register_default_template_handler, register_template_handler, registered_template_handler, template_handler_extensions
Constructor Details
#initialize(source, identifier, handler, details) ⇒ Template
Returns a new instance of Template.
112 113 114 115 116 117 118 119 120 121 122 |
# File 'lib/action_view/template.rb', line 112 def initialize(source, identifier, handler, details) @source = source @identifier = identifier @handler = handler @original_encoding = nil @method_names = {} format = details[:format] || :html @formats = Array.wrap(format).map { |f| f.is_a?(Mime::Type) ? f.ref : f } @virtual_path = details[:virtual_path].try(:sub, ".#{format}", "") end |
Instance Attribute Details
#formats ⇒ Object (readonly)
Returns the value of attribute formats.
101 102 103 |
# File 'lib/action_view/template.rb', line 101 def formats @formats end |
#handler ⇒ Object (readonly)
Returns the value of attribute handler.
101 102 103 |
# File 'lib/action_view/template.rb', line 101 def handler @handler end |
#identifier ⇒ Object (readonly)
Returns the value of attribute identifier.
101 102 103 |
# File 'lib/action_view/template.rb', line 101 def identifier @identifier end |
#original_encoding ⇒ Object (readonly)
Returns the value of attribute original_encoding.
101 102 103 |
# File 'lib/action_view/template.rb', line 101 def original_encoding @original_encoding end |
#source ⇒ Object (readonly)
Returns the value of attribute source.
101 102 103 |
# File 'lib/action_view/template.rb', line 101 def source @source end |
#virtual_path ⇒ Object (readonly)
Returns the value of attribute virtual_path.
101 102 103 |
# File 'lib/action_view/template.rb', line 101 def virtual_path @virtual_path end |
Instance Method Details
#counter_name ⇒ Object
154 155 156 |
# File 'lib/action_view/template.rb', line 154 def counter_name @counter_name ||= "#{variable_name}_counter".to_sym end |
#inspect ⇒ Object
158 159 160 161 162 163 164 165 |
# File 'lib/action_view/template.rb', line 158 def inspect @inspect ||= if defined?(Rails.root) identifier.sub("#{Rails.root}/", '') else identifier end end |
#mime_type ⇒ Object
146 147 148 |
# File 'lib/action_view/template.rb', line 146 def mime_type @mime_type ||= Mime::Type.lookup_by_extension(@formats.first.to_s) if @formats.first end |
#render(view, locals, &block) ⇒ Object
124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 |
# File 'lib/action_view/template.rb', line 124 def render(view, locals, &block) # Notice that we use a bang in this instrumentation because you don't want to # consume this in production. This is only slow if it's being listened to. ActiveSupport::Notifications.instrument("!render_template.action_view", :virtual_path => @virtual_path) do if view.is_a?(ActionView::CompiledTemplates) mod = ActionView::CompiledTemplates else mod = view.singleton_class end method_name = compile(locals, view, mod) view.send(method_name, locals, &block) end rescue Exception => e if e.is_a?(Template::Error) e.sub_template_of(self) raise e else raise Template::Error.new(self, view.respond_to?(:assigns) ? view.assigns : {}, e) end end |
#variable_name ⇒ Object
150 151 152 |
# File 'lib/action_view/template.rb', line 150 def variable_name @variable_name ||= @virtual_path[%r'_?(\w+)(\.\w+)*$', 1].to_sym end |