tzispa_rig 0.4.3 → 0.4.4
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 +6 -5
- data/lib/tzispa/rig/template.rb +2 -2
- data/lib/tzispa/rig/version.rb +1 -1
- metadata +2 -17
- data/lib/tzispa/rig/parser.rb +0 -165
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: d7bcd3c23e2bd1422bb4063c90fb5f2c13ad89c0
|
4
|
+
data.tar.gz: 0ae585b5ee37682149e6f20a760c73f5306bafc6
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 2b19ba2bb38467fd667744d9ae63f9f7b914b25f9cdeb109681b95822702bfa7cc04f2d67269bad1bc0424a5b0b2cf4a4443b89c1beb17df3766d25635576f18
|
7
|
+
data.tar.gz: 361177bf1bb749c7653c767ebbaaeefdc02c9989091bf23a0a2d3c19bd6087fc34624eb33bc651d88896b78427f2ae3203a3a54abbb3638a6efa645e9db1e0b1
|
data/CHANGELOG.md
CHANGED
@@ -2,6 +2,10 @@ Tzispa Rig
|
|
2
2
|
|
3
3
|
Rig templates implementation
|
4
4
|
|
5
|
+
## v0.4.4
|
6
|
+
- add session,router_params,not_found&logger delegators to make template binders less contextized
|
7
|
+
- remove unused gem dependencies and code (old parser)
|
8
|
+
|
5
9
|
## v0.4.3
|
6
10
|
- add config and repository delegators into context
|
7
11
|
- updated rig templates documentation
|
data/lib/tzispa/rig/binder.rb
CHANGED
@@ -14,15 +14,16 @@ module Tzispa
|
|
14
14
|
class Binder
|
15
15
|
extend Forwardable
|
16
16
|
|
17
|
-
attr_reader :context, :
|
17
|
+
attr_reader :context, :data_struct, :tags, :parser
|
18
18
|
def_delegators :@parser, :attribute_tags
|
19
|
-
def_delegators :@context, :app, :request, :response, :
|
19
|
+
def_delegators :@context, :app, :request, :response, :session, :router_params, :not_found
|
20
|
+
def_delegators :app, :repository, :config, :logger
|
20
21
|
|
21
22
|
|
22
23
|
def initialize(parser, context)
|
23
24
|
@parser = parser
|
24
25
|
@context = context
|
25
|
-
@
|
26
|
+
@data_struct = attribute_tags.count > 0 ? Struct.new(*attribute_tags) : Struct.new(nil)
|
26
27
|
end
|
27
28
|
|
28
29
|
alias :tags :attribute_tags
|
@@ -69,7 +70,7 @@ module Tzispa
|
|
69
70
|
end
|
70
71
|
|
71
72
|
def data(**params)
|
72
|
-
(@data ||= @
|
73
|
+
(@data ||= @data_struct.new).tap { |d|
|
73
74
|
params.each{ |k,v|
|
74
75
|
raise UnknownTag.new "#{k} is not a tag in #{self.class.name}" unless tags.include? k
|
75
76
|
d[k] = v
|
@@ -123,7 +124,7 @@ module Tzispa
|
|
123
124
|
|
124
125
|
def initialize(binder)
|
125
126
|
@context = binder.context
|
126
|
-
@data = binder.
|
127
|
+
@data = binder.data_struct.new
|
127
128
|
end
|
128
129
|
|
129
130
|
end
|
data/lib/tzispa/rig/template.rb
CHANGED
@@ -173,11 +173,11 @@ module Tzispa
|
|
173
173
|
|
174
174
|
def create_binder
|
175
175
|
::File.open("#{domain.path}/#{binder_require}.rb", "w") { |f|
|
176
|
-
f.puts
|
176
|
+
f.puts write_binder_code
|
177
177
|
} if @type == :block
|
178
178
|
end
|
179
179
|
|
180
|
-
def
|
180
|
+
def write_binder_code
|
181
181
|
Tzispa::Utils::Indenter.new(2).tap { |binder_code|
|
182
182
|
binder_code << "require 'tzispa/rig/binder'\n\n"
|
183
183
|
level = 0
|
data/lib/tzispa/rig/version.rb
CHANGED
metadata
CHANGED
@@ -1,29 +1,15 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: tzispa_rig
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.4.
|
4
|
+
version: 0.4.4
|
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-11-
|
11
|
+
date: 2016-11-15 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
|
-
- !ruby/object:Gem::Dependency
|
14
|
-
name: tzispa_helpers
|
15
|
-
requirement: !ruby/object:Gem::Requirement
|
16
|
-
requirements:
|
17
|
-
- - "~>"
|
18
|
-
- !ruby/object:Gem::Version
|
19
|
-
version: 0.1.3
|
20
|
-
type: :runtime
|
21
|
-
prerelease: false
|
22
|
-
version_requirements: !ruby/object:Gem::Requirement
|
23
|
-
requirements:
|
24
|
-
- - "~>"
|
25
|
-
- !ruby/object:Gem::Version
|
26
|
-
version: 0.1.3
|
27
13
|
- !ruby/object:Gem::Dependency
|
28
14
|
name: tzispa_utils
|
29
15
|
requirement: !ruby/object:Gem::Requirement
|
@@ -65,7 +51,6 @@ files:
|
|
65
51
|
- lib/tzispa/rig/binder.rb
|
66
52
|
- lib/tzispa/rig/engine.rb
|
67
53
|
- lib/tzispa/rig/parameters.rb
|
68
|
-
- lib/tzispa/rig/parser.rb
|
69
54
|
- lib/tzispa/rig/parsernext.rb
|
70
55
|
- lib/tzispa/rig/syntax.rb
|
71
56
|
- lib/tzispa/rig/template.rb
|
data/lib/tzispa/rig/parser.rb
DELETED
@@ -1,165 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
require 'tzispa/rig/engine'
|
4
|
-
require 'tzispa/rig/formatter'
|
5
|
-
require 'tzispa/helpers/security'
|
6
|
-
|
7
|
-
module Tzispa
|
8
|
-
module Rig
|
9
|
-
class Parser
|
10
|
-
|
11
|
-
include Tzispa::Helpers::Security
|
12
|
-
|
13
|
-
EMPTY_STRING = ''.freeze
|
14
|
-
|
15
|
-
attr_reader :text
|
16
|
-
|
17
|
-
RIG_SYNTAX = {
|
18
|
-
:re_flags => /<flags:(\[(\w+=[^,\]]+(,\w+=[^,\]]+)*?)\])\/>/.freeze,
|
19
|
-
:blk => /<(blk):(\w+(?:\.\w+)?)(?:\[(\w+=[^,\]]+(?:,\w+=[^,\]]+)*)\])?\/>/.freeze,
|
20
|
-
:iblk => /<(iblk):(\w+):(\w+(?:\.\w+)?)(?:\[(\w+=[^,\]]+(?:,\w+=[^,\]]+)*)\])?:(\w+(?:\.\w+)?)(?:\[(\w+=[^,\]]+(?:,\w+=[^,\]]+)*)\])?\/>/.freeze,
|
21
|
-
:static => /<(static):(\w+(?:\.\w+)?)(?:\[(\w+=[^,\]]+(?:,\w+=[^,\]]+)*)\])?\/>/.freeze,
|
22
|
-
:re_var => /<var(\[%[A-Z]?[0-9]*[a-z]\])?:(\w+)\/>/.freeze,
|
23
|
-
:re_metavar => /\{%([^%]+?)%\}/.freeze,
|
24
|
-
:re_loop => /<loop:(\w+)>(.*?)<\/loop:\1>/m.freeze,
|
25
|
-
:re_ife => /<ife:(\w+)>(.*?)(<else:\1\/>(.*?))?<\/ife:\1>/m.freeze,
|
26
|
-
:re_purl => /<purl:(\w+)(\[(\w+=[^,\]]+(,\w+=[^,\]]+)*?)\])?\/>/.freeze,
|
27
|
-
:re_api => /<sapi:(\w+(?:\.\w+)?):(\w+)(?::([^:]+))?(?::([^\/]+))?\/>/.freeze
|
28
|
-
}
|
29
|
-
|
30
|
-
def initialize(engine, binder=nil, text=nil)
|
31
|
-
@engine = engine
|
32
|
-
@binder = binder || engine.binder
|
33
|
-
@context = engine.context
|
34
|
-
@text = text
|
35
|
-
end
|
36
|
-
|
37
|
-
def parse!
|
38
|
-
@text ||= @engine.content
|
39
|
-
@binder.bind! if @binder && @binder.respond_to?( :bind! )
|
40
|
-
if @engine.type == :block
|
41
|
-
parseStatement
|
42
|
-
parseExpression
|
43
|
-
end
|
44
|
-
parseBlock
|
45
|
-
self
|
46
|
-
end
|
47
|
-
|
48
|
-
|
49
|
-
private
|
50
|
-
|
51
|
-
def parseExpression
|
52
|
-
parseMetavar
|
53
|
-
parseVar
|
54
|
-
parsePurl
|
55
|
-
parseAPI
|
56
|
-
end
|
57
|
-
|
58
|
-
def parseStatement
|
59
|
-
parseLoop
|
60
|
-
parseIfe
|
61
|
-
end
|
62
|
-
|
63
|
-
def parseFlags
|
64
|
-
@text.gsub!(RIG_SYNTAX[:re_flags]) { |match|
|
65
|
-
flags = Regexp.last_match(1)
|
66
|
-
@engine.flags = flags
|
67
|
-
EMPTY_STRING
|
68
|
-
}
|
69
|
-
end
|
70
|
-
|
71
|
-
def parseLoop
|
72
|
-
@text.gsub!(RIG_SYNTAX[:re_loop]) { |match|
|
73
|
-
loopid = Regexp.last_match(1)
|
74
|
-
loopbody = Regexp.last_match(2)
|
75
|
-
lenrig = @binder.respond_to?("#{loopid}") ? @binder.send("#{loopid}") : []
|
76
|
-
lenrig.respond_to?(:map) ? lenrig.map { |item| Parser.new(@engine, item, loopbody.dup).parse!.text }.join : String.new.freeze
|
77
|
-
}
|
78
|
-
end
|
79
|
-
|
80
|
-
def parseIfe
|
81
|
-
@text.gsub!(RIG_SYNTAX[:re_ife]) { |match|
|
82
|
-
ifetest = Regexp.last_match(1)
|
83
|
-
test = @binder.respond_to?("#{ifetest}") ? @binder.send("#{ifetest}") : false
|
84
|
-
ifebody = Regexp.last_match(2)
|
85
|
-
elsebody = Regexp.last_match(4)
|
86
|
-
Parser.new(@engine, @binder, test ? "#{ifebody}" : "#{elsebody}").parse!.text
|
87
|
-
}
|
88
|
-
end
|
89
|
-
|
90
|
-
def parseMetavar
|
91
|
-
@text.gsub!(RIG_SYNTAX[:re_metavar]) { |match|
|
92
|
-
varid = Regexp.last_match(1)
|
93
|
-
if @context.respond_to?(varid)
|
94
|
-
@context.send(varid)
|
95
|
-
elsif !@context.env.nil? and !@context.env[varid].nil?
|
96
|
-
@context.env[varid]
|
97
|
-
elsif @binder.respond_to?(varid)
|
98
|
-
@binder.send(varid)
|
99
|
-
else
|
100
|
-
Formatter.unknown(varid)
|
101
|
-
end
|
102
|
-
}
|
103
|
-
end
|
104
|
-
|
105
|
-
def parseVar
|
106
|
-
@text.gsub!(RIG_SYNTAX[:re_var]) { |match|
|
107
|
-
fmt = Regexp.last_match(1)
|
108
|
-
varid = Regexp.last_match(2)
|
109
|
-
value = @binder.respond_to?(varid) ? @binder.send(varid) : Formatter.unknown(varid)
|
110
|
-
Formatter.rigvar(value, fmt)
|
111
|
-
}
|
112
|
-
end
|
113
|
-
|
114
|
-
def parsePurl
|
115
|
-
@text.gsub!(RIG_SYNTAX[:re_purl]) { |match|
|
116
|
-
urlid = Regexp.last_match[1]
|
117
|
-
urlparams = Parameters.new(Regexp.last_match[3])
|
118
|
-
@engine.app.router_path urlid.to_sym, urlparams.data
|
119
|
-
}
|
120
|
-
end
|
121
|
-
|
122
|
-
def parseAPI
|
123
|
-
@text.gsub!(RIG_SYNTAX[:re_api]) { |match|
|
124
|
-
handler, verb, predicate, sufix = Regexp.last_match[1], Regexp.last_match[2], Regexp.last_match[3], Regexp.last_match[4]
|
125
|
-
sign = Parser.sign_array [handler, verb, predicate], @engine.app.config.salt
|
126
|
-
@engine.app.router_path :api, {handler: handler, verb: verb, predicate: predicate, sign: sign, sufix: sufix}
|
127
|
-
}
|
128
|
-
end
|
129
|
-
|
130
|
-
def parseBlock
|
131
|
-
reBlocks = Regexp.new(RIG_SYNTAX[:re_blk].to_s + '|' + RIG_SYNTAX[:re_iblk].to_s + '|' + RIG_SYNTAX[:re_static].to_s)
|
132
|
-
|
133
|
-
@text.gsub!(reBlocks) {
|
134
|
-
strtype = (Regexp.last_match[2] || '') << (Regexp.last_match[7] || '') << (Regexp.last_match[16] || '')
|
135
|
-
case strtype
|
136
|
-
when 'blk'
|
137
|
-
rigtype = :block
|
138
|
-
rigname = Regexp.last_match[3]
|
139
|
-
rigparams = Regexp.last_match[5]
|
140
|
-
when 'iblk'
|
141
|
-
rigtype = :block
|
142
|
-
rigtest = Regexp.last_match[8]
|
143
|
-
if (@binder.respond_to?("#{rigtest}?") ? @binder.send("#{rigtest}?") : false)
|
144
|
-
rigname = Regexp.last_match[9]
|
145
|
-
rigparams = Regexp.last_match[11]
|
146
|
-
else
|
147
|
-
rigname = Regexp.last_match[12]
|
148
|
-
rigparams = Regexp.last_match[14]
|
149
|
-
end
|
150
|
-
when 'static'
|
151
|
-
rigtype = :static
|
152
|
-
rigname = Regexp.last_match[17]
|
153
|
-
rigparams = Regexp.last_match[19]
|
154
|
-
else
|
155
|
-
raise ArgumentError.new("Unknown Rig type: #{strtype}")
|
156
|
-
end
|
157
|
-
engine = Engine.new(name: rigname, type: rigtype, parent: @engine, params: rigparams)
|
158
|
-
engine.render!
|
159
|
-
engine.text
|
160
|
-
}
|
161
|
-
end
|
162
|
-
|
163
|
-
end
|
164
|
-
end
|
165
|
-
end
|