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 +4 -4
- data/lib/grokdown/creating.rb +28 -15
- data/lib/grokdown/document.rb +14 -2
- data/lib/grokdown/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 0df4042c8ccc179f5294c0b1e19e12b231d6bb152795d0fcf44a0aa68e8bb8ed
|
4
|
+
data.tar.gz: beb8f749febaf3f8de2097f5f4206328ba4083bfd872257ce67b58742228a2ef
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 4b4ac09e38dd8b5cfee67ddf23bc1b0b90893a35473a7be7d519b1d02286d643494890543233c6dc194c156294490e1db497a3efc4b31e834fec0de0f835870a
|
7
|
+
data.tar.gz: 78b56dce2afa9c0711fb4f56ac8e8ef31ec90b9be52488567b0af532f2f8814419c5fa23806dad6b98f91f0c6f2634cec9ada24a5d83e162ace1aa360d7d6f9f
|
data/lib/grokdown/creating.rb
CHANGED
@@ -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
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
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
|
55
|
+
new(*args).tap(&block)
|
56
|
+
end
|
44
57
|
end
|
45
58
|
|
46
59
|
module InstanceMethods
|
data/lib/grokdown/document.rb
CHANGED
@@ -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
|
data/lib/grokdown/version.rb
CHANGED