Class: Smartgen::Engine::Base

Inherits:
Object
  • Object
show all
Defined in:
lib/smartgen/engines/base.rb

Overview

Base class for engines.

An engine process markup files, converting them to HTML.

Direct Known Subclasses

ERB, Markdown, Textile

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeBase

Returns a new instance of Base.



12
13
14
15
16
17
# File 'lib/smartgen/engines/base.rb', line 12

def initialize
  self.pre_processors ||= []
  self.pre_processors.each do |pre_processor|
    pre_processor.engine = self if pre_processor.respond_to?(:engine=)
  end
end

Class Method Details

.inherited(base) ⇒ Object



41
42
43
# File 'lib/smartgen/engines/base.rb', line 41

def inherited(base)
  base.pre_processors = []
end

.register(processor) ⇒ Object

Registers a pre processor for this engine.



37
38
39
# File 'lib/smartgen/engines/base.rb', line 37

def register(processor)
  self.pre_processors += [processor]
end

Instance Method Details

#process(body, metadata = Smartgen::ObjectHash.new) ⇒ Object

Process a file, calling each pre processor if any.



20
21
22
# File 'lib/smartgen/engines/base.rb', line 20

def process(body, =Smartgen::ObjectHash.new)
  process_without_pre_processors(pre_process(body, ), )
end

#process_without_pre_processors(contents, metadata = Smartgen::ObjectHash.new) ⇒ Object



24
25
26
# File 'lib/smartgen/engines/base.rb', line 24

def process_without_pre_processors(contents, =Smartgen::ObjectHash.new)
  parse(contents, )
end

#supported?(extension) ⇒ Boolean

Returns true if the given extension is supported by this engine.

Returns:

  • (Boolean)


29
30
31
# File 'lib/smartgen/engines/base.rb', line 29

def supported?(extension)
  extensions.include?(extension)
end