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) ⇒ Template
Returns a new instance of Template.
110
111
112
113
114
115
116
117
118
|
# File 'lib/action_view/template.rb', line 110
def initialize(template_path, load_path)
@template_path = template_path.dup
@load_path, @filename = load_path, File.join(load_path, template_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.
106
107
108
|
# File 'lib/action_view/template.rb', line 106
def base_path
@base_path
end
|
#extension ⇒ Object
Returns the value of attribute extension.
107
108
109
|
# File 'lib/action_view/template.rb', line 107
def extension
@extension
end
|
Returns the value of attribute filename.
106
107
108
|
# File 'lib/action_view/template.rb', line 106
def filename
@filename
end
|
Returns the value of attribute format.
107
108
109
|
# File 'lib/action_view/template.rb', line 107
def format
@format
end
|
#load_path ⇒ Object
Returns the value of attribute load_path.
106
107
108
|
# File 'lib/action_view/template.rb', line 106
def load_path
@load_path
end
|
Returns the value of attribute locale.
107
108
109
|
# File 'lib/action_view/template.rb', line 107
def locale
@locale
end
|
Returns the value of attribute name.
107
108
109
|
# File 'lib/action_view/template.rb', line 107
def name
@name
end
|
#template_path ⇒ Object
Returns the value of attribute template_path.
106
107
108
|
# File 'lib/action_view/template.rb', line 106
def template_path
@template_path
end
|
Class Method Details
.exempt_from_layout(*extensions) ⇒ Object
Don’t render layouts for templates with the given extensions.
99
100
101
102
103
104
|
# File 'lib/action_view/template.rb', line 99
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
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
|
# File 'lib/action_view/template.rb', line 120
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
148
149
150
|
# File 'lib/action_view/template.rb', line 148
def content_type
format.gsub('.', '/')
end
|
#exempt_from_layout? ⇒ Boolean
179
180
181
|
# File 'lib/action_view/template.rb', line 179
def exempt_from_layout?
@@exempt_from_layout.any? { |exempted| path =~ exempted }
end
|
139
140
141
|
# File 'lib/action_view/template.rb', line 139
def format_and_extension
(extensions = [format, extension].compact.join(".")).blank? ? nil : extensions
end
|
205
206
207
|
# File 'lib/action_view/template.rb', line 205
def load!
freeze
end
|
#method_segment ⇒ Object
188
189
190
|
# File 'lib/action_view/template.rb', line 188
def method_segment
relative_path.to_s.gsub(/([^a-zA-Z0-9_])/) { $1.ord }
end
|
#multipart? ⇒ Boolean
144
145
146
|
# File 'lib/action_view/template.rb', line 144
def multipart?
format && format.include?('.')
end
|
157
158
159
|
# File 'lib/action_view/template.rb', line 157
def path
[base_path, [name, locale, format, extension].compact.join('.')].compact.join('/')
end
|
#path_without_extension ⇒ Object
162
163
164
|
# File 'lib/action_view/template.rb', line 162
def path_without_extension
[base_path, [name, locale, format].compact.join('.')].compact.join('/')
end
|
167
168
169
|
# File 'lib/action_view/template.rb', line 167
def path_without_format_and_extension
[base_path, [name, locale].compact.join('.')].compact.join('/')
end
|
#relative_path ⇒ Object
172
173
174
175
176
|
# File 'lib/action_view/template.rb', line 172
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
193
194
195
196
197
198
199
200
201
202
203
|
# File 'lib/action_view/template.rb', line 193
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
|
183
184
185
|
# File 'lib/action_view/template.rb', line 183
def source
File.read(filename)
end
|