Class: Malline::RailsHandler

Inherits:
ActionView::TemplateHandler
  • Object
show all
Includes:
ActionView::TemplateHandlers::Compilable
Defined in:
lib/malline/adapters/rails-2.1.rb

Overview

Malline template handler for Rails 2.1

We use Compilable-interface, even though Malline templates really doesn’t compile into anything, but at least template files won’t always be re-read from files. Builder templates (.builder|.rxml) also use this interface.

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.line_offsetObject

We have three lines framework code before real template code in ‘compiled code’



29
30
31
# File 'lib/malline/adapters/rails-2.1.rb', line 29

def self.line_offset
	3
end

Instance Method Details

#cache_fragment(block, name = {}, options = nil) ⇒ Object

Get the rendered fragment contents



45
46
47
48
49
# File 'lib/malline/adapters/rails-2.1.rb', line 45

def cache_fragment block, name = {}, options = nil
	@view.fragment_for(block, name, options) do
		eval("__malline_handler.rendered", block.binding)
	end
end

#compile(template) ⇒ Object

Compiles the template, i.e. return a runnable ruby code that initializes a new Malline::Base objects and renders the template.



35
36
37
38
39
40
41
42
# File 'lib/malline/adapters/rails-2.1.rb', line 35

def compile template
	path = template.path.gsub('\\', '\\\\\\').gsub("'", "\\\\'")
	"__malline_handler = Malline::Base.new self
	malline.path = '#{path}'
	__malline_handler.render do
		#{template.source}
	end"
end