tzispa_rig 0.5.4 → 0.5.5
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +4 -0
- data/lib/tzispa/rig/binder.rb +7 -13
- data/lib/tzispa/rig/helpers/template_maker.rb +66 -0
- data/lib/tzispa/rig/parsernext.rb +2 -3
- data/lib/tzispa/rig/template.rb +19 -69
- data/lib/tzispa/rig/template_binder.rb +1 -0
- data/lib/tzispa/rig/token.rb +7 -7
- data/lib/tzispa/rig/{type_token → tokens}/api_url.rb +1 -1
- data/lib/tzispa/rig/{type_token → tokens}/block.rb +1 -1
- data/lib/tzispa/rig/{type_token → tokens}/expression.rb +8 -4
- data/lib/tzispa/rig/{type_token → tokens}/statement.rb +4 -4
- data/lib/tzispa/rig/version.rb +1 -1
- metadata +7 -6
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 3e832ffa87f19506e339017eee1aeb22d6664671
|
4
|
+
data.tar.gz: f4365cd9feb40b7e97d23c680e8d379145f132d6
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: b135a0befc2df801b505cf87ec3706c41ca12b70fdbcb286652fb41f3c43ba23bcbb944bf873573bf13b11af9204ffee54f08225a44e4a7cdf074301b5d58fc4
|
7
|
+
data.tar.gz: 447f262807c582167eb1ba9b1756fa8bba284cd4842965a54aa957ec600565394a42efc7fd4e65ca03c66bfdd6f384840f79c2f8b707039acc39c283f6469f69
|
data/CHANGELOG.md
CHANGED
data/lib/tzispa/rig/binder.rb
CHANGED
@@ -50,17 +50,11 @@ module Tzispa
|
|
50
50
|
#
|
51
51
|
# loop_binder(:mylist)
|
52
52
|
#
|
53
|
-
# The LoopBinder returned by this funcion is independent of the
|
54
|
-
# parent binder where it is defined, so the template symbols of the parent
|
55
|
-
# binder are not accesible in the loop_binder context. In
|
56
|
-
# other words, in the top example the two 'myvar' symbols are different
|
57
|
-
# and you can not access the first myvar value inside the loop
|
58
|
-
#
|
59
53
|
# ==== Parameters
|
60
54
|
# loop_id<Symbol>: The id of the template loop to bind
|
61
55
|
#
|
62
56
|
def loop_binder(loop_id)
|
63
|
-
prl =
|
57
|
+
prl = loop?(loop_id)
|
64
58
|
LoopBinder.new(prl, context) if prl
|
65
59
|
end
|
66
60
|
|
@@ -70,14 +64,14 @@ module Tzispa
|
|
70
64
|
|
71
65
|
private
|
72
66
|
|
73
|
-
def
|
74
|
-
|
75
|
-
duplicated?
|
76
|
-
|
67
|
+
def loop?(loop_id)
|
68
|
+
ltk = parser.loop_token loop_id
|
69
|
+
duplicated? ltk
|
70
|
+
ltk.first if ltk.count.positive?
|
77
71
|
end
|
78
72
|
|
79
|
-
def duplicated?(
|
80
|
-
raise DuplicatedLoop.new(self.class.name,
|
73
|
+
def duplicated?(token)
|
74
|
+
raise DuplicatedLoop.new(self.class.name, token.id) if token.count > 1
|
81
75
|
end
|
82
76
|
end
|
83
77
|
|
@@ -0,0 +1,66 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'fileutils'
|
4
|
+
require 'tzispa/utils/string'
|
5
|
+
require 'tzispa/utils/indenter'
|
6
|
+
|
7
|
+
module Tzispa
|
8
|
+
module Rig
|
9
|
+
module Helpers
|
10
|
+
module TemplateMaker
|
11
|
+
|
12
|
+
using Tzispa::Utils::TzString
|
13
|
+
|
14
|
+
def create(content = '')
|
15
|
+
FileUtils.mkdir_p(path) unless Dir.exist? path
|
16
|
+
super(content)
|
17
|
+
create_binder
|
18
|
+
end
|
19
|
+
|
20
|
+
def binder_require
|
21
|
+
@binder_require ||= "view/#{subdomain || '_'}/#{type}/#{name.downcase}"
|
22
|
+
end
|
23
|
+
|
24
|
+
def binder_namespace
|
25
|
+
@binder_namespace ||= "#{domain.name.to_s.camelize}::#{subdomain&.camelize}View"
|
26
|
+
end
|
27
|
+
|
28
|
+
def binder_class_name
|
29
|
+
@binder_class_name ||= @name.camelize
|
30
|
+
end
|
31
|
+
|
32
|
+
def binder_class
|
33
|
+
@binder_class ||= begin
|
34
|
+
domain.require binder_require
|
35
|
+
"#{binder_namespace}::#{binder_class_name}#{type.to_s.capitalize}".constantize
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
39
|
+
def create_binder
|
40
|
+
return unless %i[block layout].include?(type)
|
41
|
+
::File.open("#{domain.path}/#{binder_require}.rb", 'w') do |f|
|
42
|
+
f.puts write_binder_code
|
43
|
+
end
|
44
|
+
end
|
45
|
+
|
46
|
+
def write_binder_code
|
47
|
+
Tzispa::Utils::Indenter.new(2).tap do |binder_code|
|
48
|
+
binder_code << "require 'tzispa/rig/binder'\n\n"
|
49
|
+
level = 0
|
50
|
+
binder_namespace.split('::').each do |ns|
|
51
|
+
binder_code.indent if level.positive?
|
52
|
+
binder_code << "module #{ns}\n"
|
53
|
+
level += 1
|
54
|
+
end
|
55
|
+
binder_code.indent << "\nclass #{binder_class_name} < Tzispa::Rig::TemplateBinder\n\n"
|
56
|
+
binder_code.indent << "def bind!\n"
|
57
|
+
binder_code << "end\n\n"
|
58
|
+
binder_code.unindent << "end\n"
|
59
|
+
binder_namespace.split('::').each { binder_code.unindent << "end\n" }
|
60
|
+
end.to_s
|
61
|
+
end
|
62
|
+
end
|
63
|
+
end
|
64
|
+
end
|
65
|
+
end
|
66
|
+
|
@@ -40,7 +40,6 @@ module Tzispa
|
|
40
40
|
@attribute_tags = nil
|
41
41
|
@childrens = []
|
42
42
|
@tokens = []
|
43
|
-
@loop_parser = {}
|
44
43
|
parse_flags
|
45
44
|
if bindable?
|
46
45
|
parse_statements
|
@@ -73,11 +72,11 @@ module Tzispa
|
|
73
72
|
end
|
74
73
|
end
|
75
74
|
|
76
|
-
def
|
75
|
+
def loop_token(id)
|
77
76
|
lpp = tokens.select { |p| p.type == :loop && p.id == id }
|
78
77
|
lpp.concat(
|
79
78
|
tokens.select { |p| p.type == :ife }.map do |p|
|
80
|
-
p.
|
79
|
+
p.loop_token(id)
|
81
80
|
end.flatten.compact
|
82
81
|
)
|
83
82
|
end
|
data/lib/tzispa/rig/template.rb
CHANGED
@@ -1,12 +1,10 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
3
|
require 'forwardable'
|
4
|
-
require 'fileutils'
|
5
|
-
require 'tzispa/utils/string'
|
6
|
-
require 'tzispa/utils/indenter'
|
7
4
|
require 'tzispa/rig/parameters'
|
8
5
|
require 'tzispa/rig/parsernext'
|
9
6
|
require 'tzispa/rig/template_binder'
|
7
|
+
require 'tzispa/rig/helpers/template_maker'
|
10
8
|
|
11
9
|
module Tzispa
|
12
10
|
module Rig
|
@@ -95,7 +93,9 @@ module Tzispa
|
|
95
93
|
class Template < File
|
96
94
|
extend Forwardable
|
97
95
|
|
98
|
-
|
96
|
+
include Tzispa::Rig::Helpers::TemplateMaker
|
97
|
+
|
98
|
+
|
99
99
|
|
100
100
|
BASIC_TYPES = %i[layout block static].freeze
|
101
101
|
RIG_EXTENSION = 'rig'
|
@@ -122,29 +122,30 @@ module Tzispa
|
|
122
122
|
self
|
123
123
|
end
|
124
124
|
|
125
|
-
def modified?
|
126
|
-
super || (parser && parser.childrens.index(&:modified?))
|
127
|
-
end
|
128
|
-
|
129
|
-
def valid?
|
130
|
-
!content.empty? && !parser.empty?
|
131
|
-
end
|
132
|
-
|
133
125
|
def render(context, binder = nil)
|
134
126
|
parse! unless parser
|
135
127
|
binder ||= TemplateBinder.for self, context
|
136
|
-
binder.bound
|
137
|
-
parser.render binder
|
128
|
+
parser.render binder.bound
|
138
129
|
end
|
139
130
|
|
140
131
|
def path
|
141
132
|
@path ||= "#{domain.path}/view/#{subdomain || '_'}/#{type.to_s.downcase}"
|
142
133
|
end
|
143
134
|
|
144
|
-
def
|
145
|
-
|
146
|
-
|
147
|
-
|
135
|
+
def params=(value)
|
136
|
+
@params = Parameters.new(value)
|
137
|
+
end
|
138
|
+
|
139
|
+
def params
|
140
|
+
@params.data
|
141
|
+
end
|
142
|
+
|
143
|
+
def modified?
|
144
|
+
super || (parser && parser.childrens.index(&:modified?))
|
145
|
+
end
|
146
|
+
|
147
|
+
def valid?
|
148
|
+
!content.empty? && !parser.empty?
|
148
149
|
end
|
149
150
|
|
150
151
|
def block?
|
@@ -163,33 +164,6 @@ module Tzispa
|
|
163
164
|
block? || layout?
|
164
165
|
end
|
165
166
|
|
166
|
-
def params=(value)
|
167
|
-
@params = Parameters.new(value)
|
168
|
-
end
|
169
|
-
|
170
|
-
def params
|
171
|
-
@params.data
|
172
|
-
end
|
173
|
-
|
174
|
-
def binder_require
|
175
|
-
@binder_require ||= "view/#{subdomain || '_'}/#{type}/#{name.downcase}"
|
176
|
-
end
|
177
|
-
|
178
|
-
def binder_namespace
|
179
|
-
@binder_namespace ||= "#{domain.name.to_s.camelize}::#{subdomain&.camelize}View"
|
180
|
-
end
|
181
|
-
|
182
|
-
def binder_class_name
|
183
|
-
@binder_class_name ||= @name.camelize
|
184
|
-
end
|
185
|
-
|
186
|
-
def binder_class
|
187
|
-
@binder_class ||= begin
|
188
|
-
domain.require binder_require
|
189
|
-
"#{binder_namespace}::#{binder_class_name}#{type.to_s.capitalize}".constantize
|
190
|
-
end
|
191
|
-
end
|
192
|
-
|
193
167
|
private
|
194
168
|
|
195
169
|
def build_name(name)
|
@@ -203,30 +177,6 @@ module Tzispa
|
|
203
177
|
raise ArgumentError("#{value} is not a Rig block") unless BASIC_TYPES.include?(value)
|
204
178
|
@type = value
|
205
179
|
end
|
206
|
-
|
207
|
-
def create_binder
|
208
|
-
return unless %i[block layout].include?(type)
|
209
|
-
::File.open("#{domain.path}/#{binder_require}.rb", 'w') do |f|
|
210
|
-
f.puts write_binder_code
|
211
|
-
end
|
212
|
-
end
|
213
|
-
|
214
|
-
def write_binder_code
|
215
|
-
Tzispa::Utils::Indenter.new(2).tap do |binder_code|
|
216
|
-
binder_code << "require 'tzispa/rig/binder'\n\n"
|
217
|
-
level = 0
|
218
|
-
binder_namespace.split('::').each do |ns|
|
219
|
-
binder_code.indent if level.positive?
|
220
|
-
binder_code << "module #{ns}\n"
|
221
|
-
level += 1
|
222
|
-
end
|
223
|
-
binder_code.indent << "\nclass #{binder_class_name} < Tzispa::Rig::TemplateBinder\n\n"
|
224
|
-
binder_code.indent << "def bind!\n"
|
225
|
-
binder_code << "end\n\n"
|
226
|
-
binder_code.unindent << "end\n"
|
227
|
-
binder_namespace.split('::').each { binder_code.unindent << "end\n" }
|
228
|
-
end.to_s
|
229
|
-
end
|
230
180
|
end
|
231
181
|
|
232
182
|
end
|
data/lib/tzispa/rig/token.rb
CHANGED
@@ -11,7 +11,7 @@ module Tzispa
|
|
11
11
|
|
12
12
|
using Tzispa::Utils::TzString
|
13
13
|
|
14
|
-
RE_ANCHOR = /(
|
14
|
+
RE_ANCHOR = /(\u0010\$\h+\$\u0010)/
|
15
15
|
|
16
16
|
attr_reader :type, :parser
|
17
17
|
def_delegators :@parser, :domain, :content_type, :template
|
@@ -23,19 +23,19 @@ module Tzispa
|
|
23
23
|
|
24
24
|
class << self
|
25
25
|
def instance(parser, type, match)
|
26
|
-
"Tzispa::Rig::
|
26
|
+
"Tzispa::Rig::Tokens::#{type.to_s.capitalize}".constantize.new parser, match
|
27
27
|
end
|
28
28
|
end
|
29
29
|
|
30
30
|
def anchor
|
31
|
-
@anchor ||= "
|
31
|
+
@anchor ||= "\u0010$#{format '%x', object_id}$\u0010"
|
32
32
|
end
|
33
33
|
end
|
34
34
|
|
35
|
-
require 'tzispa/rig/
|
36
|
-
require 'tzispa/rig/
|
37
|
-
require 'tzispa/rig/
|
38
|
-
require 'tzispa/rig/
|
35
|
+
require 'tzispa/rig/tokens/api_url'
|
36
|
+
require 'tzispa/rig/tokens/expression'
|
37
|
+
require 'tzispa/rig/tokens/statement'
|
38
|
+
require 'tzispa/rig/tokens/block'
|
39
39
|
|
40
40
|
end
|
41
41
|
end
|
@@ -4,7 +4,7 @@ require 'tzispa/utils/string'
|
|
4
4
|
|
5
5
|
module Tzispa
|
6
6
|
module Rig
|
7
|
-
module
|
7
|
+
module Tokens
|
8
8
|
|
9
9
|
class Meta < Rig::Token
|
10
10
|
attr_reader :id
|
@@ -41,9 +41,13 @@ module Tzispa
|
|
41
41
|
end
|
42
42
|
|
43
43
|
def render(binder)
|
44
|
-
if binder.data.respond_to?(
|
45
|
-
value = binder.data.send(
|
46
|
-
|
44
|
+
if binder.data.respond_to?(id)
|
45
|
+
value = binder.data.send(id).to_s
|
46
|
+
begin
|
47
|
+
value.send(parser.content_escape_method)
|
48
|
+
rescue
|
49
|
+
value
|
50
|
+
end
|
47
51
|
else
|
48
52
|
unknown
|
49
53
|
end
|
@@ -4,7 +4,7 @@ require 'forwardable'
|
|
4
4
|
|
5
5
|
module Tzispa
|
6
6
|
module Rig
|
7
|
-
module
|
7
|
+
module Tokens
|
8
8
|
|
9
9
|
class Loop < Rig::Token
|
10
10
|
extend Forwardable
|
@@ -67,9 +67,9 @@ module Tzispa
|
|
67
67
|
end
|
68
68
|
end
|
69
69
|
|
70
|
-
def
|
71
|
-
lpp = then_parser.
|
72
|
-
lpp.concat(else_parser&.
|
70
|
+
def loop_token(id)
|
71
|
+
lpp = then_parser.loop_token(id)
|
72
|
+
lpp.concat(else_parser&.loop_token(id) || [])
|
73
73
|
lpp.compact.freeze
|
74
74
|
end
|
75
75
|
|
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.5
|
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-05-03 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: tzispa_utils
|
@@ -65,16 +65,17 @@ files:
|
|
65
65
|
- lib/tzispa/rig.rb
|
66
66
|
- lib/tzispa/rig/binder.rb
|
67
67
|
- lib/tzispa/rig/engine.rb
|
68
|
+
- lib/tzispa/rig/helpers/template_maker.rb
|
68
69
|
- lib/tzispa/rig/parameters.rb
|
69
70
|
- lib/tzispa/rig/parsernext.rb
|
70
71
|
- lib/tzispa/rig/syntax.rb
|
71
72
|
- lib/tzispa/rig/template.rb
|
72
73
|
- lib/tzispa/rig/template_binder.rb
|
73
74
|
- lib/tzispa/rig/token.rb
|
74
|
-
- lib/tzispa/rig/
|
75
|
-
- lib/tzispa/rig/
|
76
|
-
- lib/tzispa/rig/
|
77
|
-
- lib/tzispa/rig/
|
75
|
+
- lib/tzispa/rig/tokens/api_url.rb
|
76
|
+
- lib/tzispa/rig/tokens/block.rb
|
77
|
+
- lib/tzispa/rig/tokens/expression.rb
|
78
|
+
- lib/tzispa/rig/tokens/statement.rb
|
78
79
|
- lib/tzispa/rig/version.rb
|
79
80
|
- lib/tzispa_rig.rb
|
80
81
|
- test/engine_test.rb
|