Class: Marko::Markup::Macro

Inherits:
Object
  • Object
show all
Defined in:
lib/marko/markup/macro.rb

Overview

Base class for macro substitutions

Examples:

class Todo < Macro
  @pattern = /@@todo[^\n]*\n/
  def subs(sample, obj = nil)
    # code that returns <substitution>
    # for the sample parameter
  end
end

text = "bla-bla-bla @@todo foo\nbla-bla-bla"
Todo.new.gsub!(text)
# => "bla-bla-bla <substitution for @@todo foo>"

Direct Known Subclasses

MLink, MList, MSkip, MTodo, MTree

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.patternObject



28
29
30
# File 'lib/marko/markup/macro.rb', line 28

def self.pattern
  @pattern
end

Instance Method Details

#gsub!(text, obj = nil) ⇒ Object

substitutes all occured #pattern it text



38
39
40
41
# File 'lib/marko/markup/macro.rb', line 38

def gsub!(text, obj = nil)
  fn = subfn(text, obj)
  text.scan(pattern).each(&fn)
end

#patternRegexp

Returns pattern to process.

Returns:

  • (Regexp)

    pattern to process



33
34
35
# File 'lib/marko/markup/macro.rb', line 33

def pattern
  self.class.pattern
end