Class: ActionView::Template
- Inherits:
-
Object
- Object
- ActionView::Template
- Extended by:
- Handlers, ActiveSupport::Autoload
- Defined in:
- actionpack/lib/action_view/template.rb,
actionpack/lib/action_view/template/text.rb,
actionpack/lib/action_view/template/error.rb,
actionpack/lib/action_view/template/handler.rb,
actionpack/lib/action_view/template/handlers.rb,
actionpack/lib/action_view/template/handlers/erb.rb
Overview
Action View Template Handlers
Defined Under Namespace
Modules: Handlers Classes: Error, Handler, Text
Constant Summary
- Finalizer =
proc do |method_name, mod| proc do mod.module_eval do remove_possible_method method_name end end end
Instance Attribute Summary (collapse)
-
- (Object) formats
readonly
Returns the value of attribute formats.
-
- (Object) handler
readonly
Returns the value of attribute handler.
-
- (Object) identifier
readonly
Returns the value of attribute identifier.
-
- (Object) original_encoding
readonly
Returns the value of attribute original_encoding.
-
- (Object) source
readonly
Returns the value of attribute source.
-
- (Object) virtual_path
readonly
Returns the value of attribute virtual_path.
Instance Method Summary (collapse)
- - (Object) counter_name
-
- (Template) initialize(source, identifier, handler, details)
constructor
A new instance of Template.
- - (Object) inspect
- - (Object) mime_type
- - (Object) render(view, locals, &block)
- - (Object) variable_name
Methods included from Handlers
extended, extensions, handler_class_for_extension, register_default_template_handler, register_template_handler, registered_template_handler, template_handler_extensions
Methods included from ActiveSupport::Autoload
autoload, autoload_at, autoload_under, autoloads, eager_autoload, eager_autoload!
Constructor Details
- (Template) initialize(source, identifier, handler, details)
A new instance of Template
112 113 114 115 116 117 118 119 120 121 122 |
# File 'actionpack/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(&:to_sym) @virtual_path = details[:virtual_path].try(:sub, ".#{format}", "") end |
Instance Attribute Details
- (Object) formats (readonly)
Returns the value of attribute formats
101 102 103 |
# File 'actionpack/lib/action_view/template.rb', line 101 def formats @formats end |
- (Object) handler (readonly)
Returns the value of attribute handler
101 102 103 |
# File 'actionpack/lib/action_view/template.rb', line 101 def handler @handler end |
- (Object) identifier (readonly)
Returns the value of attribute identifier
101 102 103 |
# File 'actionpack/lib/action_view/template.rb', line 101 def identifier @identifier end |
- (Object) original_encoding (readonly)
Returns the value of attribute original_encoding
101 102 103 |
# File 'actionpack/lib/action_view/template.rb', line 101 def original_encoding @original_encoding end |
- (Object) source (readonly)
Returns the value of attribute source
101 102 103 |
# File 'actionpack/lib/action_view/template.rb', line 101 def source @source end |
- (Object) virtual_path (readonly)
Returns the value of attribute virtual_path
101 102 103 |
# File 'actionpack/lib/action_view/template.rb', line 101 def virtual_path @virtual_path end |
Instance Method Details
- (Object) counter_name
154 155 156 |
# File 'actionpack/lib/action_view/template.rb', line 154 def counter_name @counter_name ||= "#{variable_name}_counter".to_sym end |
- (Object) inspect
158 159 160 161 162 163 164 165 |
# File 'actionpack/lib/action_view/template.rb', line 158 def inspect @inspect ||= if defined?(Rails.root) identifier.sub("#{Rails.root}/", '') else identifier end end |
- (Object) mime_type
146 147 148 |
# File 'actionpack/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 |
- (Object) render(view, locals, &block)
124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 |
# File 'actionpack/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 |
- (Object) variable_name
150 151 152 |
# File 'actionpack/lib/action_view/template.rb', line 150 def variable_name @variable_name ||= @virtual_path[%r'_?(\w+)(\.\w+)*$', 1].to_sym end |