Module: Grokdown::Creating

Defined in:
lib/grokdown/creating.rb

Defined Under Namespace

Modules: InstanceMethods

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.extended(base) ⇒ Object



5
6
7
# File 'lib/grokdown/creating.rb', line 5

def self.extended(base)
  base.send(:include, InstanceMethods)
end

Instance Method Details

#build(node) ⇒ Object



9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
# File 'lib/grokdown/creating.rb', line 9

def build(node)
  begin
    return collection_of_arguments_from_node(node).map { |args| _build(args, false) { |i| i.node = node } } if respond_to?(:collection_of_arguments_from_node)
  rescue NoMethodError => e
    raise Error, "cannot find #{e.name} from #{node.to_commonmark.inspect} at #{node.sourcepos[:start_line]} in #{self} collection_of_arguments_from_node"
  rescue CommonMarker::NodeError
    raise Error, "could not get string content from #{node.to_commonmark.inspect} at #{node.sourcepos[:start_line]} in #{self} collection_of_arguments_from_node"
  end

  begin
    return _build(arguments_from_node(node)) { |i| i.node = node } if respond_to?(:arguments_from_node)
  rescue NoMethodError => e
    raise Error, "cannot find #{e.name} from #{node.to_commonmark.inspect} at #{node.sourcepos[:start_line]} in #{self} arguments_from_node"
  rescue CommonMarker::NodeError
    raise Error, "could not get string content from #{node.to_commonmark.inspect} at #{node.sourcepos[:start_line]} in #{self} arguments_from_node"
  end

  new.tap { |i| i.node = node }
end