Methods
- accessible_paths
- content_type
- exempt_from_layout
- exempt_from_layout?
- filename
- format_and_extension
- load!
- method_segment
- mime_type
- multipart?
- new
- path
- path_without_extension
- path_without_format_and_extension
- relative_path
- render_template
- source
Included Modules
- Renderable
Classes and Modules
Class ActionView::Template::EagerPathClass ActionView::Template::Path
Attributes
| [RW] | base_path | |
| [RW] | extension | |
| [RW] | filename | |
| [RW] | format | |
| [RW] | load_path | |
| [RW] | locale | |
| [RW] | name | |
| [RW] | template_path |
Public Class methods
Don‘t render layouts for templates with the given extensions.
[ show source ]
# File vendor/rails/actionpack/lib/action_view/template.rb, line 99
99: def self.exempt_from_layout(*extensions)
100: regexps = extensions.collect do |extension|
101: extension.is_a?(Regexp) ? extension : /\.#{Regexp.escape(extension.to_s)}$/
102: end
103: @@exempt_from_layout.merge(regexps)
104: end
[ show source ]
# File vendor/rails/actionpack/lib/action_view/template.rb, line 110
110: def initialize(template_path, load_path = nil)
111: @template_path, @load_path = template_path.dup, load_path
112: @base_path, @name, @locale, @format, @extension = split(template_path)
113: @base_path.to_s.gsub!(/\/$/, '') # Push to split method
114:
115: # Extend with partial super powers
116: extend RenderablePartial if @name =~ /^_/
117: end
Public Instance methods
[ show source ]
# File vendor/rails/actionpack/lib/action_view/template.rb, line 119
119: def accessible_paths
120: paths = []
121:
122: if valid_extension?(extension)
123: paths << path
124: paths << path_without_extension
125: if multipart?
126: formats = format.split(".")
127: paths << "#{path_without_format_and_extension}.#{formats.first}"
128: paths << "#{path_without_format_and_extension}.#{formats.second}"
129: end
130: else
131: # template without explicit template handler should only be reachable through its exact path
132: paths << template_path
133: end
134:
135: paths
136: end
[ show source ]
# File vendor/rails/actionpack/lib/action_view/template.rb, line 147
147: def content_type
148: format.gsub('.', '/')
149: end
[ show source ]
# File vendor/rails/actionpack/lib/action_view/template.rb, line 178
178: def exempt_from_layout?
179: @@exempt_from_layout.any? { |exempted| path =~ exempted }
180: end
[ show source ]
# File vendor/rails/actionpack/lib/action_view/template.rb, line 182
182: def filename
183: # no load_path means this is an "absolute pathed" template
184: load_path ? File.join(load_path, template_path) : template_path
185: end
[ show source ]
# File vendor/rails/actionpack/lib/action_view/template.rb, line 138
138: def format_and_extension
139: (extensions = [format, extension].compact.join(".")).blank? ? nil : extensions
140: end
[ show source ]
# File vendor/rails/actionpack/lib/action_view/template.rb, line 210
210: def load!
211: freeze
212: end
[ show source ]
# File vendor/rails/actionpack/lib/action_view/template.rb, line 193
193: def method_segment
194: relative_path.to_s.gsub(/([^a-zA-Z0-9_])/) { $1.ord }
195: end
[ show source ]
# File vendor/rails/actionpack/lib/action_view/template.rb, line 151
151: def mime_type
152: Mime::Type.lookup_by_extension(format) if format && defined?(::Mime)
153: end
[ show source ]
# File vendor/rails/actionpack/lib/action_view/template.rb, line 143
143: def multipart?
144: format && format.include?('.')
145: end
[ show source ]
# File vendor/rails/actionpack/lib/action_view/template.rb, line 156
156: def path
157: [base_path, [name, locale, format, extension].compact.join('.')].compact.join('/')
158: end
[ show source ]
# File vendor/rails/actionpack/lib/action_view/template.rb, line 161
161: def path_without_extension
162: [base_path, [name, locale, format].compact.join('.')].compact.join('/')
163: end
[ show source ]
# File vendor/rails/actionpack/lib/action_view/template.rb, line 166
166: def path_without_format_and_extension
167: [base_path, [name, locale].compact.join('.')].compact.join('/')
168: end
[ show source ]
# File vendor/rails/actionpack/lib/action_view/template.rb, line 171
171: def relative_path
172: path = File.expand_path(filename)
173: path.sub!(/^#{Regexp.escape(File.expand_path(RAILS_ROOT))}\//, '') if defined?(RAILS_ROOT)
174: path
175: end
[ show source ]
# File vendor/rails/actionpack/lib/action_view/template.rb, line 198
198: def render_template(view, local_assigns = {})
199: render(view, local_assigns)
200: rescue Exception => e
201: raise e unless filename
202: if TemplateError === e
203: e.sub_template_of(self)
204: raise e
205: else
206: raise TemplateError.new(self, view.assigns, e)
207: end
208: end
[ show source ]
# File vendor/rails/actionpack/lib/action_view/template.rb, line 188
188: def source
189: File.read(filename)
190: end