tzispa_rig 0.4.5 → 0.5.0
Sign up to get free protection for your applications and to get access to all the features.
- 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
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 8c7fc4d4373f601d2153eb629fa2cbd150ce1f2c
|
4
|
+
data.tar.gz: 179daf386ee3851db47dfc3808667bd9dae5acfd
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 0b42740653389d7d04833dc5e90ccdfff3d6316ef35eb790fe748f928f0602ef29ea4ed2573b6ef2ec86954aea73e9a3ac92968210cd4f59bb6d7418cc4e5649
|
7
|
+
data.tar.gz: ffe72dfc14733a083980078d497cc1ca315935de5019a97d2b7e6a457931e635807a9d00b17e47035bc4a93d0f363ced286201c01abc992e258eac4afa87a733
|
data/CHANGELOG.md
CHANGED
@@ -2,6 +2,16 @@ Tzispa Rig
|
|
2
2
|
|
3
3
|
Rig templates implementation
|
4
4
|
|
5
|
+
## v0.5.0
|
6
|
+
- Rig templates syntax changes in url/purl and blk/iblk/static
|
7
|
+
- Added support for subdoamins in layouts
|
8
|
+
- new rig engine interface now shared by all apps
|
9
|
+
- added some testing with minitest
|
10
|
+
- escape (by content type) var tags values before render
|
11
|
+
- allow recursive template block calls
|
12
|
+
- code refactoring & templates namespace simplification
|
13
|
+
- rig-parser implementation improvements
|
14
|
+
|
5
15
|
## v0.4.5
|
6
16
|
- code fixes for replacing TzString with String refinement
|
7
17
|
|
data/README.md
CHANGED
@@ -68,8 +68,8 @@ private
|
|
68
68
|
attr_reader :idb
|
69
69
|
|
70
70
|
def load_brand
|
71
|
-
brand =
|
72
|
-
|
71
|
+
brand = repository[:brand, :ecomm_shop][idb]
|
72
|
+
attach(
|
73
73
|
idb: brand.id,
|
74
74
|
name: brand.name,
|
75
75
|
skey: brand.skey
|
@@ -111,7 +111,9 @@ In the binder you must define customer_exist
|
|
111
111
|
def bind!
|
112
112
|
idc = context.router_params[:id0]
|
113
113
|
customer = context.repository[:customer, :ecomm_shop][idb]
|
114
|
-
|
114
|
+
attach(
|
115
|
+
customer_exist: !customer.nil?
|
116
|
+
)
|
115
117
|
end
|
116
118
|
|
117
119
|
```
|
@@ -141,14 +143,16 @@ In the binder you must use the 'loop_binder' method
|
|
141
143
|
```ruby
|
142
144
|
|
143
145
|
def bind!
|
144
|
-
|
146
|
+
attach(
|
147
|
+
lbrands: loop_binder(:lbrands).bind!(&load_brands)
|
148
|
+
)
|
145
149
|
end
|
146
150
|
|
147
151
|
private
|
148
152
|
|
149
153
|
def load_brands
|
150
154
|
Proc.new {
|
151
|
-
|
155
|
+
repository[:brand, :ecomm_shop].list.map { |b|
|
152
156
|
loop_item(
|
153
157
|
id: b.id,
|
154
158
|
skey: b.skey,
|
@@ -262,7 +266,7 @@ You can also use template subdomains using dot notation in the name
|
|
262
266
|
</div>
|
263
267
|
</div>
|
264
268
|
</div>
|
265
|
-
<
|
269
|
+
<blk:widget.footer/>
|
266
270
|
<static:footscripts/>
|
267
271
|
</body>
|
268
272
|
</html>
|
data/Rakefile
ADDED
data/lib/tzispa/rig/binder.rb
CHANGED
@@ -1,7 +1,6 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
3
|
require 'forwardable'
|
4
|
-
require 'tzispa/rig'
|
5
4
|
|
6
5
|
module Tzispa
|
7
6
|
module Rig
|
@@ -14,10 +13,11 @@ module Tzispa
|
|
14
13
|
class Binder
|
15
14
|
extend Forwardable
|
16
15
|
|
17
|
-
attr_reader :context, :data_struct, :
|
16
|
+
attr_reader :context, :data_struct, :parser
|
18
17
|
def_delegators :@parser, :attribute_tags
|
19
|
-
def_delegators :@context, :app, :request, :response, :session, :router_params, :
|
18
|
+
def_delegators :@context, :app, :request, :response, :session, :router_params, :cache
|
20
19
|
def_delegators :app, :repository, :config, :logger
|
20
|
+
alias :tags :attribute_tags
|
21
21
|
|
22
22
|
|
23
23
|
def initialize(parser, context)
|
@@ -26,8 +26,6 @@ module Tzispa
|
|
26
26
|
@data_struct = attribute_tags.count > 0 ? Struct.new(*attribute_tags) : Struct.new(nil)
|
27
27
|
end
|
28
28
|
|
29
|
-
alias :tags :attribute_tags
|
30
|
-
|
31
29
|
# Gets a LoopBinder context for the given loop_id in a rig template
|
32
30
|
#
|
33
31
|
# .... <var:myvar/> ...
|
@@ -54,6 +52,12 @@ module Tzispa
|
|
54
52
|
LoopBinder.new loop_parser[0], @context
|
55
53
|
end
|
56
54
|
|
55
|
+
def attr_cache(*attrs)
|
56
|
+
attrs.each { |attrib|
|
57
|
+
cache[attrib] = send(attrib) if respond_to?(attrib)
|
58
|
+
}
|
59
|
+
end
|
60
|
+
|
57
61
|
end
|
58
62
|
|
59
63
|
|
@@ -69,8 +73,12 @@ module Tzispa
|
|
69
73
|
@template = template
|
70
74
|
end
|
71
75
|
|
72
|
-
def data
|
73
|
-
|
76
|
+
def data
|
77
|
+
@data ||= @data_struct.new
|
78
|
+
end
|
79
|
+
|
80
|
+
def attach(**params)
|
81
|
+
data.tap { |d|
|
74
82
|
params.each{ |k,v|
|
75
83
|
raise UnknownTag.new "#{k} is not a tag in #{self.class.name}" unless tags.include? k
|
76
84
|
d[k] = v
|
data/lib/tzispa/rig/engine.rb
CHANGED
@@ -1,61 +1,73 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
|
-
|
3
|
-
require '
|
2
|
+
require 'singleton'
|
3
|
+
require 'digest'
|
4
4
|
require 'lru_redux'
|
5
|
-
|
5
|
+
require 'tzispa/rig/template'
|
6
6
|
|
7
7
|
module Tzispa
|
8
8
|
module Rig
|
9
9
|
|
10
10
|
class Engine
|
11
|
+
include Singleton
|
11
12
|
|
12
|
-
|
13
|
+
@@cache_size = 512
|
14
|
+
@@cache_ttl = 600 # 10 mins
|
13
15
|
|
14
|
-
def initialize
|
15
|
-
@
|
16
|
-
@cache = LruRedux::ThreadSafeCache.new(cache_size) if cache_enabled
|
16
|
+
def initialize
|
17
|
+
@cache = LruRedux::TTL::ThreadSafeCache.new(@@cache_size, @@cache_ttl)
|
17
18
|
end
|
18
19
|
|
19
|
-
|
20
|
-
rig_template name, :layout, format, params, nil
|
21
|
-
end
|
20
|
+
class << self
|
22
21
|
|
23
|
-
|
24
|
-
|
25
|
-
|
22
|
+
def empty
|
23
|
+
TemplateBase.new
|
24
|
+
end
|
26
25
|
|
27
|
-
|
28
|
-
|
29
|
-
|
26
|
+
def layout(name:, domain:, content_type:, params:nil)
|
27
|
+
rig_template name, domain, :layout, content_type, params
|
28
|
+
end
|
30
29
|
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
30
|
+
def block(name:, domain:, content_type:, params:nil)
|
31
|
+
rig_template name, domain, :block, content_type, params
|
32
|
+
end
|
33
|
+
|
34
|
+
def static(name:, domain:, content_type:, params:nil)
|
35
|
+
rig_template name, domain, :static, content_type, params
|
36
|
+
end
|
37
|
+
|
38
|
+
def rig_template(name, domain, block_type, content_type, params)
|
39
|
+
instance.send(:cache_template, name, domain, block_type, content_type, params)
|
40
|
+
end
|
41
|
+
|
42
|
+
def cache_size=(sz)
|
43
|
+
@@cache_size = sz
|
36
44
|
end
|
45
|
+
|
46
|
+
def cache_ttl=(seconds)
|
47
|
+
@@cache_ttl = seconds
|
48
|
+
end
|
49
|
+
|
37
50
|
end
|
38
51
|
|
39
52
|
private
|
40
53
|
|
41
|
-
def cache_template(name,
|
42
|
-
key = "#{
|
43
|
-
|
54
|
+
def cache_template(name, domain, block_type, content_type, params)
|
55
|
+
key = "#{domain}/#{block_type}/#{name}/#{content_type}".to_sym
|
56
|
+
get_template(key, name, domain, block_type, content_type).dup.tap { |ctpl|
|
44
57
|
ctpl.params = params if params
|
45
|
-
|
58
|
+
}
|
46
59
|
end
|
47
60
|
|
48
|
-
def get_template(key, name,
|
49
|
-
if @cache.key?(key) && (@cache[key].modified? || !@cache[key].valid?)
|
50
|
-
set_template(key, name,
|
61
|
+
def get_template(key, name, domain, block_type, content_type)
|
62
|
+
if !@cache.key?(key) || @cache.key?(key) && (@cache[key].modified? || !@cache[key].valid?)
|
63
|
+
set_template(key, name, domain, block_type, content_type)
|
51
64
|
else
|
52
65
|
@cache[key]
|
53
66
|
end
|
54
67
|
end
|
55
68
|
|
56
|
-
|
57
|
-
|
58
|
-
@cache[key] = Template.new(name: name, type: type, format: tpl_format, domain: @app.domain, parent: parent, engine: self).load!.parse!
|
69
|
+
def set_template(key, name, domain, block_type, content_type)
|
70
|
+
@cache[key] = Template.new(name: name, type: block_type, domain: domain, content_type: content_type).load!.parse!
|
59
71
|
end
|
60
72
|
|
61
73
|
end
|
@@ -14,16 +14,12 @@ module Tzispa
|
|
14
14
|
setData(params) if params
|
15
15
|
end
|
16
16
|
|
17
|
-
def
|
18
|
-
@data[key.to_sym] = value
|
19
|
-
end
|
20
|
-
|
21
|
-
def get(key)
|
17
|
+
def [](key)
|
22
18
|
@data[key.to_sym]
|
23
19
|
end
|
24
20
|
|
25
|
-
def [](key)
|
26
|
-
@data[key.to_sym]
|
21
|
+
def []=(key, value)
|
22
|
+
@data[key.to_sym] = value
|
27
23
|
end
|
28
24
|
|
29
25
|
def has?(key)
|
@@ -35,7 +31,7 @@ module Tzispa
|
|
35
31
|
end
|
36
32
|
|
37
33
|
def to_h
|
38
|
-
@data
|
34
|
+
@data.dup
|
39
35
|
end
|
40
36
|
|
41
37
|
alias_method :data, :to_h
|