Class: NoraMark::Transformer

Inherits:
Object
  • Object
show all
Includes:
NodeUtil
Defined in:
lib/nora_mark/transformer.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from NodeUtil

#_node, #block, #inline, #text

Constructor Details

#initialize(rules, options) ⇒ Transformer

Returns a new instance of Transformer.



5
6
7
8
# File 'lib/nora_mark/transformer.rb', line 5

def initialize(rules, options)
  @rules = rules
  @options = options
end

Instance Attribute Details

#optionsObject

Returns the value of attribute options.



4
5
6
# File 'lib/nora_mark/transformer.rb', line 4

def options
  @options
end

Instance Method Details

#modify(&block) ⇒ Object



23
24
25
# File 'lib/nora_mark/transformer.rb', line 23

def modify(&block)
  instance_eval(&block)
end

#replace(&block) ⇒ Object



27
28
29
30
# File 'lib/nora_mark/transformer.rb', line 27

def replace(&block)
  new_node = instance_eval(&block)
  @node.replace new_node if new_node
end

#transform(node) ⇒ Object



10
11
12
13
14
15
16
17
18
19
20
21
# File 'lib/nora_mark/transformer.rb', line 10

def transform(node)
  frontmatter_node = node.find_node :type => :Frontmatter
  @frontmatter = frontmatter_node.yaml if frontmatter_node
  node.all_nodes.unshift(node).each do |n|
    if (match_rule = @rules.find { |rule| n.match?(rule[0]) })
      action, p = match_rule[1, 2]
      @node = n
      send(action, &p)
    end
  end
  node
end