Class: Preprocessor::BasicPreprocessor

Inherits:
Object
  • Object
show all
Includes:
Audio, Footnote, Image, Utilities, Video
Defined in:
lib/preprocessor.rb

Constant Summary collapse

TAG_REGEX =
/(.)?\{\{(\S+?)(?:\s+(.*?))?\}\}/
REPLACEMENT_REGEX =
/\{-\{-(.*?)-\}-\}/

Constants included from Video

Video::CUSTOM_EMBEDDERS

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Footnote

#footnote, #footnotes, included

Methods included from Video

#video

Methods included from Audio

#audio

Methods included from Image

#image

Methods included from Utilities

#absolute?, #absolutize

Constructor Details

#initialize(delegate) ⇒ BasicPreprocessor

Returns a new instance of BasicPreprocessor.



28
29
30
# File 'lib/preprocessor.rb', line 28

def initialize(delegate)
  self.delegate = delegate
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(sym, *args) ⇒ Object



32
33
34
35
36
37
38
39
40
41
# File 'lib/preprocessor.rb', line 32

def method_missing(sym, *args)
  text = delegate.send(sym, *args)

  while text.match(TAG_REGEX)
    text.sub!(TAG_REGEX, replacement_for($2, $3, $1 || ''))
  end

  text.gsub!(REPLACEMENT_REGEX, '{{\1}}')
  text
end

Instance Attribute Details

#delegateObject

Returns the value of attribute delegate.



17
18
19
# File 'lib/preprocessor.rb', line 17

def delegate
  @delegate
end