Class: Reactive::Mvc::View::Template
- Inherits:
-
Object
- Object
- Reactive::Mvc::View::Template
show all
- Extended by:
- ActiveSupport::Memoizable, TemplateHandlers
- Includes:
- Renderable
- Defined in:
- lib/reactive-mvc/view/template.rb
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.
11
12
13
14
15
16
17
18
19
|
# File 'lib/reactive-mvc/view/template.rb', line 11
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.
8
9
10
|
# File 'lib/reactive-mvc/view/template.rb', line 8
def base_path
@base_path
end
|
#extension ⇒ Object
Returns the value of attribute extension.
8
9
10
|
# File 'lib/reactive-mvc/view/template.rb', line 8
def extension
@extension
end
|
#filename ⇒ Object
Returns the value of attribute filename.
8
9
10
|
# File 'lib/reactive-mvc/view/template.rb', line 8
def filename
@filename
end
|
Returns the value of attribute format.
8
9
10
|
# File 'lib/reactive-mvc/view/template.rb', line 8
def format
@format
end
|
#load_path ⇒ Object
Returns the value of attribute load_path.
8
9
10
|
# File 'lib/reactive-mvc/view/template.rb', line 8
def load_path
@load_path
end
|
#name ⇒ Object
Returns the value of attribute name.
8
9
10
|
# File 'lib/reactive-mvc/view/template.rb', line 8
def name
@name
end
|
Instance Method Details
#content_type ⇒ Object
30
31
32
|
# File 'lib/reactive-mvc/view/template.rb', line 30
def content_type
format.gsub('.', '/')
end
|
21
22
23
|
# File 'lib/reactive-mvc/view/template.rb', line 21
def format_and_extension
(extensions = [format, extension].compact.join(".")).blank? ? nil : extensions
end
|
#method_segment ⇒ Object
60
61
62
|
# File 'lib/reactive-mvc/view/template.rb', line 60
def method_segment
relative_path.to_s.gsub(/([^a-zA-Z0-9_])/) { $1.ord }
end
|
#multipart? ⇒ Boolean
26
27
28
|
# File 'lib/reactive-mvc/view/template.rb', line 26
def multipart?
format && format.include?('.')
end
|
#path ⇒ Object
34
35
36
|
# File 'lib/reactive-mvc/view/template.rb', line 34
def path
[base_path, [name, format, extension].compact.join('.')].compact.join('/')
end
|
#path_without_extension ⇒ Object
39
40
41
|
# File 'lib/reactive-mvc/view/template.rb', line 39
def path_without_extension
[base_path, [name, format].compact.join('.')].compact.join('/')
end
|
44
45
46
|
# File 'lib/reactive-mvc/view/template.rb', line 44
def path_without_format_and_extension
[base_path, name].compact.join('/')
end
|
#relative_path ⇒ Object
49
50
51
52
|
# File 'lib/reactive-mvc/view/template.rb', line 49
def relative_path
path = File.expand_path(filename)
path.sub(/^#{Regexp.escape(Reactive.configuration.root_dir)}\//, '')
end
|
#render_template(view, local_assigns = {}) ⇒ Object
65
66
67
68
69
70
71
72
73
74
75
|
# File 'lib/reactive-mvc/view/template.rb', line 65
def render_template(view, local_assigns = {})
render(view, local_assigns)
rescue Exception => e
raise e unless filename
if TemplateError === e
e.sub_template_of(relative_path)
raise e
else
raise TemplateError.new(relative_path, source, e)
end
end
|
#source ⇒ Object
55
56
57
|
# File 'lib/reactive-mvc/view/template.rb', line 55
def source
File.read(filename)
end
|