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



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

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

Instance Method Details

#build(node) ⇒ Object



18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
# File 'lib/grokdown/creating.rb', line 18

def build(node)
  if @create
    args = begin
      @create.call(node)
    rescue NoMethodError => e
      raise Error, "cannot find #{e.name} from #{node.to_commonmark.inspect} at #{node.sourcepos[:start_line]} in #{self} create block"
    rescue CommonMarker::NodeError => e
      raise Error, "could not get string content from #{node.to_commonmark.inspect} at #{node.sourcepos[:start_line]} in #{self} create block"
    end

    _build(args) {|i| i.node=node }
  else
    new.tap do |i| i.node=node end
  end
end

#create(many: false, &block) ⇒ Object



13
14
15
16
# File 'lib/grokdown/creating.rb', line 13

def create(many: false, &block)
  @create = block
  @create_many = many
end