Class: Quarry::Markup::Macro

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

Overview

Macro

Direct Known Subclasses

After, Before

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(spec, code, lineno, ioc = {}) ⇒ Macro

Returns a new instance of Macro.



21
22
23
24
25
# File 'lib/quarry/markup/macro.rb', line 21

def initialize(spec, code, lineno, ioc={})
  @spec   = spec
  @code   = code.rstrip
  @lineno = lineno
end

Instance Attribute Details

#codeObject (readonly)

Returns the value of attribute code.



18
19
20
# File 'lib/quarry/markup/macro.rb', line 18

def code
  @code
end

#linenoObject (readonly)

Returns the value of attribute lineno.



19
20
21
# File 'lib/quarry/markup/macro.rb', line 19

def lineno
  @lineno
end

#specObject (readonly) Also known as: parent

def self.types

@types ||= []

end



17
18
19
# File 'lib/quarry/markup/macro.rb', line 17

def spec
  @spec
end

Instance Method Details

#run(runner, spec, context, output) ⇒ Object

Run macro.



30
31
32
33
# File 'lib/quarry/markup/macro.rb', line 30

def run(runner, spec, context, output)
  context.instance_eval(code, spec.file, lineno)
  output.report_macro(self)
end

#tabObject



36
37
38
# File 'lib/quarry/markup/macro.rb', line 36

def tab
  @tab ||= to_s.index(/\S/)
end

#to_sObject



41
# File 'lib/quarry/markup/macro.rb', line 41

def to_s ; code ; end

#to_scriptObject

As could appear in stand-alone script.



44
45
46
# File 'lib/quarry/markup/macro.rb', line 44

def to_script
  code.to_s
end