tzispa_rig 0.4.5 → 0.5.0
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/CHANGELOG.md +10 -0
- data/README.md +10 -6
- data/Rakefile +7 -0
- data/lib/tzispa/rig/binder.rb +15 -7
- data/lib/tzispa/rig/engine.rb +43 -31
- data/lib/tzispa/rig/parameters.rb +4 -8
- data/lib/tzispa/rig/parsernext.rb +68 -378
- data/lib/tzispa/rig/syntax.rb +4 -7
- data/lib/tzispa/rig/template.rb +78 -54
- data/lib/tzispa/rig/token.rb +57 -0
- data/lib/tzispa/rig/type_token/api_url.rb +83 -0
- data/lib/tzispa/rig/type_token/block.rb +144 -0
- data/lib/tzispa/rig/type_token/expression.rb +65 -0
- data/lib/tzispa/rig/type_token/statement.rb +73 -0
- data/lib/tzispa/rig/version.rb +1 -1
- data/lib/tzispa/rig.rb +3 -2
- data/test/engine_test.rb +41 -0
- data/test/parameters_test.rb +35 -0
- data/test/parsernext_test.rb +256 -0
- data/test/res/apps/test_domain/view/product/layout/list.rig.htm +1 -0
- data/test/template_test.rb +78 -0
- data/test/test_helper.rb +174 -0
- metadata +31 -5
data/test/engine_test.rb
ADDED
@@ -0,0 +1,41 @@
|
|
1
|
+
require 'fileutils'
|
2
|
+
require 'test_helper'
|
3
|
+
|
4
|
+
class EngineTest < Minitest::Test
|
5
|
+
include TemplateTestHelper
|
6
|
+
|
7
|
+
def setup
|
8
|
+
mklayout = ::File.new index_layout.filename, "wt"
|
9
|
+
mklayout << STR_L
|
10
|
+
mklayout.close
|
11
|
+
index_layout.load!
|
12
|
+
mkplayout = ::File.new productlist_layout.filename, "wt"
|
13
|
+
mkplayout << STR_L
|
14
|
+
mkplayout.close
|
15
|
+
productlist_layout.load!
|
16
|
+
end
|
17
|
+
|
18
|
+
def test_index
|
19
|
+
index = Tzispa::Rig::Engine.layout(name: 'index', domain: domain, content_type: :txt)
|
20
|
+
assert_equal index.content, STR_L
|
21
|
+
assert_equal index.type, :layout
|
22
|
+
assert index.layout?
|
23
|
+
refute index.modified?
|
24
|
+
# to force modified file timestamp
|
25
|
+
sleep 0.3
|
26
|
+
mkfile = ::File.new index_layout.filename, "at"
|
27
|
+
mkfile << STR_L
|
28
|
+
mkfile.close
|
29
|
+
assert index.modified?
|
30
|
+
assert_equal index.load!.content, "#{STR_L}#{STR_L}"
|
31
|
+
end
|
32
|
+
|
33
|
+
def test_subdomainlayout
|
34
|
+
playout = Tzispa::Rig::Engine.layout(name: 'product@list', domain: domain, content_type: :htm)
|
35
|
+
assert_equal playout.type, :layout
|
36
|
+
assert playout.layout?
|
37
|
+
refute playout.modified?
|
38
|
+
assert_equal playout.content, STR_L
|
39
|
+
end
|
40
|
+
|
41
|
+
end
|
@@ -0,0 +1,35 @@
|
|
1
|
+
require 'test_helper'
|
2
|
+
|
3
|
+
class ParametersTest < Minitest::Test
|
4
|
+
extend Minitest::Spec::DSL
|
5
|
+
|
6
|
+
RAW_PARAMS = "k1=value1;k2=value2"
|
7
|
+
RAW_ADDPARAMS = "k4=value4"
|
8
|
+
|
9
|
+
let(:params) { Tzispa::Rig::Parameters.new RAW_PARAMS, ';' }
|
10
|
+
let(:badparams) { Tzispa::Rig::Parameters.new RAW_PARAMS }
|
11
|
+
|
12
|
+
def test_params
|
13
|
+
assert params.has? 'k1'
|
14
|
+
assert params['k1'] == 'value1'
|
15
|
+
assert_equal params['k2'], 'value2'
|
16
|
+
assert_nil params['k4']
|
17
|
+
end
|
18
|
+
|
19
|
+
def test_params_set
|
20
|
+
params.merge RAW_ADDPARAMS
|
21
|
+
assert_equal params['k4'], 'value4'
|
22
|
+
assert_equal params.to_s, "#{RAW_PARAMS};#{RAW_ADDPARAMS}"
|
23
|
+
params['k5'] = 'value5'
|
24
|
+
assert params.has? 'k5'
|
25
|
+
assert_equal params['k5'], 'value5'
|
26
|
+
assert_equal params.to_s, "#{RAW_PARAMS};#{RAW_ADDPARAMS};k5=value5"
|
27
|
+
end
|
28
|
+
|
29
|
+
def test_bad_params
|
30
|
+
refute_equal badparams['k1'], 'value1'
|
31
|
+
refute badparams.has? 'k2'
|
32
|
+
end
|
33
|
+
|
34
|
+
|
35
|
+
end
|
@@ -0,0 +1,256 @@
|
|
1
|
+
require 'fileutils'
|
2
|
+
require 'test_helper'
|
3
|
+
require 'tzispa/helpers/security'
|
4
|
+
|
5
|
+
class ParsernextTest < Minitest::Test
|
6
|
+
include TemplateTestHelper
|
7
|
+
include Tzispa::Helpers::Security
|
8
|
+
|
9
|
+
def setup
|
10
|
+
all_templates.each { |tpl|
|
11
|
+
::File.open(tpl.filename, "wt") { |mkfile|
|
12
|
+
mkfile << STR_T
|
13
|
+
}
|
14
|
+
}
|
15
|
+
end
|
16
|
+
|
17
|
+
def test_empty_parser
|
18
|
+
parser = Tzispa::Rig::ParserNext.new text: STR_P, domain: domain, content_type: :htm, bindable: true
|
19
|
+
parser.parse!
|
20
|
+
assert_equal parser.tokens.count, 0
|
21
|
+
assert_equal parser.attribute_tags.count, 0
|
22
|
+
assert parser.empty?
|
23
|
+
end
|
24
|
+
|
25
|
+
def test_meta_parser
|
26
|
+
parser = Tzispa::Rig::ParserNext.new text: TPL_META, domain: domain, content_type: :htm, bindable: true
|
27
|
+
parser.parse!
|
28
|
+
assert_equal parser.tokens.count, 2
|
29
|
+
assert_equal parser.attribute_tags.count, 2
|
30
|
+
assert_equal parser.attribute_tags, [:meta1, :meta2]
|
31
|
+
assert_equal parser.attribute_tags, [:meta1, :meta2]
|
32
|
+
assert_instance_of Tzispa::Rig::TypeToken::Meta, parser.tokens[0]
|
33
|
+
assert_instance_of Tzispa::Rig::TypeToken::Meta, parser.tokens[1]
|
34
|
+
assert_equal parser.tokens[0].id, :meta1
|
35
|
+
assert_equal parser.tokens[1].id, :meta2
|
36
|
+
end
|
37
|
+
|
38
|
+
def test_meta_render
|
39
|
+
parser = Tzispa::Rig::ParserNext.new text: TPL_META, domain: domain, content_type: :txt, bindable: true
|
40
|
+
parser.parse!
|
41
|
+
binder = binder_fake.new parser, context, [123, 'john doe']
|
42
|
+
assert_equal parser.render(binder), 'meta testing 123\n\n 123:john doe\n'
|
43
|
+
binder = binder_fake.new parser, context, [nil, 'john doe']
|
44
|
+
assert_equal parser.render(binder), 'meta testing \n\n :john doe\n'
|
45
|
+
binder = binder_fake.new parser, context, []
|
46
|
+
assert_equal parser.render(binder), 'meta testing \n\n :\n'
|
47
|
+
end
|
48
|
+
|
49
|
+
def test_var_parser
|
50
|
+
parser = Tzispa::Rig::ParserNext.new text: TPL_VAR, domain: domain, content_type: :htm, bindable: true
|
51
|
+
parser.parse!
|
52
|
+
assert_equal parser.tokens.count, 4
|
53
|
+
assert_equal parser.attribute_tags.count, 4
|
54
|
+
assert_equal parser.attribute_tags, [:meta1, :meta2, :uno, :dos]
|
55
|
+
# metas are parsed before vars
|
56
|
+
assert_instance_of Tzispa::Rig::TypeToken::Var, parser.tokens[2]
|
57
|
+
assert_instance_of Tzispa::Rig::TypeToken::Var, parser.tokens[3]
|
58
|
+
assert_equal parser.tokens[2].id, :uno
|
59
|
+
assert_equal parser.tokens[3].id, :dos
|
60
|
+
end
|
61
|
+
|
62
|
+
def test_var_render
|
63
|
+
parser = Tzispa::Rig::ParserNext.new text: TPL_VAR, domain: domain, content_type: :htm, bindable: true
|
64
|
+
parser.parse!
|
65
|
+
binder = binder_fake.new parser, context, [2016, 'john doe', 'happy', 'year']
|
66
|
+
assert_equal parser.render(binder), 'var testing happy\n\n 2016 year happy:john doe\n'
|
67
|
+
binder = binder_fake.new parser, context, [2015, 'john doe', 'happy']
|
68
|
+
assert_equal parser.render(binder), 'var testing happy\n\n 2015 happy:john doe\n'
|
69
|
+
binder = binder_fake.new parser, context, []
|
70
|
+
assert_equal parser.render(binder), 'var testing \n\n :\n'
|
71
|
+
end
|
72
|
+
|
73
|
+
def test_loop_parser
|
74
|
+
parser = Tzispa::Rig::ParserNext.new text: TPL_LOOP, domain: domain, content_type: :htm, bindable: true
|
75
|
+
parser.parse!
|
76
|
+
assert_equal parser.tokens.count, 2
|
77
|
+
assert_equal parser.attribute_tags.count, 2
|
78
|
+
assert_equal parser.attribute_tags, [:literator, :tres]
|
79
|
+
assert_instance_of Tzispa::Rig::TypeToken::Loop, parser.tokens[0]
|
80
|
+
assert_equal parser.tokens[0].id, :literator
|
81
|
+
assert_equal parser.tokens[0].body_parser.tokens.count, 2
|
82
|
+
assert_equal parser.tokens[0].body_parser.attribute_tags.count, 2
|
83
|
+
assert_equal parser.tokens[0].body_parser.attribute_tags, [:uno, :dos]
|
84
|
+
assert_instance_of Tzispa::Rig::TypeToken::Var, parser.tokens[0].body_parser.tokens[0]
|
85
|
+
assert_instance_of Tzispa::Rig::TypeToken::Var, parser.tokens[0].body_parser.tokens[1]
|
86
|
+
assert_equal parser.tokens[0].body_parser.tokens[0].id, :uno
|
87
|
+
assert_equal parser.tokens[0].body_parser.tokens[1].id, :dos
|
88
|
+
end
|
89
|
+
|
90
|
+
def test_loop_render
|
91
|
+
parser = Tzispa::Rig::ParserNext.new text: TPL_LOOP, domain: domain, content_type: :htm, bindable: true
|
92
|
+
parser.parse!
|
93
|
+
binder = binder_fake.new parser, context, [Struct.new(:data).new([
|
94
|
+
binder_fake.new(parser.tokens[0].body_parser, {}, [1, 2]),
|
95
|
+
binder_fake.new(parser.tokens[0].body_parser, {}, [3, 4]),
|
96
|
+
binder_fake.new(parser.tokens[0].body_parser, {}, [5, 6])
|
97
|
+
]), 'watching']
|
98
|
+
assert_equal parser.render(binder), ' loop testing 1 2\n 1 loop testing 3 4\n 3 loop testing 5 6\n 5 watching'
|
99
|
+
binder = binder_fake.new parser, context, [Struct.new(:data).new([]), 'watching']
|
100
|
+
assert_equal parser.render(binder), ' watching'
|
101
|
+
binder = binder_fake.new parser, context, [Struct.new(:data).new, 'watching']
|
102
|
+
#assert_raises(NoMethodError) { parser.render(binder) }
|
103
|
+
binder = binder_fake.new parser, context, [[], 'watching']
|
104
|
+
assert_raises(NoMethodError) { parser.render(binder) }
|
105
|
+
end
|
106
|
+
|
107
|
+
def test_ife_parser
|
108
|
+
parser = Tzispa::Rig::ParserNext.new text: TPL_IFE, domain: domain, content_type: :htm, bindable: true
|
109
|
+
parser.parse!
|
110
|
+
assert_equal parser.tokens.count, 2
|
111
|
+
assert_equal parser.tokens[0].attribute_tags.count, 3
|
112
|
+
assert_equal parser.tokens[0].attribute_tags, [:condition, :uno, :dos]
|
113
|
+
assert_equal parser.tokens[1].attribute_tags.count, 4
|
114
|
+
assert_equal parser.tokens[1].attribute_tags, [:condition, :dos, :tres, :uno]
|
115
|
+
assert_equal parser.attribute_tags.count, 4
|
116
|
+
assert_equal parser.attribute_tags, [:condition, :uno, :dos, :tres]
|
117
|
+
assert_instance_of Tzispa::Rig::TypeToken::Ife, parser.tokens[0]
|
118
|
+
assert_equal parser.tokens[0].test, :condition
|
119
|
+
assert_equal parser.tokens[1].test, :condition
|
120
|
+
assert_equal parser.tokens[0].then_parser.tokens.count, 2
|
121
|
+
assert_nil parser.tokens[0].else_parser
|
122
|
+
assert_equal parser.tokens[1].then_parser.tokens.count, 3
|
123
|
+
assert_equal parser.tokens[1].else_parser.tokens.count, 1
|
124
|
+
end
|
125
|
+
|
126
|
+
def test_ife_render
|
127
|
+
parser = Tzispa::Rig::ParserNext.new text: TPL_IFE, domain: domain, content_type: :htm, bindable: true
|
128
|
+
parser.parse!
|
129
|
+
binder = binder_fake.new parser, context, [1==1, 'john doe', 'happy', 'year']
|
130
|
+
assert_equal parser.render(binder), ' ife testing john doe happy\n john doe happy year '
|
131
|
+
binder = binder_fake.new parser, context, [1==0, 'john doe', 'happy', 'year']
|
132
|
+
assert_equal parser.render(binder), ' happy '
|
133
|
+
end
|
134
|
+
|
135
|
+
|
136
|
+
def test_url_parser
|
137
|
+
parser = Tzispa::Rig::ParserNext.new text: "#{TPL_URL1} #{TPL_URL2} #{TPL_URL3}", domain: domain, content_type: :htm, bindable: true
|
138
|
+
parser.parse!
|
139
|
+
assert_equal parser.tokens.count, 4
|
140
|
+
assert_instance_of Tzispa::Rig::TypeToken::Url, parser.tokens[1]
|
141
|
+
assert_instance_of Tzispa::Rig::TypeToken::Url, parser.tokens[2]
|
142
|
+
assert_equal parser.tokens[0].id, :idp
|
143
|
+
assert_equal parser.tokens[1].layout, 'article'
|
144
|
+
assert_equal parser.tokens[2].layout, 'product@list'
|
145
|
+
assert_equal parser.tokens[3].layout, 'article_edit'
|
146
|
+
assert_equal parser.tokens[1].params, 'id=111,title=this_is_an_url_title'
|
147
|
+
assert_equal parser.tokens[2].params, "id=#{parser.tokens[0].anchor},title=this_is_an_url_title"
|
148
|
+
assert_equal parser.tokens[3].params, 'id=1220,format=json'
|
149
|
+
assert_nil parser.tokens[1].app_name
|
150
|
+
assert_nil parser.tokens[2].app_name
|
151
|
+
assert_equal parser.tokens[3].app_name, :adminapp
|
152
|
+
end
|
153
|
+
|
154
|
+
def test_url_render
|
155
|
+
parser = Tzispa::Rig::ParserNext.new text: TPL_URL1, domain: domain, content_type: :htm, bindable: true
|
156
|
+
parser.parse!
|
157
|
+
binder = binder_fake.new parser, context, []
|
158
|
+
assert_equal parser.render(binder), 'http://mytestdomainurl.com/article/this_is_an_url_title/111'
|
159
|
+
|
160
|
+
parser = Tzispa::Rig::ParserNext.new text: TPL_URL2, domain: domain, content_type: :htm, bindable: true
|
161
|
+
parser.parse!
|
162
|
+
binder = binder_fake.new parser, context, [2091]
|
163
|
+
assert_equal parser.render(binder), '/product@list/this_is_an_url_title/2091'
|
164
|
+
|
165
|
+
parser = Tzispa::Rig::ParserNext.new text: TPL_URL3, domain: domain, content_type: :htm, bindable: true
|
166
|
+
parser.parse!
|
167
|
+
binder = binder_fake.new parser, context, []
|
168
|
+
assert_equal parser.render(binder), '/adminapp/article_edit/1220.json'
|
169
|
+
end
|
170
|
+
|
171
|
+
def test_api_parser
|
172
|
+
parser = Tzispa::Rig::ParserNext.new text: "#{TPL_API1} #{TPL_API2} #{TPL_API3}", domain: domain, content_type: :htm, bindable: true
|
173
|
+
parser.parse!
|
174
|
+
assert_equal parser.tokens.count, 4
|
175
|
+
assert_instance_of Tzispa::Rig::TypeToken::Api, parser.tokens[1]
|
176
|
+
assert_instance_of Tzispa::Rig::TypeToken::Api, parser.tokens[2]
|
177
|
+
assert_instance_of Tzispa::Rig::TypeToken::Api, parser.tokens[3]
|
178
|
+
assert_equal parser.tokens[1].handler, 'article'
|
179
|
+
assert_equal parser.tokens[1].verb, 'add'
|
180
|
+
assert_nil parser.tokens[1].predicate
|
181
|
+
assert_nil parser.tokens[1].app_name
|
182
|
+
assert_equal parser.tokens[2].handler, 'article'
|
183
|
+
assert_equal parser.tokens[2].verb, 'edit'
|
184
|
+
assert_equal parser.tokens[2].predicate, "#{parser.tokens[0].anchor}"
|
185
|
+
assert_equal parser.tokens[2].app_name, :adminapp
|
186
|
+
assert_equal parser.tokens[3].handler, 'order'
|
187
|
+
assert_equal parser.tokens[3].verb, 'detail_sum'
|
188
|
+
assert_equal parser.tokens[3].predicate, '2016_10,2016_12'
|
189
|
+
assert_nil parser.tokens[3].app_name
|
190
|
+
end
|
191
|
+
|
192
|
+
def test_api_render
|
193
|
+
parser = Tzispa::Rig::ParserNext.new text: TPL_API1, domain: domain, content_type: :htm, bindable: true
|
194
|
+
parser.parse!
|
195
|
+
binder = binder_fake.new parser, context, []
|
196
|
+
assert_equal parser.render(binder), 'http://mytestdomainurl.com/article/add'
|
197
|
+
|
198
|
+
parser = Tzispa::Rig::ParserNext.new text: TPL_API2, domain: domain, content_type: :htm, bindable: true
|
199
|
+
parser.parse!
|
200
|
+
binder = binder_fake.new parser, context, [11999]
|
201
|
+
assert_equal parser.render(binder), 'http://admin.mytestdomainurl.com/adminapp/article/edit/11999'
|
202
|
+
|
203
|
+
sign = context.sign_array ['order', 'detail_sum', '2016_10,2016_12']
|
204
|
+
parser = Tzispa::Rig::ParserNext.new text: TPL_API3, domain: domain, content_type: :htm, bindable: true
|
205
|
+
parser.parse!
|
206
|
+
binder = binder_fake.new parser, context, []
|
207
|
+
assert_equal parser.render(binder), "http://mytestdomainurl.com/#{sign}__order/detail_sum/2016_10,2016_12"
|
208
|
+
end
|
209
|
+
|
210
|
+
|
211
|
+
def test_blk_parser
|
212
|
+
parser = Tzispa::Rig::ParserNext.new text: TPL_BLK, domain: domain, content_type: :htm, bindable: true
|
213
|
+
parser.parse!
|
214
|
+
assert_equal parser.tokens.count, 5
|
215
|
+
assert_instance_of Tzispa::Rig::TypeToken::Block, parser.tokens[1]
|
216
|
+
assert_instance_of Tzispa::Rig::TypeToken::Block, parser.tokens[2]
|
217
|
+
assert_instance_of Tzispa::Rig::TypeToken::IBlock, parser.tokens[3]
|
218
|
+
assert_instance_of Tzispa::Rig::TypeToken::IBlock, parser.tokens[4]
|
219
|
+
assert_equal parser.tokens[1].id, 'detail'
|
220
|
+
assert_equal parser.tokens[2].id, 'product@detail'
|
221
|
+
assert_equal parser.tokens[2].params, "tab=#{parser.tokens[0].anchor}"
|
222
|
+
assert_equal parser.tokens[3].id, "test"
|
223
|
+
assert_equal parser.tokens[3].id_then, "block_one"
|
224
|
+
assert_equal parser.tokens[3].id_else, 'product@block_two'
|
225
|
+
assert_equal parser.tokens[3].params_then, "select=50"
|
226
|
+
assert_nil parser.tokens[3].params_else
|
227
|
+
assert_equal parser.tokens[4].id, "test"
|
228
|
+
assert_equal parser.tokens[4].id_then, "product@block_one"
|
229
|
+
assert_equal parser.tokens[4].id_else, 'block_two'
|
230
|
+
assert_equal parser.tokens[4].params_else, "select=10"
|
231
|
+
assert_nil parser.tokens[4].params_then
|
232
|
+
end
|
233
|
+
|
234
|
+
def test_static_parser
|
235
|
+
parser = Tzispa::Rig::ParserNext.new text: TPL_STA, domain: domain, content_type: :htm, bindable: true
|
236
|
+
parser.parse!
|
237
|
+
assert_equal parser.tokens.count, 4
|
238
|
+
assert_instance_of Tzispa::Rig::TypeToken::Static, parser.tokens[1]
|
239
|
+
assert_instance_of Tzispa::Rig::TypeToken::Static, parser.tokens[2]
|
240
|
+
assert_instance_of Tzispa::Rig::TypeToken::Static, parser.tokens[3]
|
241
|
+
assert_equal parser.tokens[1].id, 'whatsnew'
|
242
|
+
assert_equal parser.tokens[2].id, 'product@whatsnew'
|
243
|
+
assert_equal parser.tokens[2].params, "section=retail"
|
244
|
+
assert_equal parser.tokens[3].id, 'product@whatsnew'
|
245
|
+
assert_equal parser.tokens[3].params, "section=#{parser.tokens[0].anchor}"
|
246
|
+
end
|
247
|
+
|
248
|
+
|
249
|
+
def teardown
|
250
|
+
all_templates.each { |tpl|
|
251
|
+
FileUtils.rm tpl.filename
|
252
|
+
}
|
253
|
+
end
|
254
|
+
|
255
|
+
|
256
|
+
end
|
@@ -0,0 +1 @@
|
|
1
|
+
This is a layout template file
|
@@ -0,0 +1,78 @@
|
|
1
|
+
require 'fileutils'
|
2
|
+
require 'test_helper'
|
3
|
+
|
4
|
+
class TemplateTest < Minitest::Test
|
5
|
+
include TemplateTestHelper
|
6
|
+
|
7
|
+
def setup
|
8
|
+
mkfile = ::File.new file.filename, "wt"
|
9
|
+
mkfile << STR_T
|
10
|
+
mkfile.close
|
11
|
+
file.load!
|
12
|
+
mklayout = ::File.new index_layout.filename, "wt"
|
13
|
+
mklayout << STR_L
|
14
|
+
mklayout.close
|
15
|
+
index_layout.load!
|
16
|
+
mkblock = ::File.new index_block.filename, "wt"
|
17
|
+
mkblock << STR_B
|
18
|
+
mkblock.close
|
19
|
+
index_block.load!
|
20
|
+
mkstatic = ::File.new index_static.filename, "wt"
|
21
|
+
mkstatic << STR_S
|
22
|
+
mkstatic.close
|
23
|
+
index_static.load!
|
24
|
+
end
|
25
|
+
|
26
|
+
def test_file
|
27
|
+
assert file.exist?
|
28
|
+
assert_equal file.content, STR_T
|
29
|
+
refute nofile.exist?
|
30
|
+
assert_raises(Tzispa::Rig::NotFound) { nofile.load! }
|
31
|
+
refute file.modified?
|
32
|
+
# to force modified file timestamp
|
33
|
+
sleep 0.3
|
34
|
+
mkfile = ::File.new file.filename, "at"
|
35
|
+
mkfile << STR_T
|
36
|
+
mkfile.close
|
37
|
+
assert file.modified?
|
38
|
+
end
|
39
|
+
|
40
|
+
def test_rig_layout
|
41
|
+
assert index_layout.exist?
|
42
|
+
assert_equal index_layout.content, STR_L
|
43
|
+
assert_equal index_layout.type, :layout
|
44
|
+
assert index_layout.layout?
|
45
|
+
refute index_layout.modified?
|
46
|
+
# to force modified file timestamp
|
47
|
+
sleep 0.3
|
48
|
+
mkfile = ::File.new index_layout.filename, "at"
|
49
|
+
mkfile << STR_L
|
50
|
+
mkfile.close
|
51
|
+
assert index_layout.modified?
|
52
|
+
assert_equal index_layout.load!.content, "#{STR_L}#{STR_L}"
|
53
|
+
end
|
54
|
+
|
55
|
+
def test_rig_block
|
56
|
+
assert index_block.exist?
|
57
|
+
assert_equal index_block.content, STR_B
|
58
|
+
assert_equal index_block.type, :block
|
59
|
+
assert index_block.block?
|
60
|
+
end
|
61
|
+
|
62
|
+
def test_rig_static
|
63
|
+
assert index_static.exist?
|
64
|
+
assert_equal index_static.content, STR_S
|
65
|
+
assert_equal index_static.type, :static
|
66
|
+
assert index_static.static?
|
67
|
+
end
|
68
|
+
|
69
|
+
def teardown
|
70
|
+
FileUtils.rm file.filename
|
71
|
+
FileUtils.rm index_layout.filename
|
72
|
+
FileUtils.rm index_block.filename
|
73
|
+
FileUtils.rm index_static.filename
|
74
|
+
end
|
75
|
+
|
76
|
+
|
77
|
+
|
78
|
+
end
|
data/test/test_helper.rb
ADDED
@@ -0,0 +1,174 @@
|
|
1
|
+
$LOAD_PATH.unshift File.expand_path('../../lib', __FILE__)
|
2
|
+
require 'tzispa_rig'
|
3
|
+
require 'minitest/autorun'
|
4
|
+
require 'tzispa/helpers/security'
|
5
|
+
|
6
|
+
|
7
|
+
module TemplateTestHelper
|
8
|
+
extend Minitest::Spec::DSL
|
9
|
+
include Tzispa::Helpers::Security
|
10
|
+
|
11
|
+
TPL_META = 'meta testing {%meta1%}\n\n {%meta1%}:{%meta2%}\n'
|
12
|
+
TPL_VAR = 'var testing <var:uno/>\n\n {%meta1%} <var:dos/> <var:uno/>:{%meta2%}\n'
|
13
|
+
TPL_LOOP = '<loop:literator> loop testing <var:uno/> <var:dos/>\n <var:uno/> </loop:literator> <var:tres/>'
|
14
|
+
TPL_IFE = '<ife:condition> ife testing <var:uno/> <var:dos/>\n </ife:condition> <ife:condition> <var:uno/> {%dos%} {%tres%} <else:condition/> <var:dos/> </ife:condition> '
|
15
|
+
TPL_URL1 = '<url:article[id=111,title=this_is_an_url_title]/>'
|
16
|
+
TPL_URL2 = '<purl:product@list[id={%idp%},title=this_is_an_url_title]/>'
|
17
|
+
TPL_URL3 = '<purl#adminapp:article_edit[id=1220,format=json]/>'
|
18
|
+
TPL_API1 = '<api:article:add/>'
|
19
|
+
TPL_API2 = '<api#adminapp:article:edit:{%idarticle%}/>'
|
20
|
+
TPL_API3 = '<sapi:order:detail_sum:2016_10,2016_12/>'
|
21
|
+
TPL_BLK = '<blk:detail/> <blk:product@detail[tab={%selected_tab%}]/> <iblk:test:block_one[select=50]:product@block_two/> <iblk:test:product@block_one:block_two[select=10]/>'
|
22
|
+
TPL_STA = '<static:whatsnew/> <static:product@whatsnew[section=retail]/> <static:product@whatsnew[section={%selected%}]/>'
|
23
|
+
|
24
|
+
|
25
|
+
FILENAME = "test/res/testfile"
|
26
|
+
STR_T = "This is a plain text file\n"
|
27
|
+
STR_P = "This is a rig template file\n"
|
28
|
+
STR_L = "This is a layout template file\n"
|
29
|
+
STR_B = "This is a block template file\n"
|
30
|
+
STR_S = "This is a static template file\n"
|
31
|
+
|
32
|
+
let(:domain_fake) {
|
33
|
+
Struct.new(:name) {
|
34
|
+
def path
|
35
|
+
"test/res/apps/#{name}"
|
36
|
+
end
|
37
|
+
|
38
|
+
def require(file)
|
39
|
+
Kernel.require "./#{path}/#{file}"
|
40
|
+
end
|
41
|
+
}
|
42
|
+
}
|
43
|
+
let(:domain) { domain_fake.new :test_domain }
|
44
|
+
let(:file) { Tzispa::Rig::File.new(FILENAME) }
|
45
|
+
let(:nofile) { Tzispa::Rig::File.new "test/res/notexistingfile" }
|
46
|
+
let(:index_layout) { Tzispa::Rig::Template.new name: 'index', type: :layout, domain: domain, content_type: 'txt' }
|
47
|
+
let(:productlist_layout) { Tzispa::Rig::Template.new name: 'product@list', type: :layout, domain: domain, content_type: 'htm' }
|
48
|
+
let(:index_block) { Tzispa::Rig::Template.new name: 'index', type: :block, domain: domain, content_type: 'txt' }
|
49
|
+
let(:index_static) { Tzispa::Rig::Template.new name: 'index', type: :static, domain: domain, content_type: 'txt' }
|
50
|
+
let(:detail_block) { Tzispa::Rig::Template.new name: 'detail', type: :block, domain: domain, content_type: :htm }
|
51
|
+
let(:product_detail_block) { Tzispa::Rig::Template.new name: 'product@detail', type: :block, domain: domain, content_type: :htm }
|
52
|
+
let(:block_one) { Tzispa::Rig::Template.new name: 'block_one', type: :block, domain: domain, content_type: :htm }
|
53
|
+
let(:product_block_two) { Tzispa::Rig::Template.new name: 'product@block_two', type: :block, domain: domain, content_type: :htm }
|
54
|
+
let(:product_block_one) { Tzispa::Rig::Template.new name: 'product@block_one', type: :block, domain: domain, content_type: :htm }
|
55
|
+
let(:block_two) { Tzispa::Rig::Template.new name: 'block_two', type: :block, domain: domain, content_type: :htm }
|
56
|
+
let(:whatsnew_static) { Tzispa::Rig::Template.new name: 'whatsnew', type: :static, domain: domain, content_type: :htm }
|
57
|
+
let(:product_whatsnew_static) { Tzispa::Rig::Template.new name: 'product@whatsnew', type: :static, domain: domain, content_type: :htm }
|
58
|
+
let(:all_templates) { [detail_block, product_detail_block, block_one, product_block_two, product_block_one, block_two, whatsnew_static, product_whatsnew_static] }
|
59
|
+
|
60
|
+
let(:binder_fake) {
|
61
|
+
Struct.new(:parser, :context, :values) {
|
62
|
+
def data_struct
|
63
|
+
parser.attribute_tags.count > 0 ? Struct.new(*parser.attribute_tags) : Struct.new(nil)
|
64
|
+
end
|
65
|
+
|
66
|
+
def data
|
67
|
+
data_struct.new(*values)
|
68
|
+
end
|
69
|
+
}
|
70
|
+
}
|
71
|
+
|
72
|
+
let(:config_fake) {
|
73
|
+
Struct.new(:canonical_url)
|
74
|
+
}
|
75
|
+
|
76
|
+
let(:app_fake) {
|
77
|
+
Struct.new(:config)
|
78
|
+
}
|
79
|
+
|
80
|
+
let(:context_fake) {
|
81
|
+
Struct.new(:app, :applications, :salt) {
|
82
|
+
|
83
|
+
def layout_path(layout, params={})
|
84
|
+
String.new.tap { |path|
|
85
|
+
path << "/#{layout}"
|
86
|
+
path << "/#{params[:title]}" if params[:title]
|
87
|
+
user_params = params.reject { |k,v| k == :title || k == :format}
|
88
|
+
path << "/#{user_params.values.join('__')}" if user_params.size > 0
|
89
|
+
path << ".#{params[:format]}" if params[:format]
|
90
|
+
}
|
91
|
+
end
|
92
|
+
|
93
|
+
def app_layout_path(app_name, layout, params={})
|
94
|
+
String.new.tap { |path|
|
95
|
+
path << "/#{app_name}"
|
96
|
+
path << "/#{layout}"
|
97
|
+
path << "/#{params[:title]}" if params[:title]
|
98
|
+
user_params = params.reject { |k,v| k == :title || k == :format}
|
99
|
+
path << "/#{user_params.values.join('__')}" if user_params.size > 0
|
100
|
+
path << ".#{params[:format]}" if params[:format]
|
101
|
+
}
|
102
|
+
end
|
103
|
+
|
104
|
+
def layout_canonical_url(layout, params={})
|
105
|
+
String.new.tap { |path|
|
106
|
+
path << "#{app.config.canonical_url}"
|
107
|
+
path << "/#{layout}"
|
108
|
+
path << "/#{params[:title]}" if params[:title]
|
109
|
+
user_params = params.reject { |k,v| k == :title || k == :format}
|
110
|
+
path << "/#{user_params.values.join('__')}" if user_params.size > 0
|
111
|
+
path << ".#{params[:format]}" if params[:format]
|
112
|
+
}
|
113
|
+
end
|
114
|
+
|
115
|
+
def app_layout_canonical_url(app_name, layout, params={})
|
116
|
+
String.new.tap { |path|
|
117
|
+
path << "#{applications[app_name].config.canonical_url}"
|
118
|
+
path << "/#{app_name}"
|
119
|
+
path << "/#{layout}"
|
120
|
+
path << "/#{params[:title]}" if params[:title]
|
121
|
+
user_params = params.reject { |k,v| k == :title || k == :format}
|
122
|
+
path << "/#{user_params.values.join('__')}" if user_params.size > 0
|
123
|
+
path << ".#{params[:format]}" if params[:format]
|
124
|
+
}
|
125
|
+
end
|
126
|
+
|
127
|
+
def api(handler, verb, predicate, sufix, app_name = nil)
|
128
|
+
String.new.tap { |path|
|
129
|
+
path << (app_name ?
|
130
|
+
"#{applications[app_name].config.canonical_url}" :
|
131
|
+
"#{app.config.canonical_url}")
|
132
|
+
path << "/#{app_name}" if app_name
|
133
|
+
path << "/#{handler}/#{verb}"
|
134
|
+
path << "/#{predicate}" if predicate
|
135
|
+
path << ".#{sufix}" if sufix
|
136
|
+
}
|
137
|
+
end
|
138
|
+
|
139
|
+
def sapi(handler, verb, predicate, sufix, app_name = nil)
|
140
|
+
sign = sign_array [handler, verb, predicate]
|
141
|
+
String.new.tap { |path|
|
142
|
+
path << (app_name ? "#{applications[app_name].config.canonical_url}" : "#{app.config.canonical_url}")
|
143
|
+
path << "/#{app_name}" if app_name
|
144
|
+
path << "/#{sign}__#{handler}/#{verb}"
|
145
|
+
path << "/#{predicate}" if predicate
|
146
|
+
path << ".#{sufix}" if sufix
|
147
|
+
}
|
148
|
+
end
|
149
|
+
|
150
|
+
def sign_array(astr)
|
151
|
+
sign, i = String.new, 0
|
152
|
+
astr.each { |s|
|
153
|
+
i = i + 1
|
154
|
+
sign << "#{"_"*i}#{s}"
|
155
|
+
}
|
156
|
+
sign << "**#{salt}"
|
157
|
+
Digest::SHA1.hexdigest sign
|
158
|
+
end
|
159
|
+
}
|
160
|
+
}
|
161
|
+
|
162
|
+
let(:context) {
|
163
|
+
cfg_main = config_fake.new 'http://mytestdomainurl.com'
|
164
|
+
cfg_admin = config_fake.new 'http://admin.mytestdomainurl.com'
|
165
|
+
app_main = app_fake.new cfg_main
|
166
|
+
app_admin = app_fake.new cfg_admin
|
167
|
+
applications = {
|
168
|
+
main: app_main,
|
169
|
+
adminapp: app_admin
|
170
|
+
}
|
171
|
+
context_fake.new app_main, applications, 'qwertyuiop0987654321'
|
172
|
+
}
|
173
|
+
|
174
|
+
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: tzispa_rig
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.5.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Juan Antonio Piñero
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2017-02-13 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: tzispa_utils
|
@@ -16,14 +16,14 @@ dependencies:
|
|
16
16
|
requirements:
|
17
17
|
- - "~>"
|
18
18
|
- !ruby/object:Gem::Version
|
19
|
-
version: 0.
|
19
|
+
version: '0.3'
|
20
20
|
type: :runtime
|
21
21
|
prerelease: false
|
22
22
|
version_requirements: !ruby/object:Gem::Requirement
|
23
23
|
requirements:
|
24
24
|
- - "~>"
|
25
25
|
- !ruby/object:Gem::Version
|
26
|
-
version: 0.
|
26
|
+
version: '0.3'
|
27
27
|
- !ruby/object:Gem::Dependency
|
28
28
|
name: lru_redux
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
@@ -38,6 +38,20 @@ dependencies:
|
|
38
38
|
- - "~>"
|
39
39
|
- !ruby/object:Gem::Version
|
40
40
|
version: '1.1'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: minitest
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '5.0'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '5.0'
|
41
55
|
description: General purpose template engine
|
42
56
|
email:
|
43
57
|
- japinero@area-integral.com
|
@@ -47,6 +61,7 @@ extra_rdoc_files: []
|
|
47
61
|
files:
|
48
62
|
- CHANGELOG.md
|
49
63
|
- README.md
|
64
|
+
- Rakefile
|
50
65
|
- lib/tzispa/rig.rb
|
51
66
|
- lib/tzispa/rig/binder.rb
|
52
67
|
- lib/tzispa/rig/engine.rb
|
@@ -54,8 +69,19 @@ files:
|
|
54
69
|
- lib/tzispa/rig/parsernext.rb
|
55
70
|
- lib/tzispa/rig/syntax.rb
|
56
71
|
- lib/tzispa/rig/template.rb
|
72
|
+
- lib/tzispa/rig/token.rb
|
73
|
+
- lib/tzispa/rig/type_token/api_url.rb
|
74
|
+
- lib/tzispa/rig/type_token/block.rb
|
75
|
+
- lib/tzispa/rig/type_token/expression.rb
|
76
|
+
- lib/tzispa/rig/type_token/statement.rb
|
57
77
|
- lib/tzispa/rig/version.rb
|
58
78
|
- lib/tzispa_rig.rb
|
79
|
+
- test/engine_test.rb
|
80
|
+
- test/parameters_test.rb
|
81
|
+
- test/parsernext_test.rb
|
82
|
+
- test/res/apps/test_domain/view/product/layout/list.rig.htm
|
83
|
+
- test/template_test.rb
|
84
|
+
- test/test_helper.rb
|
59
85
|
homepage: https://github.com/japiber/tzispa_rig
|
60
86
|
licenses:
|
61
87
|
- MIT
|
@@ -76,7 +102,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
76
102
|
version: '0'
|
77
103
|
requirements: []
|
78
104
|
rubyforge_project:
|
79
|
-
rubygems_version: 2.
|
105
|
+
rubygems_version: 2.6.10
|
80
106
|
signing_key:
|
81
107
|
specification_version: 4
|
82
108
|
summary: General purpose template engine
|