Class: Flatrack::Template

Inherits:
Object
  • Object
show all
Defined in:
lib/flatrack/template.rb,
lib/flatrack/template/rb.rb,
lib/flatrack/template/html.rb,
lib/flatrack/template/erubis.rb,
lib/flatrack/template/erubis/handler.rb

Overview

The default template parser/finder

Defined Under Namespace

Classes: Erubis, Html, Rb

Constant Summary collapse

DEFAULT_FORMAT =
'html'

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(base_path, type, format, file) ⇒ Template

Creates a new template instance

Parameters:

  • type (Symbol)

    the type of template

  • format (String)

    the format e.g. html

  • file (String)

    the location of the file



34
35
36
37
38
39
# File 'lib/flatrack/template.rb', line 34

def initialize(base_path, type, format, file)
  @base_path   = base_path
  @format      = format || DEFAULT_FORMAT
  @type, @file = type, file.to_s
  @renderer    = find
end

Instance Attribute Details

#base_pathObject (readonly)

Returns the value of attribute base_path.



12
13
14
# File 'lib/flatrack/template.rb', line 12

def base_path
  @base_path
end

#fileObject (readonly)

Returns the value of attribute file.



12
13
14
# File 'lib/flatrack/template.rb', line 12

def file
  @file
end

#formatObject (readonly)

Returns the value of attribute format.



12
13
14
# File 'lib/flatrack/template.rb', line 12

def format
  @format
end

#typeObject (readonly)

Returns the value of attribute type.



12
13
14
# File 'lib/flatrack/template.rb', line 12

def type
  @type
end

Class Method Details

.find(base_path, type, format, file) ⇒ Object

Creates a new template instance and invokes find

Parameters:

  • type (Symbol)

    the type of template

  • format (String)

    the format e.g. html

  • file (String)

    the location of the file



26
27
28
# File 'lib/flatrack/template.rb', line 26

def self.find(base_path, type, format, file)
  new(base_path, type, format, file)
end

.register_path(path) ⇒ Object



15
16
17
18
19
20
# File 'lib/flatrack/template.rb', line 15

def self.register_path(path)
  classes.each do |klass|
    files = Dir.glob File.join path, '**', "*.#{klass::RENDERS}"
    Tilt.register klass, *files
  end
end