Class: Lotus::View::Template

Inherits:
Object
  • Object
show all
Defined in:
lib/lotus/view/template.rb

Overview

A logic-less template.

Since:

  • 0.1.0

Direct Known Subclasses

Rendering::Partial

Instance Method Summary collapse

Constructor Details

#initialize(template, encoding = Encoding::UTF_8) ⇒ Template

Returns a new instance of Template.

Since:

  • 0.1.0



9
10
11
# File 'lib/lotus/view/template.rb', line 9

def initialize(template, encoding = Encoding::UTF_8)
  @_template = Tilt.new(template, nil, default_encoding: encoding)
end

Instance Method Details

#formatSymbol

Returns the format that the template handles.

Examples:

require 'lotus/view'

template = Lotus::View::Template.new('index.html.erb')
template.format # => :html

Returns:

  • (Symbol)

    the format name

Since:

  • 0.1.0



24
25
26
# File 'lib/lotus/view/template.rb', line 24

def format
  @_template.basename.match(/\.([^.]+)/).captures.first.to_sym
end

#render(scope, &blk) ⇒ String

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Render the template within the context of the given scope.

Parameters:

  • scope (Lotus::View::Scope)

    the rendering scope

Returns:

  • (String)

    the output of the rendering process

See Also:

  • Scope

Since:

  • 0.1.0



38
39
40
# File 'lib/lotus/view/template.rb', line 38

def render(scope, &blk)
  @_template.render(scope, {}, &blk)
end