Class: Zafu::Handler

Inherits:
ActionView::TemplateHandler
  • Object
show all
Includes:
ActionView::TemplateHandlers::Compilable
Defined in:
lib/zafu/handler.rb

Instance Method Summary collapse

Instance Method Details

#compile(template) ⇒ Object



10
11
12
13
14
15
16
17
18
19
20
21
# File 'lib/zafu/handler.rb', line 10

def compile(template)
  @template = template
  helper   = Thread.current[:view]
  if !helper.respond_to?(:zafu_context)
    raise Exception.new("Please add \"include Zafu::ControllerMethods\" into your ApplicationController for zafu to work properly.")
  end
  ast = Zafu::Template.new(template, self)
  context = helper.zafu_context.merge(:helper => helper)
  context[:node] ||= get_zafu_node_from_view(helper)
  rb = ast.to_ruby('@output_buffer', context)
  ";@erb = %q{#{ast.to_erb(context)}};#{rb}"
end

#get_template_text(path, base_path) ⇒ Object



23
24
25
26
27
28
29
# File 'lib/zafu/handler.rb', line 23

def get_template_text(path, base_path)
  if path == @template.path && base_path.nil?
    [@template.source, @template.path, @template.base_path]
  else
    Thread.current[:view].get_template_text(path, base_path)
  end
end