Class Haml::Template
In: lib/haml/template.rb
Parent: Object

This class interfaces with ActionView to make Haml usable as a Ruby on Rails plugin. It usually shouldn‘t need to be used by end users. Just in case, though, here‘s what you might do to render templates/index.haml:

  ActionView::Base.register_template_handler("haml", Haml::Template)
  base = ActionView::Base.new("templates")
  base.render("index")

Or, if you want to really get into the nitty-gritty:

  base = ActionView::Base.new
  template = Haml::Template.new(base)
  template.render("templates/index.haml")

Methods

new   options   options=   render  

Public Class methods

Creates a new Haml::Template object that uses view to render its templates.

[Source]

    # File lib/haml/template.rb, line 41
41:     def initialize(view)
42:       @view = view
43:     end

Gets various options for Haml. See README for details.

[Source]

    # File lib/haml/template.rb, line 29
29:       def options
30:         @@options
31:       end

Sets various options for Haml. See README for details.

[Source]

    # File lib/haml/template.rb, line 34
34:       def options=(value)
35:         @@options = value
36:       end

Public Instance methods

Renders the file at the location template, with local_assigns available as local variables within the template. Returns the result as a string.

[Source]

    # File lib/haml/template.rb, line 48
48:     def render(template, local_assigns={})
49:       @view.instance_eval do
50:         evaluate_assigns
51:       end
52: 
53:       options = @@options.dup
54:       locals = options[:locals] || {}
55:       locals.merge! local_assigns
56:       options[:locals] = locals
57: 
58:       if @view.haml_inline
59:         engine = Haml::Engine.new(template, options)
60:       else
61:         options[:filename] ||= template
62:         engine = Haml::Engine.new(File.read(template), options)
63:       end
64: 
65:       yield_proc = @view.instance_eval do
66:         proc { |*name| instance_variable_get("@content_for_#{name.first || 'layout'}") }
67:       end
68: 
69:       engine.to_html(@view) { |*args| yield_proc.call(*args) }
70: 
71:     end

[Validate]