grokdown 0.1.1 → 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: e28649738fc0fd8efb4ecb18aee9129c5516931433647aa81b566b7961a90ee4
4
- data.tar.gz: '08cde2281282a101e666b3986f1d5ec4a10475578a6716a9b3ac2758a0f35515'
3
+ metadata.gz: 0df4042c8ccc179f5294c0b1e19e12b231d6bb152795d0fcf44a0aa68e8bb8ed
4
+ data.tar.gz: beb8f749febaf3f8de2097f5f4206328ba4083bfd872257ce67b58742228a2ef
5
5
  SHA512:
6
- metadata.gz: 92cc60eeb1d8f1b4bc46403a64cce8de6b48a8bbbc8256b36d604c4ea289d1d9f25ef70f108fdf757b86d91f17bf2610c80a1484b3c0bc6f5427fec4034f2605
7
- data.tar.gz: 8c34f3929947a4934e4d0b55e175899a5ea57ee81a820f4107bb39580209244f612db586f765e6a39bdeecbfe5d04889f42433518b5edb31fc9197af77e0f84c
6
+ metadata.gz: 4b4ac09e38dd8b5cfee67ddf23bc1b0b90893a35473a7be7d519b1d02286d643494890543233c6dc194c156294490e1db497a3efc4b31e834fec0de0f835870a
7
+ data.tar.gz: 78b56dce2afa9c0711fb4f56ac8e8ef31ec90b9be52488567b0af532f2f8814419c5fa23806dad6b98f91f0c6f2634cec9ada24a5d83e162ace1aa360d7d6f9f
@@ -10,8 +10,9 @@ module Grokdown
10
10
  mod = self
11
11
  define_method(:recurse) { mod }
12
12
 
13
- def create(&block)
13
+ def create(many: false, &block)
14
14
  @create = block
15
+ @create_many = many
15
16
  end
16
17
 
17
18
  def build(node)
@@ -22,25 +23,37 @@ module Grokdown
22
23
  raise Error, "cannot find #{e.name} from #{node.to_commonmark.inspect} at #{node.sourcepos[:start_line]}"
23
24
  end
24
25
 
25
- case args
26
- when Hash
27
- if self < Hash
28
- new.merge!(args)
29
- else
30
- new(**args)
31
- end
32
- when Array
26
+ _build(args) {|i| i.node=node }
27
+ else
28
+ new.tap do |i| i.node=node end
29
+ end
30
+ end
31
+
32
+ private def _build(args,recurse=true,&block)
33
+ case args
34
+ when Hash
35
+ if self < Hash
36
+ new.merge!(args).tap(&block)
37
+
38
+ else
39
+ new(**args).tap(&block)
40
+
41
+ end
42
+ when Array
43
+ if @create_many && recurse
44
+ args.map {|i| _build(i,false,&block) }
45
+ else
33
46
  if self < Array
34
- new(args)
47
+ new(args).tap(&block)
48
+
35
49
  else
36
- new(*args)
50
+ new(*args).tap(&block)
51
+
37
52
  end
38
- else
39
- new(*args)
40
53
  end
41
54
  else
42
- new
43
- end.tap do |i| i.node=node end
55
+ new(*args).tap(&block)
56
+ end
44
57
  end
45
58
 
46
59
  module InstanceMethods
@@ -22,6 +22,20 @@ module Grokdown
22
22
  end
23
23
 
24
24
  def push(node)
25
+ case node when Matching
26
+ _push(node)
27
+ when Array
28
+ node.each do |n|
29
+ _push(n)
30
+ end
31
+ else
32
+ _push(node)
33
+ end
34
+
35
+ self
36
+ end
37
+
38
+ private def _push(node)
25
39
  if accepts = @walk.reverse.find {|i| i.consumes?(node) }
26
40
  accepts.consume(node)
27
41
  else
@@ -29,8 +43,6 @@ module Grokdown
29
43
  end
30
44
 
31
45
  @walk.push(node)
32
-
33
- self
34
46
  end
35
47
 
36
48
  attr_reader :nodes
@@ -1,3 +1,3 @@
1
1
  module Grokdown
2
- VERSION = "0.1.1"
2
+ VERSION = "0.2.0"
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: grokdown
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.1
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Caleb Buxton