Class: Poirot::View

Inherits:
Mustache
  • Object
show all
Includes:
ViewHelper
Defined in:
lib/poirot/view.rb

Class Method Summary collapse

Instance Method Summary collapse

Methods included from ViewHelper

#csrf_token

Constructor Details

#initialize(view_context, template_source) ⇒ View

Returns a new instance of View.



6
7
8
9
10
11
# File 'lib/poirot/view.rb', line 6

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



44
45
46
47
48
49
50
# File 'lib/poirot/view.rb', line 44

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



15
16
17
# File 'lib/poirot/view.rb', line 15

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



31
32
33
34
35
36
37
38
39
40
41
42
# File 'lib/poirot/view.rb', line 31

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



27
28
29
# File 'lib/poirot/view.rb', line 27

def render_buffer(buffer)
  self.render(buffer, context).html_safe
end

#respond_to?(method_sym, include_private = false) ⇒ Boolean

Returns:

  • (Boolean)


19
20
21
22
23
24
25
# File 'lib/poirot/view.rb', line 19

def respond_to?(method_sym, include_private = false)
  if view_context.respond_to?(method_sym)
    true
  else
    super
  end
end