vanilla 1.9.14.3 → 1.9.15.1
Sign up to get free protection for your applications and to get access to all the features.
- data/Rakefile +1 -1
- data/lib/vanilla/snip_reference.treetop +14 -0
- data/lib/vanilla/snip_reference_parser.rb +13 -58
- data/test/snip_parser_test.rb +53 -0
- data/test/tmp/soup/current_snip.yml +2 -2
- data/test/tmp/soup/system.yml +2 -2
- metadata +2 -1
data/Rakefile
CHANGED
@@ -13,6 +13,7 @@ grammar SnipReference
|
|
13
13
|
end
|
14
14
|
|
15
15
|
rule argument
|
16
|
+
hash_argument <HashArgument> /
|
16
17
|
unquoted_words <NormalArgument> /
|
17
18
|
quoted_word <NormalArgument>
|
18
19
|
end
|
@@ -21,6 +22,19 @@ grammar SnipReference
|
|
21
22
|
"," optional_spaces
|
22
23
|
end
|
23
24
|
|
25
|
+
rule hash_argument
|
26
|
+
word_or_symbol optional_spaces hash_argument_separator optional_spaces word
|
27
|
+
end
|
28
|
+
|
29
|
+
rule hash_argument_separator
|
30
|
+
"=>" /
|
31
|
+
":"
|
32
|
+
end
|
33
|
+
|
34
|
+
rule word_or_symbol
|
35
|
+
[:]? word
|
36
|
+
end
|
37
|
+
|
24
38
|
rule word
|
25
39
|
unquoted_word / quoted_word
|
26
40
|
end
|
@@ -40,10 +40,21 @@ module SnipReference
|
|
40
40
|
module ArgumentList
|
41
41
|
def to_arguments
|
42
42
|
args = elements[0].to_arguments
|
43
|
-
|
43
|
+
if args.is_a?(Array)
|
44
|
+
args << elements[1].elements[1].to_arguments if elements[1].elements
|
45
|
+
elsif args.is_a?(Hash)
|
46
|
+
args.merge!(elements[1].elements[1].to_arguments) if elements[1].elements
|
47
|
+
end
|
44
48
|
args
|
45
49
|
end
|
46
50
|
end
|
51
|
+
module HashArgument
|
52
|
+
def to_arguments
|
53
|
+
key = elements[0].text_value
|
54
|
+
key = $1 if key =~ /\A:(.*)\Z/
|
55
|
+
{key.to_sym => elements[4].text_value}
|
56
|
+
end
|
57
|
+
end
|
47
58
|
module NormalArgument
|
48
59
|
def to_arguments
|
49
60
|
[text_value]
|
@@ -52,60 +63,4 @@ module SnipReference
|
|
52
63
|
end
|
53
64
|
|
54
65
|
require 'treetop'
|
55
|
-
require 'vanilla/snip_reference'
|
56
|
-
|
57
|
-
|
58
|
-
if __FILE__ == $0
|
59
|
-
|
60
|
-
Treetop.load "vanilla/snip_reference"
|
61
|
-
require 'test/unit'
|
62
|
-
|
63
|
-
class SnipReferenceParserTest < Test::Unit::TestCase
|
64
|
-
examples = {
|
65
|
-
%|{snip}| => {:snip => 'snip', :attribute => nil, :arguments => []},
|
66
|
-
%|{snip argument}| => {:snip => 'snip', :attribute => nil, :arguments => ["argument"]},
|
67
|
-
%|{"snip with spaces"}| => {:snip => 'snip with spaces', :attribute => nil, :arguments => []},
|
68
|
-
%|{snip-with-dashes}| => {:snip => 'snip-with-dashes', :attribute => nil, :arguments => []},
|
69
|
-
%|{snip_with_underscores}| => {:snip => 'snip_with_underscores', :attribute => nil, :arguments => []},
|
70
|
-
%|{"snip with spaces" argument}| => {:snip => 'snip with spaces', :attribute => nil, :arguments => ['argument']},
|
71
|
-
%|{'snip with spaces' argument}| => {:snip => 'snip with spaces', :attribute => nil, :arguments => ['argument']},
|
72
|
-
%|{snip "argument with spaces"}| => {:snip => 'snip', :attribute => nil, :arguments => ['argument with spaces']},
|
73
|
-
%|{snip 'argument with spaces'}| => {:snip => 'snip', :attribute => nil, :arguments => ['argument with spaces']},
|
74
|
-
%|{snip arg1,arg2}| => {:snip => 'snip', :attribute => nil, :arguments => ['arg1', 'arg2']},
|
75
|
-
%|{snip arg1, arg2}| => {:snip => 'snip', :attribute => nil, :arguments => ['arg1', 'arg2']},
|
76
|
-
%|{snip "argument with spaces", arg2}| => {:snip => 'snip', :attribute => nil, :arguments => ['argument with spaces', 'arg2']},
|
77
|
-
%|{"snip with spaces" arg1, arg2}| => {:snip => 'snip with spaces', :attribute => nil, :arguments => ['arg1', 'arg2']},
|
78
|
-
%|{snip.snip_attribute}| => {:snip => 'snip', :attribute => 'snip_attribute', :arguments => []},
|
79
|
-
%|{snip."spaced attribute"}| => {:snip => 'snip', :attribute => 'spaced attribute', :arguments => []},
|
80
|
-
%|{"snip with spaces".attribute}| => {:snip => 'snip with spaces', :attribute => 'attribute', :arguments => []},
|
81
|
-
%|{snip.snip_attribute arg}| => {:snip => 'snip', :attribute => 'snip_attribute', :arguments => ['arg']},
|
82
|
-
%|{snip arg with spaces}| => {:snip => 'snip', :attribute => nil, :arguments => ['arg with spaces']},
|
83
|
-
%|{snip arg with spaces, another arg}| => {:snip => 'snip', :attribute => nil, :arguments => ['arg with spaces', 'another arg']},
|
84
|
-
# %|{snip key1:value1,key2:value2}| => {:snip => 'snip', :arguments => {:key1 => 'value1', :key2 => 'value2'}},
|
85
|
-
# %|{snip key1:value1, key2:value2}| => {:snip => 'snip', :arguments => {:key}},
|
86
|
-
# %|{snip key1: value1, key2: value2}|,
|
87
|
-
# %|{snip key1 => value1, key2 => value2}|,
|
88
|
-
# %|{snip :key1 => value1, :key2 => value2}|,
|
89
|
-
# %|{snip key1:"value with spaces"}|,
|
90
|
-
# %|{snip key1 => "value with spaces"}| => {:snip => 'snip', :arguments => {:key1 => "value with spaces"}}
|
91
|
-
}
|
92
|
-
|
93
|
-
def setup
|
94
|
-
@parser = SnipReferenceParser.new
|
95
|
-
end
|
96
|
-
|
97
|
-
examples.each do |example, expected|
|
98
|
-
define_method :"test_parsing_#{example}" do
|
99
|
-
reference = @parser.parse(example)
|
100
|
-
if reference
|
101
|
-
assert_equal expected[:snip], reference.snip
|
102
|
-
assert_equal expected[:attribute], reference.attribute
|
103
|
-
assert_equal expected[:arguments], reference.arguments
|
104
|
-
else
|
105
|
-
flunk "failed to parse: #{example}"
|
106
|
-
end
|
107
|
-
end
|
108
|
-
end
|
109
|
-
end
|
110
|
-
|
111
|
-
end
|
66
|
+
require 'vanilla/snip_reference'
|
@@ -0,0 +1,53 @@
|
|
1
|
+
require File.join(File.dirname(__FILE__), *%w[test_helper])
|
2
|
+
Treetop.load File.join(File.dirname(__FILE__), *%w[.. lib vanilla snip_reference])
|
3
|
+
|
4
|
+
class SnipReferenceParserTest < Test::Unit::TestCase
|
5
|
+
examples = {
|
6
|
+
%|{snip}| => {:snip => 'snip', :attribute => nil, :arguments => []},
|
7
|
+
%|{snip argument}| => {:snip => 'snip', :attribute => nil, :arguments => ["argument"]},
|
8
|
+
%|{"snip with spaces"}| => {:snip => 'snip with spaces', :attribute => nil, :arguments => []},
|
9
|
+
%|{snip-with-dashes}| => {:snip => 'snip-with-dashes', :attribute => nil, :arguments => []},
|
10
|
+
%|{snip_with_underscores}| => {:snip => 'snip_with_underscores', :attribute => nil, :arguments => []},
|
11
|
+
%|{"snip with spaces" argument}| => {:snip => 'snip with spaces', :attribute => nil, :arguments => ['argument']},
|
12
|
+
%|{'snip with spaces' argument}| => {:snip => 'snip with spaces', :attribute => nil, :arguments => ['argument']},
|
13
|
+
%|{snip "argument with spaces"}| => {:snip => 'snip', :attribute => nil, :arguments => ['argument with spaces']},
|
14
|
+
%|{snip 'argument with spaces'}| => {:snip => 'snip', :attribute => nil, :arguments => ['argument with spaces']},
|
15
|
+
%|{snip arg1,arg2}| => {:snip => 'snip', :attribute => nil, :arguments => ['arg1', 'arg2']},
|
16
|
+
%|{snip arg1, arg2}| => {:snip => 'snip', :attribute => nil, :arguments => ['arg1', 'arg2']},
|
17
|
+
%|{snip "argument with spaces", arg2}| => {:snip => 'snip', :attribute => nil, :arguments => ['argument with spaces', 'arg2']},
|
18
|
+
%|{"snip with spaces" arg1, arg2}| => {:snip => 'snip with spaces', :attribute => nil, :arguments => ['arg1', 'arg2']},
|
19
|
+
%|{snip.snip_attribute}| => {:snip => 'snip', :attribute => 'snip_attribute', :arguments => []},
|
20
|
+
%|{snip."spaced attribute"}| => {:snip => 'snip', :attribute => 'spaced attribute', :arguments => []},
|
21
|
+
%|{"snip with spaces".attribute}| => {:snip => 'snip with spaces', :attribute => 'attribute', :arguments => []},
|
22
|
+
%|{snip.snip_attribute arg}| => {:snip => 'snip', :attribute => 'snip_attribute', :arguments => ['arg']},
|
23
|
+
%|{snip arg with spaces}| => {:snip => 'snip', :attribute => nil, :arguments => ['arg with spaces']},
|
24
|
+
%|{snip arg with spaces, another arg}| => {:snip => 'snip', :attribute => nil, :arguments => ['arg with spaces', 'another arg']},
|
25
|
+
%|{snip key1=>value1, key2 => value2}| => {:snip => 'snip', :arguments => {:key1 => 'value1', :key2 => 'value2'}},
|
26
|
+
%|{snip.attribute key1=>value1}| => {:snip => 'snip', :attribute => 'attribute', :arguments => {:key1 => 'value1'}},
|
27
|
+
%|{snip key1 => value1, key2 => value2}| => {:snip => 'snip', :arguments => {:key1 => 'value1', :key2 => 'value2'}},
|
28
|
+
%|{snip :key1 => value1, :key2 => value2}| => {:snip => 'snip', :arguments => {:key1 => 'value1', :key2 => 'value2'}},
|
29
|
+
%|{snip key1 => "value with spaces"}| => {:snip => 'snip', :arguments => {:key1 => "value with spaces"}},
|
30
|
+
# %|{snip "key with spaces" => value} | => {:snip => 'snip', :arguments => {:"key with spaces" => "value"}},
|
31
|
+
%|{snip key1:value1,key2:value2}| => {:snip => 'snip', :arguments => {:key1 => 'value1', :key2 => 'value2'}},
|
32
|
+
%|{snip key1:value1, key2:value2}| => {:snip => 'snip', :arguments => {:key1 => 'value1', :key2 => 'value2'}},
|
33
|
+
%|{snip key1: value1, key2: value2}| => {:snip => 'snip', :arguments => {:key1 => 'value1', :key2 => 'value2'}},
|
34
|
+
%|{snip key1:"value with spaces"}| => {:snip => 'snip', :arguments => {:key1 => 'value with spaces'}}
|
35
|
+
}
|
36
|
+
|
37
|
+
def setup
|
38
|
+
@parser = SnipReferenceParser.new
|
39
|
+
end
|
40
|
+
|
41
|
+
examples.each do |example, expected|
|
42
|
+
define_method :"test_parsing_#{example}" do
|
43
|
+
reference = @parser.parse(example)
|
44
|
+
if reference
|
45
|
+
assert_equal expected[:snip], reference.snip
|
46
|
+
assert_equal expected[:attribute], reference.attribute
|
47
|
+
assert_equal expected[:arguments], reference.arguments
|
48
|
+
else
|
49
|
+
flunk "failed to parse: #{example}"
|
50
|
+
end
|
51
|
+
end
|
52
|
+
end
|
53
|
+
end
|
@@ -1,5 +1,5 @@
|
|
1
1
|
CurrentSnip--- # Soup attributes
|
2
|
-
:updated_at: 2009-11-24
|
2
|
+
:updated_at: 2009-11-24 11:25:40.019881 +00:00
|
3
3
|
:name: current_snip
|
4
4
|
:render_as: Ruby
|
5
5
|
:usage: |-
|
@@ -12,4 +12,4 @@ CurrentSnip--- # Soup attributes
|
|
12
12
|
{current_snip name}
|
13
13
|
|
14
14
|
will output the name of the current snip, or the name of the snip currently being edited.
|
15
|
-
:created_at: 2009-11-24
|
15
|
+
:created_at: 2009-11-24 11:25:40.019878 +00:00
|
data/test/tmp/soup/system.yml
CHANGED
@@ -1,5 +1,5 @@
|
|
1
1
|
--- # Soup attributes
|
2
|
-
:updated_at: 2009-11-24
|
2
|
+
:updated_at: 2009-11-24 11:25:40.020545 +00:00
|
3
3
|
:name: system
|
4
4
|
:main_template: "{current_snip}"
|
5
|
-
:created_at: 2009-11-24
|
5
|
+
:created_at: 2009-11-24 11:25:40.020543 +00:00
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: vanilla
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.9.
|
4
|
+
version: 1.9.15.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- James Adam
|
@@ -122,6 +122,7 @@ files:
|
|
122
122
|
- test/markdown_renderer_test.rb
|
123
123
|
- test/raw_renderer_test.rb
|
124
124
|
- test/ruby_renderer_test.rb
|
125
|
+
- test/snip_parser_test.rb
|
125
126
|
- test/test_helper.rb
|
126
127
|
- test/tmp/config.yml
|
127
128
|
- test/tmp/soup/current_snip.yml
|