Module: Upmark::TransformHelpers::ClassMethods

Defined in:
lib/upmark/transform_helpers.rb

Instance Method Summary collapse

Instance Method Details

#element(*names, &block) ⇒ Object



8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
# File 'lib/upmark/transform_helpers.rb', line 8

def element(*names, &block)
  names.each do |name|
    name = name.to_s.downcase
    rule(
      {
        element: {
          name:       (name != "*" ? name : simple(:name)),
          attributes: subtree(:attributes),
          children:   subtree(:children),
          ignore:     false
        }
      }
    ) do |element|
      element[:name] ||= name
      block.call(element)
    end
  end
end

#map_attributes_subtree(ast) ⇒ Object



27
28
29
30
31
32
# File 'lib/upmark/transform_helpers.rb', line 27

def map_attributes_subtree(ast)
  ast.inject({}) do |hash, attribute|
    hash[attribute[:name].to_sym] = attribute[:value]
    hash
  end
end