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 | |
[W] | 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 actionpack/lib/action_view/template.rb, line 104 104: def self.exempt_from_layout(*extensions) 105: regexps = extensions.collect do |extension| 106: extension.is_a?(Regexp) ? extension : /\.#{Regexp.escape(extension.to_s)}$/ 107: end 108: @@exempt_from_layout.merge(regexps) 109: end
[ show source ]
# File actionpack/lib/action_view/template.rb, line 116 116: def initialize(template_path, load_path = nil) 117: @template_path, @load_path = template_path.dup, load_path 118: @base_path, @name, @locale, @format, @extension = split(template_path) 119: @base_path.to_s.gsub!(/\/$/, '') # Push to split method 120: 121: # Extend with partial super powers 122: extend RenderablePartial if @name =~ /^_/ 123: end
Public Instance methods
[ show source ]
# File actionpack/lib/action_view/template.rb, line 125 125: def accessible_paths 126: paths = [] 127: 128: if valid_extension?(extension) 129: paths << path 130: paths << path_without_extension 131: if multipart? 132: formats = format.split(".") 133: paths << "#{path_without_format_and_extension}.#{formats.first}" 134: paths << "#{path_without_format_and_extension}.#{formats.second}" 135: end 136: else 137: # template without explicit template handler should only be reachable through its exact path 138: paths << template_path 139: end 140: 141: paths 142: end
[ show source ]
# File actionpack/lib/action_view/template.rb, line 153 153: def content_type 154: format.gsub('.', '/') 155: end
[ show source ]
# File actionpack/lib/action_view/template.rb, line 184 184: def exempt_from_layout? 185: @@exempt_from_layout.any? { |exempted| path =~ exempted } 186: end
[ show source ]
# File actionpack/lib/action_view/template.rb, line 188 188: def filename 189: # no load_path means this is an "absolute pathed" template 190: load_path ? File.join(load_path, template_path) : template_path 191: end
[ show source ]
# File actionpack/lib/action_view/template.rb, line 144 144: def format_and_extension 145: (extensions = [format, extension].compact.join(".")).blank? ? nil : extensions 146: end
[ show source ]
# File actionpack/lib/action_view/template.rb, line 216 216: def load! 217: freeze 218: end
[ show source ]
# File actionpack/lib/action_view/template.rb, line 199 199: def method_segment 200: relative_path.to_s.gsub(/([^a-zA-Z0-9_])/) { $1.ord } 201: end
[ show source ]
# File actionpack/lib/action_view/template.rb, line 157 157: def mime_type 158: Mime::Type.lookup_by_extension(format) if format && defined?(::Mime) 159: end
[ show source ]
# File actionpack/lib/action_view/template.rb, line 149 149: def multipart? 150: format && format.include?('.') 151: end
[ show source ]
# File actionpack/lib/action_view/template.rb, line 162 162: def path 163: [base_path, [name, locale, format, extension].compact.join('.')].compact.join('/') 164: end
[ show source ]
# File actionpack/lib/action_view/template.rb, line 167 167: def path_without_extension 168: [base_path, [name, locale, format].compact.join('.')].compact.join('/') 169: end
[ show source ]
# File actionpack/lib/action_view/template.rb, line 172 172: def path_without_format_and_extension 173: [base_path, [name, locale].compact.join('.')].compact.join('/') 174: end
[ show source ]
# File actionpack/lib/action_view/template.rb, line 177 177: def relative_path 178: path = File.expand_path(filename) 179: path.sub!(/^#{Regexp.escape(File.expand_path(RAILS_ROOT))}\//, '') if defined?(RAILS_ROOT) 180: path 181: end
[ show source ]
# File actionpack/lib/action_view/template.rb, line 204 204: def render_template(view, local_assigns = {}) 205: render(view, local_assigns) 206: rescue Exception => e 207: raise e unless filename 208: if TemplateError === e 209: e.sub_template_of(self) 210: raise e 211: else 212: raise TemplateError.new(self, view.assigns, e) 213: end 214: end
[ show source ]
# File actionpack/lib/action_view/template.rb, line 194 194: def source 195: File.read(filename) 196: end