Class: Hanami::View::Template

Inherits:
Object
  • Object
show all
Defined in:
gems/gems/hanami-view-1.3.3/lib/hanami/view/template.rb

Overview

A logic-less template.

Since:

  • 0.1.0

Instance Method Summary collapse

Constructor Details

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

Returns a new instance of Template

Since:

  • 0.1.0

def initialize(template, encoding = Encoding::UTF_8)
  options = { default_encoding: encoding }

  if slim?(template)
    # NOTE disable_escape: true is for Slim compatibility
    # See https://github.com/hanami/assets/issues/36
    options[:disable_escape] = true
  end

  @_template = Tilt.new(template, nil, options)
end

Instance Method Details

#formatSymbol

Returns the format that the template handles.

Examples:

require 'hanami/view'

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

Returns:

  • (Symbol)

    the format name

Since:

  • 0.1.0

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

#slim?(template) ⇒ Boolean (private)

Returns:

Since:

  • 0.1.0

def slim?(template)
  File.extname(template) == ".slim".freeze
end