Module: Amp::KernelMethods

Defined in:
lib/amp-core/templates/template.rb

Instance Method Summary collapse

Instance Method Details

#template(name, type, text) ⇒ Object #template(name, text) ⇒ Object

Overloads:

  • #template(name, type, text) ⇒ Object

    Shortcut Kernel-level method for adding templates quickly. A nice method for ampfiles.

    Parameters:

    • name (String)

      the name of the template

    • type (Symbol)

      the template engine to use (such as :haml, :erb)

    • text (String)

      the text of the template

  • #template(name, text) ⇒ Object

    Shortcut Kernel-level method for adding ERb templates quickly. A nice method for ampfiles.

    Parameters:

    • name (String)

      the name of the template

    • text (String)

      the text of the template. Expected to be in ERb format.



193
194
195
196
197
198
199
200
# File 'lib/amp-core/templates/template.rb', line 193

def template(name, *args)
  if args.size > 2 || args.empty?
    raise ArgumentError.new('Usage of template: template(name, text)'+
                            'or template(name, renderer, text)')
  end
  template = (args.size > 1) ? args[0] : :erb
  Support::Template.new(:all, name, template, args.last)
end