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.
139 140 141 142 143 144 145 146 147 148 149 |
# File 'lib/action_view/template.rb', line 139 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.
128 129 130 |
# File 'lib/action_view/template.rb', line 128 def formats @formats end |
#handler ⇒ Object (readonly)
Returns the value of attribute handler.
128 129 130 |
# File 'lib/action_view/template.rb', line 128 def handler @handler end |
#identifier ⇒ Object (readonly)
Returns the value of attribute identifier.
128 129 130 |
# File 'lib/action_view/template.rb', line 128 def identifier @identifier end |
#original_encoding ⇒ Object (readonly)
Returns the value of attribute original_encoding.
128 129 130 |
# File 'lib/action_view/template.rb', line 128 def original_encoding @original_encoding end |
#source ⇒ Object (readonly)
Returns the value of attribute source.
128 129 130 |
# File 'lib/action_view/template.rb', line 128 def source @source end |
#virtual_path ⇒ Object (readonly)
Returns the value of attribute virtual_path.
128 129 130 |
# File 'lib/action_view/template.rb', line 128 def virtual_path @virtual_path end |
Instance Method Details
#counter_name ⇒ Object
181 182 183 |
# File 'lib/action_view/template.rb', line 181 def counter_name @counter_name ||= "#{variable_name}_counter".to_sym end |
#inspect ⇒ Object
185 186 187 188 189 190 191 192 |
# File 'lib/action_view/template.rb', line 185 def inspect @inspect ||= if defined?(Rails.root) identifier.sub("#{Rails.root}/", '') else identifier end end |
#mime_type ⇒ Object
173 174 175 |
# File 'lib/action_view/template.rb', line 173 def mime_type @mime_type ||= Mime::Type.lookup_by_extension(@formats.first.to_s) if @formats.first end |
#render(view, locals, &block) ⇒ Object
151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 |
# File 'lib/action_view/template.rb', line 151 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
177 178 179 |
# File 'lib/action_view/template.rb', line 177 def variable_name @variable_name ||= @virtual_path[%r'_?(\w+)(\.\w+)*$', 1].to_sym end |