Class: Malt::Engine::Abstract

Inherits:
Object
  • Object
show all
Includes:
Kernel
Defined in:
lib/malt/engines/abstract.rb

Overview

Abstract Template class serves as the base class for all other Template classes.

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(settings = {}) ⇒ Abstract

Returns a new instance of Abstract


55
56
57
58
59
60
61
62
# File 'lib/malt/engines/abstract.rb', line 55

def initialize(settings={})
  @settings = settings.rekey

  @cache  = {}
  @source = {}

  require_engine
end

Instance Attribute Details

#settingsObject (readonly)

Access to the options given to the initializer.


65
66
67
# File 'lib/malt/engines/abstract.rb', line 65

def settings
  @settings
end

Class Method Details

.default(*exts) ⇒ Object

Register and set as the default for given extensions.


42
43
44
45
46
47
# File 'lib/malt/engines/abstract.rb', line 42

def self.default(*exts)
  register(*exts)
  exts.each do |ext|
    Engine.defaults[ext.to_sym] = self
  end
end

.register(*exts) ⇒ Object

Register the class to an extension type.


37
38
39
# File 'lib/malt/engines/abstract.rb', line 37

def self.register(*exts)
  Engine.register(self, *exts)
end

.typeObject


50
51
52
# File 'lib/malt/engines/abstract.rb', line 50

def self.type
  basename.downcase.to_sym
end

Instance Method Details

#cache?Boolean

Returns:

  • (Boolean)

68
69
70
# File 'lib/malt/engines/abstract.rb', line 68

def cache?
  !settings[:nocache]
end

#create_engine(params = {}) ⇒ Object

Instantiate engine class with engine options and template text, if possible.

The initialization MUST never include template data and should support caching, if feasible.

Raises:

  • (NotImplementedError)

92
93
94
# File 'lib/malt/engines/abstract.rb', line 92

def create_engine(params={})
  raise NotImplementedError, "not implemented"
end

#prepare_engine(params = {}, &content) ⇒ Object

Prepare engine for rendering.


82
83
84
# File 'lib/malt/engines/abstract.rb', line 82

def prepare_engine(params={}, &content)
  create_engine(params, &content)
end

#render(params, &block) ⇒ Object


73
74
75
76
77
78
79
# File 'lib/malt/engines/abstract.rb', line 73

def render(params, &block)
  if into = params[:to]
    raise NotImplementedError, "unsupported rendering -- #{into}"
  else
    raise NotImplementedError, "unsupported rendering"
  end
end