tzispa_rig 0.5.1 → 0.5.2

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: b0ee09cd6bcb8f16477ec4472fe2442599db939d
4
- data.tar.gz: a168edea1da7db3d372b37ca97bbbb58b6adb3ef
3
+ metadata.gz: fa5e5300f16c59b1d36a54cb61457d7f27d73db7
4
+ data.tar.gz: 6253800420d94b93692dee73102c8accdd9cafe5
5
5
  SHA512:
6
- metadata.gz: 272a50312a02d4455a1701d12a27270fc01523ee03cd61c85fbd7609875671bbf5885f9c942f96b5f825e131174886cefcec3813e82db66b5a13bdf7a5f3c0d6
7
- data.tar.gz: d67f6a12863368644c24a2988e223972ffe5ce6c20cfe0d7632369096f6f1e5d1865e469c6afc57a6e10dc532d0561c8668d8e3c3e0f4342c2339dcd08bd616a
6
+ metadata.gz: 21d4d0c0e55ffea5ef20a6cef84fb5e47e14ac8af437c87e6bdeef7fb042108c449dd21c8b765c988345c3af10066b242a3147aaac8dccf02dce5e1840a1fb13
7
+ data.tar.gz: dbc9b3e8095d7115fd33889892dd8963acf644db99394b72108953120a4f870d41c10eee72372e5a8fdd59c19e67638b2b3d817d3b1aa7b63e9a49796555b336
data/CHANGELOG.md CHANGED
@@ -2,6 +2,11 @@ Tzispa Rig
2
2
 
3
3
  Rig templates implementation
4
4
 
5
+ ## v0.5.2
6
+ - replace lru_redux with moneta to improve template cache storage
7
+ - added fallback to super in method_missing at LoopBinder
8
+ - support for bind data from json
9
+
5
10
  ## v0.5.1
6
11
  - Bug fixes and code refactoring
7
12
 
data/README.md CHANGED
@@ -1,6 +1,6 @@
1
1
  # Tzispa Rig
2
2
 
3
- A general purpose template engine
3
+ Lego-block style general purpose template engine
4
4
 
5
5
  ## Installation
6
6
 
@@ -1,6 +1,8 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  require 'forwardable'
4
+ require 'json'
5
+ require 'tzispa/utils/hash'
4
6
 
5
7
  module Tzispa
6
8
  module Rig
@@ -88,6 +90,8 @@ module Tzispa
88
90
  class TemplateBinder < Binder
89
91
  extend Forwardable
90
92
 
93
+ using Tzispa::Utils::TzHash
94
+
91
95
  attr_reader :template
92
96
  def_delegators :@template, :params
93
97
 
@@ -100,15 +104,28 @@ module Tzispa
100
104
  @data ||= @data_struct.new
101
105
  end
102
106
 
103
- def attach(**params)
107
+ def attach(json = nil, **params)
108
+ attach_json(json) if json
104
109
  data.tap do |d|
105
110
  params.each do |k, v|
106
111
  raise UnknownTag.new(self.class.name, k) unless tags.include? k
107
- d[k] = v
112
+ d[k] = v.is_a?(Enumerable) ? attach_loop(k, v) : v
108
113
  end
109
114
  end
110
115
  end
111
116
 
117
+ def attach_json(data)
118
+ src = JSON.parse(data).symbolize!
119
+ attach(src.reject { |_, v| v.is_a?(Array) || v.is_a?(::Hash) })
120
+ attach(src.select { |_, v| v.is_a?(Array) }.map do |k, v|
121
+ [k, attach_loop(k, v)]
122
+ end.to_h)
123
+ end
124
+
125
+ def attach_loop(k, v)
126
+ loop_binder(k).bind! { v.map { |item| loop_item item.symbolize! } }
127
+ end
128
+
112
129
  def self.for(template, context)
113
130
  if template.bindable?
114
131
  binder_class = template.binder_class
@@ -131,11 +148,15 @@ module Tzispa
131
148
  end
132
149
 
133
150
  def method_missing(method, *args, &generator)
134
- @source_object.send(method, *args, &generator)
151
+ if respond_to_missing? method
152
+ @source_object.send(method, *args, &generator)
153
+ else
154
+ super
155
+ end
135
156
  end
136
157
 
137
- def respond_to_missing?(method, *)
138
- @source_object.respond_to?(method)
158
+ def respond_to_missing?(method)
159
+ @source_object.respond_to?(method, true)
139
160
  end
140
161
 
141
162
  def loop_item(params = nil)
@@ -1,7 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
  require 'singleton'
3
3
  require 'digest'
4
- require 'lru_redux'
4
+ require 'moneta'
5
5
  require 'tzispa/rig/template'
6
6
 
7
7
  module Tzispa
@@ -10,16 +10,12 @@ module Tzispa
10
10
  class Engine
11
11
  include Singleton
12
12
 
13
- @cache_size = 512
14
- @cache_ttl = 600
15
-
16
13
  def initialize
17
- @cache = LruRedux::TTL::ThreadSafeCache.new(Engine.cache_size, Engine.cache_ttl)
14
+ @cache = Moneta.new(:LRUHash, threadsafe: true)
15
+ # @cache = LruRedux::TTL::ThreadSafeCache.new(Engine.cache_size, Engine.cache_ttl)
18
16
  end
19
17
 
20
18
  class << self
21
- attr_accessor :cache_size, :cache_ttl
22
-
23
19
  def empty
24
20
  TemplateBase.new
25
21
  end
@@ -44,7 +40,7 @@ module Tzispa
44
40
  private
45
41
 
46
42
  def cache_template(name, domain, block_type, content_type, params)
47
- key = "#{domain}/#{block_type}/#{name}/#{content_type}".to_sym
43
+ key = "#{domain.name}/#{block_type}/#{name}/#{content_type}".to_sym
48
44
  get_template(key, name, domain, block_type, content_type).dup.tap do |ctpl|
49
45
  ctpl.params = params if params
50
46
  end
@@ -3,7 +3,7 @@
3
3
  module Tzispa
4
4
  module Rig
5
5
 
6
- VERSION = '0.5.1'
6
+ VERSION = '0.5.2'
7
7
  GEM_NAME = 'tzispa_rig'
8
8
 
9
9
  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.5.1
4
+ version: 0.5.2
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: 2017-03-13 00:00:00.000000000 Z
11
+ date: 2017-04-21 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: tzispa_utils
@@ -25,19 +25,19 @@ dependencies:
25
25
  - !ruby/object:Gem::Version
26
26
  version: '0.3'
27
27
  - !ruby/object:Gem::Dependency
28
- name: lru_redux
28
+ name: moneta
29
29
  requirement: !ruby/object:Gem::Requirement
30
30
  requirements:
31
31
  - - "~>"
32
32
  - !ruby/object:Gem::Version
33
- version: '1.1'
33
+ version: '1.0'
34
34
  type: :runtime
35
35
  prerelease: false
36
36
  version_requirements: !ruby/object:Gem::Requirement
37
37
  requirements:
38
38
  - - "~>"
39
39
  - !ruby/object:Gem::Version
40
- version: '1.1'
40
+ version: '1.0'
41
41
  - !ruby/object:Gem::Dependency
42
42
  name: minitest
43
43
  requirement: !ruby/object:Gem::Requirement
@@ -103,7 +103,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
103
103
  version: '0'
104
104
  requirements: []
105
105
  rubyforge_project:
106
- rubygems_version: 2.6.10
106
+ rubygems_version: 2.6.11
107
107
  signing_key:
108
108
  specification_version: 4
109
109
  summary: General purpose template engine