liquid_tag_with_params 0.0.2 → 0.0.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/.gitignore +2 -0
- data/README.md +2 -0
- data/lib/{liquid_tag_with_params.rb → liquid/tag_with_params.rb} +3 -2
- data/lib/{liquid_tag_with_params → liquid/tag_with_params}/parser.rb +2 -2
- data/lib/{liquid_tag_with_params → liquid/tag_with_params}/version.rb +1 -1
- data/liquid_tag_with_params.gemspec +1 -1
- data/test/{liquid_tag_with_params → liquid/tag_with_params}/parser_test.rb +19 -19
- data/test/{liquid_tag_with_params_test.rb → liquid/tag_with_params_test.rb} +2 -2
- data/test/test_helper.rb +1 -2
- metadata +8 -8
- data/Gemfile.lock +0 -23
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 82598649edec7d4e16443a6e3d689aeeb2ad0a9d
|
4
|
+
data.tar.gz: f9fd29cdfce5652b2764b86e5841d43364dae6b7
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 7671cc7d9ad66c16f87904ddba1809a005dcfb3c30add0c5bfce641f267248c27dbea4455cc1819a95429260f1ef0b47c78af1fd8d37485ff323f2bb17f1b3fe
|
7
|
+
data.tar.gz: bd7bee81e654d3c8cafac679740edaafe9e2b7b6bb99b4206d40710a3e0ede5e4fac709f81b374ca74d67363cb0f09c395e98bc2e4c73656087c19bd46d70d70
|
data/.gitignore
ADDED
data/README.md
CHANGED
@@ -20,6 +20,8 @@ string and will make parameters out of it so you can use them during rendering.
|
|
20
20
|
Here's an example of such tag:
|
21
21
|
|
22
22
|
```ruby
|
23
|
+
require 'liquid/tag_with_params'
|
24
|
+
|
23
25
|
class ShuffleTag < Liquid::TagWithParams
|
24
26
|
def initialize(tag_name, params, tokens)
|
25
27
|
super
|
@@ -1,5 +1,4 @@
|
|
1
1
|
require 'liquid'
|
2
|
-
require_relative 'liquid_tag_with_params/parser'
|
3
2
|
|
4
3
|
class Liquid::TagWithParams < Liquid::Tag
|
5
4
|
|
@@ -7,10 +6,12 @@ class Liquid::TagWithParams < Liquid::Tag
|
|
7
6
|
|
8
7
|
def initialize(tag_name, markup, parse_context)
|
9
8
|
super
|
10
|
-
@params =
|
9
|
+
@params = Liquid::TagWithParams::Parser.parse(markup)
|
11
10
|
end
|
12
11
|
|
13
12
|
def render(_context)
|
14
13
|
""
|
15
14
|
end
|
16
15
|
end
|
16
|
+
|
17
|
+
require_relative 'tag_with_params/parser'
|
@@ -1,4 +1,4 @@
|
|
1
|
-
module
|
1
|
+
module Liquid::TagWithParams::Parser
|
2
2
|
|
3
3
|
SINGLE_STRING_LITERAL = /'[^\']*'/
|
4
4
|
DOUBLE_STRING_LITERAL = /"[^\"]*"/
|
@@ -34,7 +34,7 @@ module LiquidTagWithParams::Parser
|
|
34
34
|
def self.collect_param_for_hash!(params, tokens)
|
35
35
|
key, col, val = tokens
|
36
36
|
key_type, key_value = key
|
37
|
-
col_type,
|
37
|
+
col_type, _ = col
|
38
38
|
val_type, val_value = val
|
39
39
|
|
40
40
|
unless key_type == :string && col_type == :column && val_type == :string
|
@@ -1,102 +1,102 @@
|
|
1
|
-
require_relative '
|
1
|
+
require_relative '../../test_helper'
|
2
2
|
|
3
|
-
class
|
3
|
+
class Liquid::TagWithParams::ParserTest < MiniTest::Test
|
4
4
|
|
5
5
|
def test_tokenizer
|
6
|
-
tokens =
|
6
|
+
tokens = Liquid::TagWithParams::Parser.tokenize("param")
|
7
7
|
assert_equal [[:string, "param"]], tokens
|
8
8
|
end
|
9
9
|
|
10
10
|
def test_tokenizer_with_commas
|
11
|
-
tokens =
|
11
|
+
tokens = Liquid::TagWithParams::Parser.tokenize("param_a, param_b")
|
12
12
|
assert_equal [[:string, "param_a"], [:comma, ","], [:string, "param_b"]], tokens
|
13
13
|
end
|
14
14
|
|
15
15
|
def test_tokenizer_with_columns
|
16
|
-
tokens =
|
16
|
+
tokens = Liquid::TagWithParams::Parser.tokenize("key: value")
|
17
17
|
assert_equal [[:string, "key"], [:column, ":"], [:string, "value"]], tokens
|
18
18
|
end
|
19
19
|
|
20
20
|
def test_tokenizer_with_quoted_value
|
21
|
-
tokens =
|
21
|
+
tokens = Liquid::TagWithParams::Parser.tokenize("key: 'v1, v2: v3'")
|
22
22
|
assert_equal [[:string, "key"], [:column, ":"], [:string, "'v1, v2: v3'"]], tokens
|
23
23
|
|
24
|
-
tokens =
|
24
|
+
tokens = Liquid::TagWithParams::Parser.tokenize('key: "v1, v2: v3"')
|
25
25
|
assert_equal [[:string, "key"], [:column, ":"], [:string, '"v1, v2: v3"']], tokens
|
26
26
|
end
|
27
27
|
|
28
28
|
def test_tokenizer_with_bad_input
|
29
29
|
assert_exception_raised do
|
30
|
-
|
30
|
+
Liquid::TagWithParams::Parser.tokenize("%")
|
31
31
|
end
|
32
32
|
end
|
33
33
|
|
34
34
|
def test_slice
|
35
35
|
tokens = [[:string, "a"], [:comma, ","], [:string, "b"]]
|
36
|
-
token_groups =
|
36
|
+
token_groups = Liquid::TagWithParams::Parser.slice(tokens)
|
37
37
|
assert_equal [[[:string, "a"]], [[:string, "b"]]], token_groups
|
38
38
|
end
|
39
39
|
|
40
40
|
def test_parameterize
|
41
41
|
token_groups = [[[:string, "a"]]]
|
42
|
-
params =
|
42
|
+
params = Liquid::TagWithParams::Parser.parameterize(token_groups)
|
43
43
|
assert_equal ["a"], params
|
44
44
|
|
45
45
|
token_groups = [[[:string, "a"], [:column, ":"], [:string, "b"]]]
|
46
|
-
params =
|
46
|
+
params = Liquid::TagWithParams::Parser.parameterize(token_groups)
|
47
47
|
assert_equal [{"a" => "b"}], params
|
48
48
|
end
|
49
49
|
|
50
50
|
def test_parameterize_with_bad_input
|
51
51
|
token_groups = [[[:string, "a"], [:string, "b"]]]
|
52
52
|
assert_exception_raised do
|
53
|
-
|
53
|
+
Liquid::TagWithParams::Parser.parameterize(token_groups)
|
54
54
|
end
|
55
55
|
end
|
56
56
|
|
57
57
|
def test_collect_param_for_string!
|
58
58
|
params = []
|
59
|
-
|
59
|
+
Liquid::TagWithParams::Parser.collect_param_for_string!(params, [:string, "a"])
|
60
60
|
assert_equal ["a"], params
|
61
61
|
end
|
62
62
|
|
63
63
|
def test_collect_param_for_string_with_bad_input
|
64
64
|
assert_exception_raised do
|
65
|
-
|
65
|
+
Liquid::TagWithParams::Parser.collect_param_for_string!([], [:invalid, "a"])
|
66
66
|
end
|
67
67
|
end
|
68
68
|
|
69
69
|
def test_collect_param_for_hash!
|
70
70
|
params = []
|
71
71
|
tokens = [[:string, "a"], [:column, ":"], [:string, "b"]]
|
72
|
-
|
72
|
+
Liquid::TagWithParams::Parser.collect_param_for_hash!(params, tokens)
|
73
73
|
assert_equal [{"a" => "b"}], params
|
74
74
|
end
|
75
75
|
|
76
76
|
def test_collect_param_for_hash_with_trailing_hash
|
77
77
|
params = ["x", {"y" => "z"}]
|
78
78
|
tokens = [[:string, "a"], [:column, ":"], [:string, "b"]]
|
79
|
-
|
79
|
+
Liquid::TagWithParams::Parser.collect_param_for_hash!(params, tokens)
|
80
80
|
assert_equal ["x", {"y" => "z", "a" => "b"}], params
|
81
81
|
end
|
82
82
|
|
83
83
|
def test_collect_param_for_hash_with_trailing_param
|
84
84
|
params = ["x", {"y" => "z"}, "k"]
|
85
85
|
tokens = [[:string, "a"], [:column, ":"], [:string, "b"]]
|
86
|
-
|
86
|
+
Liquid::TagWithParams::Parser.collect_param_for_hash!(params, tokens)
|
87
87
|
assert_equal ["x", {"y" => "z"}, "k", {"a" => "b"}], params
|
88
88
|
end
|
89
89
|
|
90
90
|
def test_collect_param_for_hash_with_bad_input
|
91
91
|
assert_exception_raised do
|
92
92
|
tokens = [[:string, "a"], [:invalid, ":"], [:string, "b"]]
|
93
|
-
|
93
|
+
Liquid::TagWithParams::Parser.collect_param_for_hash!([], tokens)
|
94
94
|
end
|
95
95
|
end
|
96
96
|
|
97
97
|
def test_parse
|
98
98
|
text = "param_a, param_b, key_a: val_a, key_b: val_b, param_c, key_c: val_c"
|
99
|
-
params =
|
99
|
+
params = Liquid::TagWithParams::Parser.parse(text)
|
100
100
|
assert_equal [
|
101
101
|
"param_a",
|
102
102
|
"param_b",
|
data/test/test_helper.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: liquid_tag_with_params
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Oleg Khabarov
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2017-09-
|
11
|
+
date: 2017-09-19 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: liquid
|
@@ -31,17 +31,17 @@ executables: []
|
|
31
31
|
extensions: []
|
32
32
|
extra_rdoc_files: []
|
33
33
|
files:
|
34
|
+
- ".gitignore"
|
34
35
|
- Gemfile
|
35
|
-
- Gemfile.lock
|
36
36
|
- LICENSE
|
37
37
|
- README.md
|
38
38
|
- Rakefile
|
39
|
-
- lib/
|
40
|
-
- lib/
|
41
|
-
- lib/
|
39
|
+
- lib/liquid/tag_with_params.rb
|
40
|
+
- lib/liquid/tag_with_params/parser.rb
|
41
|
+
- lib/liquid/tag_with_params/version.rb
|
42
42
|
- liquid_tag_with_params.gemspec
|
43
|
-
- test/
|
44
|
-
- test/
|
43
|
+
- test/liquid/tag_with_params/parser_test.rb
|
44
|
+
- test/liquid/tag_with_params_test.rb
|
45
45
|
- test/test_helper.rb
|
46
46
|
homepage: http://github.com/comfy/liquid_tag_with_params
|
47
47
|
licenses: []
|
data/Gemfile.lock
DELETED
@@ -1,23 +0,0 @@
|
|
1
|
-
PATH
|
2
|
-
remote: .
|
3
|
-
specs:
|
4
|
-
liquid_tag_with_params (0.0.1)
|
5
|
-
liquid (>= 4.0.0)
|
6
|
-
|
7
|
-
GEM
|
8
|
-
remote: http://rubygems.org/
|
9
|
-
specs:
|
10
|
-
liquid (4.0.0)
|
11
|
-
minitest (5.10.3)
|
12
|
-
rake (12.1.0)
|
13
|
-
|
14
|
-
PLATFORMS
|
15
|
-
ruby
|
16
|
-
|
17
|
-
DEPENDENCIES
|
18
|
-
liquid_tag_with_params!
|
19
|
-
minitest
|
20
|
-
rake
|
21
|
-
|
22
|
-
BUNDLED WITH
|
23
|
-
1.14.6
|