Class: Feet::View

Inherits:
Object show all
Defined in:
lib/feet/view.rb

Instance Method Summary collapse

Constructor Details

#initialize(template, instance_hash) ⇒ View

Returns a new instance of View.



5
6
7
8
# File 'lib/feet/view.rb', line 5

def initialize(template, instance_hash)
  @template = template
  init_vars(instance_hash)
end

Instance Method Details

#callObject



10
11
12
13
14
# File 'lib/feet/view.rb', line 10

def call
  eruby = Erubis::Eruby.new(@template)
  # Locals here are in addition to instance variables, if any
  eval eruby.src
end

#h(str) ⇒ Object

Helper method for View



24
25
26
# File 'lib/feet/view.rb', line 24

def h(str)
  URI.escape str
end

#init_vars(received_vars) ⇒ Object



16
17
18
19
20
21
# File 'lib/feet/view.rb', line 16

def init_vars(received_vars)
  received_vars.each do |key, value|
    # key example = '@quote'
    instance_variable_set(key, value)
  end
end