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) ⇒ 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)
  @_template = Tilt.new(template)
end

Instance Method Details

#formatString

Returns the format that the template handles.

Examples:

require 'lotus/view'

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

Returns:

  • (String)

    the format name

Since:

  • 0.1.0



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

def format
  @_template.basename.match(/(\.[^.]+)/).to_s.
    gsub('.', ''). # TODO shame on me, this should be part of the regex above
    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



40
41
42
# File 'lib/lotus/view/template.rb', line 40

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