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 +4 -4
- data/CHANGELOG.md +5 -0
- data/README.md +1 -1
- data/lib/tzispa/rig/binder.rb +26 -5
- data/lib/tzispa/rig/engine.rb +4 -8
- data/lib/tzispa/rig/version.rb +1 -1
- metadata +6 -6
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: fa5e5300f16c59b1d36a54cb61457d7f27d73db7
|
4
|
+
data.tar.gz: 6253800420d94b93692dee73102c8accdd9cafe5
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
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
data/lib/tzispa/rig/binder.rb
CHANGED
@@ -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
|
-
|
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)
|
data/lib/tzispa/rig/engine.rb
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
require 'singleton'
|
3
3
|
require 'digest'
|
4
|
-
require '
|
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 =
|
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
|
data/lib/tzispa/rig/version.rb
CHANGED
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.
|
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-
|
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:
|
28
|
+
name: moneta
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
30
30
|
requirements:
|
31
31
|
- - "~>"
|
32
32
|
- !ruby/object:Gem::Version
|
33
|
-
version: '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.
|
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.
|
106
|
+
rubygems_version: 2.6.11
|
107
107
|
signing_key:
|
108
108
|
specification_version: 4
|
109
109
|
summary: General purpose template engine
|