Class: Ramaze::Template::Markaby

Inherits:
Template show all
Includes:
Helper::Methods
Defined in:
lib/ramaze/template/markaby.rb

Overview

Is responsible for compiling a template using the Markaby templating engine. Can be found at: code.whytheluckystiff.net/markaby/

Class Method Summary collapse

Methods included from Helper::Methods

extend_object, #helper, included

Methods inherited from Template

caching_compile, reaction_or_file, render_method, result_and_file, wrap_compile

Class Method Details

.extract_ivs(controller) ⇒ Object

Generate a hash from instance-variables



43
44
45
46
47
48
# File 'lib/ramaze/template/markaby.rb', line 43

def extract_ivs(controller)
  controller.instance_variables.inject({}) do |hash, iv|
    sym = iv.gsub('@', '').to_sym
    hash.merge! sym => controller.instance_variable_get(iv)
  end
end

.transform(action) ⇒ Object

Entry point for Action#render



21
22
23
24
25
26
# File 'lib/ramaze/template/markaby.rb', line 21

def transform action
  result, file = result_and_file(action)

  result = transform_string(file, action) if file
  result.to_s
end

.transform_string(string, action) ⇒ Object

Takes a string and action, instance_evals the string inside a mab block that gets the instance_variables of the original action.instance passed.



32
33
34
35
36
37
38
39
# File 'lib/ramaze/template/markaby.rb', line 32

def transform_string string, action
  instance = action.instance
  ivs = extract_ivs(instance)

  instance.send(:mab, ivs) do
    instance_eval(string)
  end
end