Class: ActionView::Template
Defined Under Namespace
Classes: EagerPath, Path
Constant Summary
collapse
- @@exempt_from_layout =
Templates that are exempt from layouts
Set.new([/\.rjs$/])
Instance Attribute Summary collapse
Class Method Summary
collapse
Instance Method Summary
collapse
extended, handler_class_for_extension, register_default_template_handler, register_template_handler, registered_template_handler, template_handler_extensions
Methods included from Renderable
#compiled_source, #handler, #method_name, #method_name_without_locals, #render, #render_without_template_tracking
Constructor Details
#initialize(template_path, load_path = nil) ⇒ Template
Returns a new instance of Template.
116
117
118
119
120
121
122
123
|
# File 'lib/action_view/template.rb', line 116
def initialize(template_path, load_path = nil)
@template_path, @load_path = template_path.dup, load_path
@base_path, @name, @locale, @format, @extension = split(template_path)
@base_path.to_s.gsub!(/\/$/, '')
extend RenderablePartial if @name =~ /^_/
end
|
Instance Attribute Details
#base_path ⇒ Object
Returns the value of attribute base_path.
111
112
113
|
# File 'lib/action_view/template.rb', line 111
def base_path
@base_path
end
|
#extension ⇒ Object
Returns the value of attribute extension.
112
113
114
|
# File 'lib/action_view/template.rb', line 112
def extension
@extension
end
|
188
189
190
191
|
# File 'lib/action_view/template.rb', line 188
def filename
load_path ? File.join(load_path, template_path) : template_path
end
|
Returns the value of attribute format.
112
113
114
|
# File 'lib/action_view/template.rb', line 112
def format
@format
end
|
#load_path ⇒ Object
Returns the value of attribute load_path.
111
112
113
|
# File 'lib/action_view/template.rb', line 111
def load_path
@load_path
end
|
Returns the value of attribute locale.
112
113
114
|
# File 'lib/action_view/template.rb', line 112
def locale
@locale
end
|
Returns the value of attribute name.
112
113
114
|
# File 'lib/action_view/template.rb', line 112
def name
@name
end
|
#template_path ⇒ Object
Returns the value of attribute template_path.
111
112
113
|
# File 'lib/action_view/template.rb', line 111
def template_path
@template_path
end
|
Class Method Details
.exempt_from_layout(*extensions) ⇒ Object
Don’t render layouts for templates with the given extensions.
104
105
106
107
108
109
|
# File 'lib/action_view/template.rb', line 104
def self.exempt_from_layout(*extensions)
regexps = extensions.collect do |extension|
extension.is_a?(Regexp) ? extension : /\.#{Regexp.escape(extension.to_s)}$/
end
@@exempt_from_layout.merge(regexps)
end
|
Instance Method Details
#accessible_paths ⇒ Object
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
|
# File 'lib/action_view/template.rb', line 125
def accessible_paths
paths = []
if valid_extension?(extension)
paths << path
paths << path_without_extension
if multipart?
formats = format.split(".")
paths << "#{path_without_format_and_extension}.#{formats.first}"
paths << "#{path_without_format_and_extension}.#{formats.second}"
end
else
paths << template_path
end
paths
end
|
#content_type ⇒ Object
153
154
155
|
# File 'lib/action_view/template.rb', line 153
def content_type
format.gsub('.', '/')
end
|
#exempt_from_layout? ⇒ Boolean
184
185
186
|
# File 'lib/action_view/template.rb', line 184
def exempt_from_layout?
@@exempt_from_layout.any? { |exempted| path =~ exempted }
end
|
144
145
146
|
# File 'lib/action_view/template.rb', line 144
def format_and_extension
(extensions = [format, extension].compact.join(".")).blank? ? nil : extensions
end
|
216
217
218
|
# File 'lib/action_view/template.rb', line 216
def load!
freeze
end
|
#method_segment ⇒ Object
199
200
201
|
# File 'lib/action_view/template.rb', line 199
def method_segment
relative_path.to_s.gsub(/([^a-zA-Z0-9_])/) { $1.ord }
end
|
#multipart? ⇒ Boolean
149
150
151
|
# File 'lib/action_view/template.rb', line 149
def multipart?
format && format.include?('.')
end
|
162
163
164
|
# File 'lib/action_view/template.rb', line 162
def path
[base_path, [name, locale, format, extension].compact.join('.')].compact.join('/')
end
|
#path_without_extension ⇒ Object
167
168
169
|
# File 'lib/action_view/template.rb', line 167
def path_without_extension
[base_path, [name, locale, format].compact.join('.')].compact.join('/')
end
|
172
173
174
|
# File 'lib/action_view/template.rb', line 172
def path_without_format_and_extension
[base_path, [name, locale].compact.join('.')].compact.join('/')
end
|
#relative_path ⇒ Object
177
178
179
180
181
|
# File 'lib/action_view/template.rb', line 177
def relative_path
path = File.expand_path(filename)
path.sub!(/^#{Regexp.escape(File.expand_path(RAILS_ROOT))}\//, '') if defined?(RAILS_ROOT)
path
end
|
#render_template(view, local_assigns = {}) ⇒ Object
204
205
206
207
208
209
210
211
212
213
214
|
# File 'lib/action_view/template.rb', line 204
def render_template(view, local_assigns = {})
render(view, local_assigns)
rescue Exception => e
raise e unless filename
if TemplateError === e
e.sub_template_of(self)
raise e
else
raise TemplateError.new(self, view.assigns, e)
end
end
|
194
195
196
|
# File 'lib/action_view/template.rb', line 194
def source
File.read(filename)
end
|