Class: ActionView::Template
Instance Attribute Summary collapse
Instance Method Summary
collapse
extended, handler_class_for_extension, register_default_template_handler, register_template_handler, template_handler_extensions
Methods included from Renderable
#compiled_source, #handler, included, #method_name, #render
Constructor Details
#initialize(template_path, load_paths = []) ⇒ Template
Returns a new instance of Template.
12
13
14
15
16
17
18
19
20
|
# File 'lib/action_view/template.rb', line 12
def initialize(template_path, load_paths = [])
template_path = template_path.dup
@base_path, @name, @format, @extension = split(template_path)
@base_path.to_s.gsub!(/\/$/, '') @load_path, @filename = find_full_path(template_path, load_paths)
extend RenderablePartial if @name =~ /^_/
end
|
Instance Attribute Details
#base_path ⇒ Object
Returns the value of attribute base_path.
9
10
11
|
# File 'lib/action_view/template.rb', line 9
def base_path
@base_path
end
|
#extension ⇒ Object
Returns the value of attribute extension.
9
10
11
|
# File 'lib/action_view/template.rb', line 9
def extension
@extension
end
|
Returns the value of attribute filename.
9
10
11
|
# File 'lib/action_view/template.rb', line 9
def filename
@filename
end
|
Returns the value of attribute format.
9
10
11
|
# File 'lib/action_view/template.rb', line 9
def format
@format
end
|
#load_path ⇒ Object
Returns the value of attribute load_path.
9
10
11
|
# File 'lib/action_view/template.rb', line 9
def load_path
@load_path
end
|
Returns the value of attribute name.
9
10
11
|
# File 'lib/action_view/template.rb', line 9
def name
@name
end
|
Instance Method Details
#content_type ⇒ Object
31
32
33
|
# File 'lib/action_view/template.rb', line 31
def content_type
format.gsub('.', '/')
end
|
22
23
24
|
# File 'lib/action_view/template.rb', line 22
def format_and_extension
(extensions = [format, extension].compact.join(".")).blank? ? nil : extensions
end
|
#method_segment ⇒ Object
67
68
69
|
# File 'lib/action_view/template.rb', line 67
def method_segment
relative_path.to_s.gsub(/([^a-zA-Z0-9_])/) { $1.ord }
end
|
#multipart? ⇒ Boolean
27
28
29
|
# File 'lib/action_view/template.rb', line 27
def multipart?
format && format.include?('.')
end
|
40
41
42
|
# File 'lib/action_view/template.rb', line 40
def path
[base_path, [name, format, extension].compact.join('.')].compact.join('/')
end
|
#path_without_extension ⇒ Object
45
46
47
|
# File 'lib/action_view/template.rb', line 45
def path_without_extension
[base_path, [name, format].compact.join('.')].compact.join('/')
end
|
50
51
52
|
# File 'lib/action_view/template.rb', line 50
def path_without_format_and_extension
[base_path, name].compact.join('/')
end
|
#relative_path ⇒ Object
55
56
57
58
59
|
# File 'lib/action_view/template.rb', line 55
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
72
73
74
75
76
77
78
79
80
81
82
|
# File 'lib/action_view/template.rb', line 72
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
|
62
63
64
|
# File 'lib/action_view/template.rb', line 62
def source
File.read(filename)
end
|