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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 3abd2ac7d760cd2cabf17104393e729d9a6c8684
4
- data.tar.gz: c45a9e6387937ec48211955a0c4615012197984d
3
+ metadata.gz: 8c7fc4d4373f601d2153eb629fa2cbd150ce1f2c
4
+ data.tar.gz: 179daf386ee3851db47dfc3808667bd9dae5acfd
5
5
  SHA512:
6
- metadata.gz: bf14d442886539737944870b6d9e7d8b1e667548c19d151848eda5f07d967f9924e12a6089aa095b014d26c226812fd135590bd790256d2bdf96febca5562aba
7
- data.tar.gz: 920da35422db633d62f89ef19cc53456f2b95ce0124bc5303bca3ab1c7b76a4f451a8675f7e4fbd495a135633416ca43e69dc97c26cce31a79dec68b0eadf490
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 = context.repository[:brand, :ecomm_shop][idb]
72
- data(
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
- data.customer_exist = !customer.nil?
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
- data.lbrands = loop_binder(:lbrands).bind!(&load_brands)
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
- context.repository[:brand, :ecomm_shop].list.map { |b|
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
- <static:footer/>
269
+ <blk:widget.footer/>
266
270
  <static:footscripts/>
267
271
  </body>
268
272
  </html>
data/Rakefile ADDED
@@ -0,0 +1,7 @@
1
+ # file: Rakefile
2
+ require 'rake/testtask'
3
+
4
+ Rake::TestTask.new do |task|
5
+ task.libs << %w(test)
6
+ task.pattern = 'test/*_test.rb'
7
+ end
@@ -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, :tags, :parser
16
+ attr_reader :context, :data_struct, :parser
18
17
  def_delegators :@parser, :attribute_tags
19
- def_delegators :@context, :app, :request, :response, :session, :router_params, :not_found
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(**params)
73
- (@data ||= @data_struct.new).tap { |d|
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
@@ -1,61 +1,73 @@
1
1
  # frozen_string_literal: true
2
-
3
- require 'tzispa/rig'
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
- attr_reader :app
13
+ @@cache_size = 512
14
+ @@cache_ttl = 600 # 10 mins
13
15
 
14
- def initialize(app, cache_enabled, cache_size)
15
- @app = app
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
- def layout(name:, format:nil, params:nil)
20
- rig_template name, :layout, format, params, nil
21
- end
20
+ class << self
22
21
 
23
- def block(name:, format:nil, params:nil, parent:nil)
24
- rig_template name, :block, format, params, parent
25
- end
22
+ def empty
23
+ TemplateBase.new
24
+ end
26
25
 
27
- def static(name:, format:nil, params:nil, parent:nil)
28
- rig_template name, :static, format, params, parent
29
- end
26
+ def layout(name:, domain:, content_type:, params:nil)
27
+ rig_template name, domain, :layout, content_type, params
28
+ end
30
29
 
31
- def rig_template(name, type, tpl_format, params, parent)
32
- if @cache
33
- cache_template(name, type, tpl_format, params, parent)
34
- else
35
- Template.new(name: name, type: type, format: tpl_format, domain: @app.domain, params: params, parent: parent, engine: self).load!.parse!
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, type, tpl_format, params, parent)
42
- key = "#{type}__#{name}".to_sym
43
- (get_template(key, name, type, tpl_format, parent) || set_template(key, name, type, tpl_format, parent)).dup.tap { |ctpl|
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, type, tpl_format, parent)
49
- if @cache.key?(key) && (@cache[key].modified? || !@cache[key].valid?)
50
- set_template(key, name, type, tpl_format, parent)
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
- def set_template(key, name, type, tpl_format, parent)
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 set(key,value)
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