tzispa_rig 0.2.8 → 0.2.9
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 +4 -0
- data/lib/tzispa/rig/engine.rb +63 -0
- data/lib/tzispa/rig/parsernext.rb +4 -0
- data/lib/tzispa/rig/template.rb +8 -45
- data/lib/tzispa/rig/version.rb +1 -1
- data/lib/tzispa/rig.rb +4 -3
- metadata +17 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 6afaf56cd198b00340644368828a0727b3da7bb8
|
4
|
+
data.tar.gz: ebb745a0b564a73834c87b51d992c1db2726e818
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 6c702cc00b5efcc7850ee465003c147b87790c13b30b0ed84f1d53254cf97a16544e3bdb3dd41de9b8545faa15c7fb40e92244690fcd3c4dd9c3778e205b0549
|
7
|
+
data.tar.gz: c4b39a521c21fc2ba7e6fba446d079ed207555d76e407f16523c6a831cf1c6f95f07867ff6f0262890c64ee41b18aaaf64032f6ba8b6786085ee9d6ee667ea34
|
data/CHANGELOG.md
CHANGED
@@ -2,6 +2,10 @@ Tzispa Rig
|
|
2
2
|
|
3
3
|
Rig templates implementation
|
4
4
|
|
5
|
+
## v0.2.9
|
6
|
+
- Fix bugs in template cache engine causing modified template files are not reloading
|
7
|
+
- Replaces Tzispa::Utils::Cache with lru_redex gem
|
8
|
+
|
5
9
|
## v0.2.7
|
6
10
|
- Add url template tag to build canonical urls
|
7
11
|
|
@@ -0,0 +1,63 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'tzispa/rig'
|
4
|
+
require 'lru_redux'
|
5
|
+
|
6
|
+
|
7
|
+
module Tzispa
|
8
|
+
module Rig
|
9
|
+
|
10
|
+
class Engine
|
11
|
+
|
12
|
+
attr_reader :app
|
13
|
+
|
14
|
+
def initialize(app, cache_enabled, cache_size)
|
15
|
+
@app = app
|
16
|
+
@cache = LruRedux::Cache.new(cache_size) if cache_enabled
|
17
|
+
@mutex = Mutex.new
|
18
|
+
end
|
19
|
+
|
20
|
+
def layout(name:, format:nil, params:nil)
|
21
|
+
rig_template name, :layout, format, params, nil
|
22
|
+
end
|
23
|
+
|
24
|
+
def block(name:, format:nil, params:nil, parent:nil)
|
25
|
+
rig_template name, :block, format, params, parent
|
26
|
+
end
|
27
|
+
|
28
|
+
def static(name:, format:nil, params:nil, parent:nil)
|
29
|
+
rig_template name, :static, format, params, parent
|
30
|
+
end
|
31
|
+
|
32
|
+
def rig_template(name, type, tpl_format, params, parent)
|
33
|
+
if @cache
|
34
|
+
if @mutex.owned?
|
35
|
+
cache_template(name, type, tpl_format, params, parent)
|
36
|
+
else
|
37
|
+
@mutex.synchronize {
|
38
|
+
cache_template(name, type, tpl_format, params, parent)
|
39
|
+
}
|
40
|
+
end
|
41
|
+
else
|
42
|
+
Template.new(name: name, type: type, format: format, domain: @app.domain, params: params, parent: parent, engine: self).load!.parse!
|
43
|
+
end
|
44
|
+
end
|
45
|
+
|
46
|
+
private
|
47
|
+
|
48
|
+
def cache_template(name, type, tpl_format, params, parent)
|
49
|
+
ktpl = "#{type}__#{name}".to_sym
|
50
|
+
tpl = @cache.getset(ktpl) {
|
51
|
+
Template.new(name: name, type: type, format: tpl_format, domain: @app.domain, params: params, parent: parent, engine: self).load!.parse!
|
52
|
+
}
|
53
|
+
if tpl.modified?
|
54
|
+
@cache[ktpl] = tpl.load!.parse!
|
55
|
+
else
|
56
|
+
tpl
|
57
|
+
end
|
58
|
+
end
|
59
|
+
|
60
|
+
end
|
61
|
+
|
62
|
+
end
|
63
|
+
end
|
@@ -245,6 +245,7 @@ module Tzispa
|
|
245
245
|
|
246
246
|
def parse!
|
247
247
|
@parsed_block = template.engine.block name: @id, parent: template
|
248
|
+
template.childrens << @parsed_block
|
248
249
|
self
|
249
250
|
end
|
250
251
|
|
@@ -277,6 +278,8 @@ module Tzispa
|
|
277
278
|
def parse!
|
278
279
|
@block_then = template.engine.block name: @id_then, parent: template
|
279
280
|
@block_else = template.engine.block name: @id_else, parent: template
|
281
|
+
template.childrens << @block_then
|
282
|
+
template.childrens << @block_else
|
280
283
|
self
|
281
284
|
end
|
282
285
|
|
@@ -314,6 +317,7 @@ module Tzispa
|
|
314
317
|
|
315
318
|
def parse!
|
316
319
|
@parsed_static = template.engine.static name: @id, parent: template
|
320
|
+
template.childrens << @parsed_static
|
317
321
|
self
|
318
322
|
end
|
319
323
|
|
data/lib/tzispa/rig/template.rb
CHANGED
@@ -4,7 +4,6 @@ require 'forwardable'
|
|
4
4
|
require 'fileutils'
|
5
5
|
require 'tzispa/utils/string'
|
6
6
|
require 'tzispa/utils/indenter'
|
7
|
-
require 'tzispa/utils/cache'
|
8
7
|
require 'tzispa/rig'
|
9
8
|
|
10
9
|
module Tzispa
|
@@ -68,7 +67,7 @@ module Tzispa
|
|
68
67
|
DEFAULT_FORMAT = 'htm'.freeze
|
69
68
|
RIG_EXTENSION = 'rig'.freeze
|
70
69
|
|
71
|
-
attr_reader :name, :type, :domain, :format, :params, :parser, :engine, :subdomain
|
70
|
+
attr_reader :name, :type, :domain, :format, :params, :parser, :engine, :subdomain, :childrens
|
72
71
|
def_delegators :@parser, :attribute_tags
|
73
72
|
|
74
73
|
def initialize(name:, type:, domain: nil, parent: nil, format: nil, params: nil, engine: nil)
|
@@ -76,6 +75,7 @@ module Tzispa
|
|
76
75
|
@subdomain = subdom_name.first if subdom_name.length > 1
|
77
76
|
@name = subdom_name.last
|
78
77
|
@params = Parameters.new(params)
|
78
|
+
@childrens = Array.new
|
79
79
|
send('type=', type)
|
80
80
|
if parent
|
81
81
|
@engine = engine || parent.engine
|
@@ -95,6 +95,12 @@ module Tzispa
|
|
95
95
|
self
|
96
96
|
end
|
97
97
|
|
98
|
+
def modified?
|
99
|
+
super || (childrens.count > 0 && childrens.index { |tpl|
|
100
|
+
tpl.modified?
|
101
|
+
})
|
102
|
+
end
|
103
|
+
|
98
104
|
def render(context)
|
99
105
|
parse! unless @parser
|
100
106
|
binder = TemplateBinder.for self, context
|
@@ -188,48 +194,5 @@ module Tzispa
|
|
188
194
|
end
|
189
195
|
|
190
196
|
|
191
|
-
class Engine
|
192
|
-
|
193
|
-
attr_reader :app
|
194
|
-
|
195
|
-
def initialize(app, cache_enabled, cache_size)
|
196
|
-
@app = app
|
197
|
-
@cache = Tzispa::Utils::LRUCache.new(cache_size) if cache_enabled
|
198
|
-
@mutex = Mutex.new
|
199
|
-
end
|
200
|
-
|
201
|
-
def layout(name:, format:nil, params:nil)
|
202
|
-
rig_template name, :layout, format, params, nil
|
203
|
-
end
|
204
|
-
|
205
|
-
def block(name:, format:nil, params:nil, parent:nil)
|
206
|
-
rig_template name, :block, format, params, parent
|
207
|
-
end
|
208
|
-
|
209
|
-
def static(name:, format:nil, params:nil, parent:nil)
|
210
|
-
rig_template name, :static, format, params, parent
|
211
|
-
end
|
212
|
-
|
213
|
-
def rig_template(name, type, format, params, parent)
|
214
|
-
if @cache
|
215
|
-
#todo: a modified template file not reloading if the container template isn't modified too
|
216
|
-
ktpl = "#{type}__#{name}".to_sym
|
217
|
-
if @mutex.owned?
|
218
|
-
tpl = @cache[ktpl] || Template.new(name: name, type: type, format: format, domain: @app.domain, params: params, parent: parent, engine: self)
|
219
|
-
@cache[ktpl] = tpl.loaded? && !tpl.modified? ? tpl : tpl.load!.parse!
|
220
|
-
else
|
221
|
-
@mutex.synchronize {
|
222
|
-
tpl = @cache[ktpl] || Template.new(name: name, type: type, format: format, domain: @app.domain, params: params, parent: parent, engine: self)
|
223
|
-
@cache[ktpl] = tpl.loaded? && !tpl.modified? ? tpl : tpl.load!.parse!
|
224
|
-
}
|
225
|
-
end
|
226
|
-
else
|
227
|
-
tpl = Template.new(name: name, type: type, format: format, domain: @app.domain, params: params, parent: parent, engine: self)
|
228
|
-
tpl.load!.parse!
|
229
|
-
end
|
230
|
-
end
|
231
|
-
|
232
|
-
end
|
233
|
-
|
234
197
|
end
|
235
198
|
end
|
data/lib/tzispa/rig/version.rb
CHANGED
data/lib/tzispa/rig.rb
CHANGED
@@ -1,11 +1,12 @@
|
|
1
1
|
module Tzispa
|
2
2
|
module Rig
|
3
|
-
|
3
|
+
|
4
|
+
require 'tzispa/rig/version'
|
4
5
|
require 'tzispa/rig/parameters'
|
6
|
+
require 'tzispa/rig/parsernext'
|
5
7
|
require 'tzispa/rig/binder'
|
6
8
|
require 'tzispa/rig/template'
|
7
|
-
require 'tzispa/rig/
|
8
|
-
require 'tzispa/rig/version'
|
9
|
+
require 'tzispa/rig/engine'
|
9
10
|
|
10
11
|
end
|
11
12
|
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.2.
|
4
|
+
version: 0.2.9
|
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: 2016-04-
|
11
|
+
date: 2016-04-21 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: tzispa_helpers
|
@@ -38,6 +38,20 @@ dependencies:
|
|
38
38
|
- - "~>"
|
39
39
|
- !ruby/object:Gem::Version
|
40
40
|
version: 0.2.1
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: lru_redux
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '1.1'
|
48
|
+
type: :runtime
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '1.1'
|
41
55
|
description: General purpose template engine
|
42
56
|
email:
|
43
57
|
- japinero@area-integral.com
|
@@ -49,6 +63,7 @@ files:
|
|
49
63
|
- README.md
|
50
64
|
- lib/tzispa/rig.rb
|
51
65
|
- lib/tzispa/rig/binder.rb
|
66
|
+
- lib/tzispa/rig/engine.rb
|
52
67
|
- lib/tzispa/rig/parameters.rb
|
53
68
|
- lib/tzispa/rig/parser.rb
|
54
69
|
- lib/tzispa/rig/parsernext.rb
|