Class: Frender::TemplateWrapper

Inherits:
Object
  • Object
show all
Includes:
Methadone::CLILogging
Defined in:
lib/frender/template_wrapper.rb

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.render(options, scope, outfile = nil) ⇒ Object



5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
# File 'lib/frender/template_wrapper.rb', line 5

def self.render(options, scope, outfile=nil)
  if !File.exist?(options[:template]) && !File.readable?(options[:template])
    raise("Cannot render %s, template %s does not exist or is not readable" % [outfile, options[:template]])
  end

  content = TemplateWrapper.new.render_partial(options[:template], scope)

  if outfile
    info "Rendering file %s using template %s" % [outfile, options[:template]]
    File.open(outfile, "w") {|f| f.puts content}
  else
    info "Rendering using template %s" % options[:template]
  end

  content
end

Instance Method Details

#render_partial(template, scope) ⇒ Object



22
23
24
# File 'lib/frender/template_wrapper.rb', line 22

def render_partial(template, scope)
  Tilt.new(template, :trim => "-").render(TemplateWrapper.new, scope)
end