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



5
6
7
8
9
10
11
12
13
14
15
16
# File 'lib/zafu/handler.rb', line 5

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



18
19
20
21
22
23
24
# File 'lib/zafu/handler.rb', line 18

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