sbuilder-ial 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/VERSION +1 -0
- data/lib/action/exception.rb +13 -0
- data/lib/action/extender.rb +30 -0
- data/lib/action/file_path.rb +35 -0
- data/lib/action/model_builder.rb +74 -0
- data/lib/action/render/exception.rb +12 -0
- data/lib/action/render/producer.rb +193 -0
- data/lib/action/render/producer_ethereum.rb +404 -0
- data/lib/action/render/producer_ethereum_const.rb +221 -0
- data/lib/action/render/renderer.rb +142 -0
- data/lib/action/render/tla_element_generator.rb +1306 -0
- data/lib/action/script_eval.rb +32 -0
- data/lib/action/text.rb +17 -0
- data/lib/action/tla_rules.rb +512 -0
- data/lib/action/translator.rb +160 -0
- data/lib/app/app.rb +259 -0
- data/lib/ethereum/api.rb +669 -0
- data/lib/ethereum.rb +1 -0
- data/lib/fp/compositable.rb +185 -0
- data/lib/fp/error.rb +19 -0
- data/lib/fp/exception.rb +9 -0
- data/lib/fp/result.rb +19 -0
- data/lib/fp/sequence.rb +65 -0
- data/lib/ial/build.rb +12 -0
- data/lib/ial/exception.rb +13 -0
- data/lib/model/constants.rb +72 -0
- data/lib/model/model.rb +74 -0
- data/lib/model/model_dsl.rb +1038 -0
- data/lib/model/sexp.rb +58 -0
- data/lib/plugin/plugin.rb +273 -0
- data/lib/sbuilder-ial.rb +44 -0
- data/lib/utils/logger.rb +82 -0
- data/sbuilder-ial.gemspec +36 -0
- metadata +137 -0
@@ -0,0 +1,142 @@
|
|
1
|
+
require 'mustache'
|
2
|
+
|
3
|
+
|
4
|
+
# ------------------------------------------------------------------
|
5
|
+
# Hack mustache to allow change default otag '{{' ctag '}}'
|
6
|
+
|
7
|
+
class Mustache
|
8
|
+
|
9
|
+
|
10
|
+
# Open mustache to define class accessors 'otag' and 'ctag'
|
11
|
+
def self.otag=( o )
|
12
|
+
@@otag = o
|
13
|
+
end
|
14
|
+
def self.ctag=( c )
|
15
|
+
@@ctag = c
|
16
|
+
end
|
17
|
+
def self.otag
|
18
|
+
@@otag ||= '{{'
|
19
|
+
end
|
20
|
+
def self.ctag
|
21
|
+
@@ctag ||= '}}'
|
22
|
+
end
|
23
|
+
|
24
|
+
|
25
|
+
class Template
|
26
|
+
|
27
|
+
# Open template to set otag/ctag on parser.
|
28
|
+
#
|
29
|
+
# Returns an array of tokens for a given template.
|
30
|
+
#
|
31
|
+
# @return [Array] Array of tokens.
|
32
|
+
#
|
33
|
+
def tokens(src = @source)
|
34
|
+
p = Parser.new
|
35
|
+
p.otag = Mustache.otag
|
36
|
+
p.ctag = Mustache.ctag
|
37
|
+
p.compile(src)
|
38
|
+
end
|
39
|
+
end
|
40
|
+
|
41
|
+
end
|
42
|
+
|
43
|
+
module Sbuilder
|
44
|
+
module Ial
|
45
|
+
module Action
|
46
|
+
module Render
|
47
|
+
class Renderer < Mustache
|
48
|
+
|
49
|
+
# @attr [Logger] loger
|
50
|
+
attr_reader :logger
|
51
|
+
PROGNAME = nil # progname for logger default class name
|
52
|
+
include Sbuilder::Ial::MyLogger # mix logger
|
53
|
+
|
54
|
+
# @attr [String:Array] partials must be set before +to_str+
|
55
|
+
attr_accessor :partials
|
56
|
+
|
57
|
+
# @attr [Hash] preferences modify mustache rendering (debug?)
|
58
|
+
attr_reader :preferences
|
59
|
+
|
60
|
+
def initialize( options={} )
|
61
|
+
# exception raise if accessing unknown property
|
62
|
+
self.raise_on_context_miss = true
|
63
|
+
|
64
|
+
@options = options
|
65
|
+
@logger = getLogger( nil, options )
|
66
|
+
@logger.info "#{__method__}: starting options=#{options}"
|
67
|
+
|
68
|
+
self.partials = {}
|
69
|
+
|
70
|
+
end
|
71
|
+
|
72
|
+
def self.start( options = {} )
|
73
|
+
renderer = Renderer.new( options )
|
74
|
+
renderer
|
75
|
+
end
|
76
|
+
|
77
|
+
def setPreferences( preferences )
|
78
|
+
@preferences = preferences
|
79
|
+
@logger.info "#{__method__}: preferences=#{preferences}"
|
80
|
+
end
|
81
|
+
|
82
|
+
# Use 'to_str' instead of 'render' to use non-default otag/ctag's
|
83
|
+
def to_str( template, data=nil )
|
84
|
+
Mustache.otag = '{|'
|
85
|
+
Mustache.ctag = '|}'
|
86
|
+
|
87
|
+
begin
|
88
|
+
ret = render( template, data )
|
89
|
+
ensure
|
90
|
+
# restore default otag/ctag
|
91
|
+
Mustache.otag = '{{'
|
92
|
+
Mustache.ctag = '}}'
|
93
|
+
end
|
94
|
+
ret
|
95
|
+
end
|
96
|
+
|
97
|
+
# Render conxtext.current[key].
|
98
|
+
|
99
|
+
# @param [String, '.'] key to render, '.' means current context,
|
100
|
+
# string lookup key in current context
|
101
|
+
def EVAL( key )
|
102
|
+
|
103
|
+
logger.info "#{__method__}: key='#{key}', context.current=#{context.current}" if logger.debug?
|
104
|
+
|
105
|
+
# find generate sexp( :sym, data ) to render
|
106
|
+
if key == '.'
|
107
|
+
sexp = context.current
|
108
|
+
else
|
109
|
+
# to evaluate
|
110
|
+
hash = context.current.is_a?( Array ) ? context.current[1] : context.current
|
111
|
+
sexp = hash[key] || hash[key.to_sym]
|
112
|
+
raise MustacheException, "No such key #{key}:#{key.class} found in #{hash}" if sexp.nil?
|
113
|
+
end
|
114
|
+
|
115
|
+
sexp_type = sexp[0]
|
116
|
+
data = sexp[1]
|
117
|
+
logger.debug "#{__method__}: key=#{key}, sexp_type=#{sexp_type}" if logger.debug?
|
118
|
+
|
119
|
+
|
120
|
+
# find correct template
|
121
|
+
template = partials[sexp_type]
|
122
|
+
raise MustacheException,
|
123
|
+
<<-EOS if (template.nil?)
|
124
|
+
Unknown partial for sexp_type '#{sexp_type}'
|
125
|
+
|
126
|
+
Known partials: #{partials.keys.join(',')}"
|
127
|
+
Conxt = #{context.current}
|
128
|
+
EOS
|
129
|
+
|
130
|
+
logger.debug "#{__method__}: template=#{template}, data=#{data}" if logger.debug?
|
131
|
+
return render( template, data )
|
132
|
+
|
133
|
+
end
|
134
|
+
|
135
|
+
|
136
|
+
|
137
|
+
end
|
138
|
+
|
139
|
+
end
|
140
|
+
end
|
141
|
+
end
|
142
|
+
end
|