Class: NoraMark::Transformer
- Inherits:
-
Object
- Object
- NoraMark::Transformer
- Includes:
- NodeUtil
- Defined in:
- lib/nora_mark/transformer.rb
Instance Attribute Summary collapse
-
#options ⇒ Object
Returns the value of attribute options.
Instance Method Summary collapse
-
#initialize(rules, options) ⇒ Transformer
constructor
A new instance of Transformer.
- #modify(&block) ⇒ Object
- #replace(&block) ⇒ Object
- #transform(node) ⇒ Object
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, ) @rules = rules @options = end |
Instance Attribute Details
#options ⇒ Object
Returns the value of attribute options.
4 5 6 |
# File 'lib/nora_mark/transformer.rb', line 4 def @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 |