Class: Mullet::Sinatra::Engine

Inherits:
Object
  • Object
show all
Defined in:
lib/mullet/sinatra/engine.rb

Overview

Loads view classes and template files.

Instance Method Summary collapse

Constructor Details

#initializeEngine

Returns a new instance of Engine.



8
9
10
11
# File 'lib/mullet/sinatra/engine.rb', line 8

def initialize()
  @class_cache = Hash.new()
  @loader = Mullet::HTML::TemplateLoader.new(nil)
end

Instance Method Details

#get_template(view_name, options) ⇒ Object

Gets template.

Parameters:

  • view_name (Symbol)

    view name

  • options (Hash)

    options

Returns:

  • template



20
21
22
23
24
# File 'lib/mullet/sinatra/engine.rb', line 20

def get_template(view_name, options)
  template_path = options[:template_path] || options[:views]
  @loader.template_path = template_path
  return @loader.load("#{view_name.to_s()}.html")
end

#get_view_class(view_name, options) ⇒ Object

Gets view class.

Parameters:

  • view_name (Symbol)

    view name

  • options (Hash)

    options

Returns:

  • view class



33
34
35
36
37
38
39
40
# File 'lib/mullet/sinatra/engine.rb', line 33

def get_view_class(view_name, options)
  view_class = @class_cache.fetch(view_name, nil)
  if view_class == nil
    view_class = find_class(view_name.to_s(), options)
    @class_cache.store(view_name, view_class)
  end
  return view_class
end