Class: Poirot::View
- Inherits:
-
Mustache
- Object
- Mustache
- Poirot::View
show all
- Defined in:
- lib/poirot/view.rb
Class Method Summary
collapse
Instance Method Summary
collapse
Constructor Details
#initialize(view_context, template_source) ⇒ View
Returns a new instance of View.
4
5
6
7
8
9
|
# File 'lib/poirot/view.rb', line 4
def initialize(view_context, template_source)
@view_context = view_context
@params = view_context.params || {}
self.template = template_source
assign_variables!
end
|
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(method_name, *args, &block) ⇒ Object
42
43
44
45
46
47
48
|
# File 'lib/poirot/view.rb', line 42
def method_missing(method_name, *args, &block)
if instance_variable_names.include?("@#{method_name}") && args.empty?
instance_variable_get("@#{method_name}")
else
view_context.send(method_name,*args, &block)
end
end
|
Class Method Details
.inherited(view_class) ⇒ Object
13
14
15
|
# File 'lib/poirot/view.rb', line 13
def self.inherited(view_class)
self.template_path = Rails.root.join('app', 'views', view_class.name.split('::').first.downcase)
end
|
Instance Method Details
#include_partial(name) ⇒ Object
29
30
31
32
33
34
35
36
37
38
39
40
|
# File 'lib/poirot/view.rb', line 29
def include_partial(name)
path = ["app/views", controller_name]
path += name.split("/")
path.delete(nil)
path.last.replace("_#{path.last}.html.mustache")
filename = path.join("/")
Dir.chdir(Rails.root) do
render_buffer(File.read(filename))
end
end
|
#render_buffer(buffer) ⇒ Object
25
26
27
|
# File 'lib/poirot/view.rb', line 25
def render_buffer(buffer)
self.render(buffer, context).html_safe
end
|
#respond_to?(method_sym, include_private = false) ⇒ Boolean
17
18
19
20
21
22
23
|
# File 'lib/poirot/view.rb', line 17
def respond_to?(method_sym, include_private = false)
if view_context.respond_to?(method_sym)
true
else
super
end
end
|