slight-lang 1.1.0 → 1.1.6
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/.gitignore +1 -1
- data/LICENSE +22 -22
- data/README.md +160 -160
- data/bin/repl/repl.rb +170 -170
- data/bin/repl/utils.rb +29 -29
- data/bin/slight +2 -2
- data/bin/slsh +2 -2
- data/example/component.slight.rb +2 -2
- data/example/core.rb +29 -29
- data/example/custom_engine.rb +37 -37
- data/example/default_engine.rb +31 -28
- data/example/index.slight.rb +28 -28
- data/example/tilt_example.rb +18 -18
- data/lib/slight/config.rb +39 -39
- data/lib/slight/const.rb +13 -0
- data/lib/slight/dsl.rb +168 -169
- data/lib/slight/engine.rb +45 -45
- data/lib/slight/template.rb +38 -38
- data/lib/slight/tilt.rb +25 -26
- data/lib/slight/utils.rb +38 -38
- data/lib/slight.rb +12 -9
- data/slight.gemspec +21 -21
- metadata +4 -3
data/example/tilt_example.rb
CHANGED
@@ -1,18 +1,18 @@
|
|
1
|
-
$:.unshift File.expand_path('../../lib', __FILE__)
|
2
|
-
require 'slight/tilt'
|
3
|
-
|
4
|
-
script = %q{
|
5
|
-
div "btn btn-succes #{btn_size}" do
|
6
|
-
@btn_txt
|
7
|
-
end
|
8
|
-
}
|
9
|
-
|
10
|
-
@btn_txt = 'Pls,Click-Me.'
|
11
|
-
body = Proc.new { script }
|
12
|
-
|
13
|
-
template = Tilt.new('tilt_example.rb', 5, {}, &body)
|
14
|
-
puts template.render(self, :btn_size => "btn-lg")
|
15
|
-
|
16
|
-
# <div class="btn btn-succes btn-lg">
|
17
|
-
# Pls,Click-Me.
|
18
|
-
# </div>
|
1
|
+
$:.unshift File.expand_path('../../lib', __FILE__)
|
2
|
+
require 'slight/tilt'
|
3
|
+
|
4
|
+
script = %q{
|
5
|
+
div "btn btn-succes #{btn_size}" do
|
6
|
+
@btn_txt
|
7
|
+
end
|
8
|
+
}
|
9
|
+
|
10
|
+
@btn_txt = 'Pls,Click-Me.'
|
11
|
+
body = Proc.new { script }
|
12
|
+
|
13
|
+
template = Tilt.new('tilt_example.rb', 5, {}, &body)
|
14
|
+
puts template.render(self, :btn_size => "btn-lg")
|
15
|
+
|
16
|
+
# <div class="btn btn-succes btn-lg">
|
17
|
+
# Pls,Click-Me.
|
18
|
+
# </div>
|
data/lib/slight/config.rb
CHANGED
@@ -1,39 +1,39 @@
|
|
1
|
-
module Slight
|
2
|
-
class Configuration
|
3
|
-
def initialize(options = {}, &blk)
|
4
|
-
@options = options
|
5
|
-
@options[:cus] ||= {}
|
6
|
-
@options[:shortcutA] ||= {}
|
7
|
-
@options[:shortcutT] ||= {}
|
8
|
-
@options[:blinding] ||= {}
|
9
|
-
@options[:before_filter] ||= []
|
10
|
-
@options[:after_filter] ||= []
|
11
|
-
blk.call self
|
12
|
-
@options
|
13
|
-
end
|
14
|
-
|
15
|
-
def set(k, v); @options[:cus][k] = v; end
|
16
|
-
def get(k); @options[:cus][k]; end
|
17
|
-
def setIO(io_out); @options[:io_out] = io_out; end
|
18
|
-
def use(t, flag = :before)
|
19
|
-
if flag == :before then
|
20
|
-
@options[:before_filter].push(t)
|
21
|
-
else
|
22
|
-
@options[:after_filter].push(t)
|
23
|
-
end
|
24
|
-
end
|
25
|
-
|
26
|
-
def shortcut(type, pattern, replacement)
|
27
|
-
case(type)
|
28
|
-
when :A
|
29
|
-
@options[:shortcutA][pattern.to_sym] = replacement
|
30
|
-
when :T
|
31
|
-
@options[:shortcutT][pattern.to_sym] = replacement
|
32
|
-
end
|
33
|
-
end
|
34
|
-
|
35
|
-
def blinding(*system_fun)
|
36
|
-
@options[:blinding] = system_fun.map(&:to_sym)
|
37
|
-
end
|
38
|
-
end
|
39
|
-
end
|
1
|
+
module Slight
|
2
|
+
class Configuration
|
3
|
+
def initialize(options = {}, &blk)
|
4
|
+
@options = options
|
5
|
+
@options[:cus] ||= {}
|
6
|
+
@options[:shortcutA] ||= {}
|
7
|
+
@options[:shortcutT] ||= {}
|
8
|
+
@options[:blinding] ||= {}
|
9
|
+
@options[:before_filter] ||= []
|
10
|
+
@options[:after_filter] ||= []
|
11
|
+
blk.call self
|
12
|
+
@options
|
13
|
+
end
|
14
|
+
|
15
|
+
def set(k, v); @options[:cus][k] = v; end
|
16
|
+
def get(k); @options[:cus][k]; end
|
17
|
+
def setIO(io_out); @options[:io_out] = io_out; end
|
18
|
+
def use(t, flag = :before)
|
19
|
+
if flag == :before then
|
20
|
+
@options[:before_filter].push(t)
|
21
|
+
else
|
22
|
+
@options[:after_filter].push(t)
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
def shortcut(type, pattern, replacement)
|
27
|
+
case(type)
|
28
|
+
when :A
|
29
|
+
@options[:shortcutA][pattern.to_sym] = replacement
|
30
|
+
when :T
|
31
|
+
@options[:shortcutT][pattern.to_sym] = replacement
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
35
|
+
def blinding(*system_fun)
|
36
|
+
@options[:blinding] = system_fun.map(&:to_sym)
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|
data/lib/slight/const.rb
ADDED
@@ -0,0 +1,13 @@
|
|
1
|
+
VUEJS_DEV="https://vuejs.org/js/vue.js"
|
2
|
+
VUEJS="https://vuejs.org/js/vue.min.js"
|
3
|
+
BOOTSTRAPJS="https://bootswatch.com/_vendor/bootstrap/dist/js/bootstrap.min.js"
|
4
|
+
BOOTSTRAPJS_DEV="https://bootswatch.com/_vendor/bootstrap/dist/js/bootstrap.js"
|
5
|
+
JQUERY="https://bootswatch.com/_vendor/jquery/dist/jquery.min.js"
|
6
|
+
|
7
|
+
BOOTSTRAP_FLATY="https://bootswatch.com/4/flatly/bootstrap.min.css"
|
8
|
+
BOOTSTRAP_UNITED="https://bootswatch.com/4/united/bootstrap.min.css"
|
9
|
+
BOOTSTRAP="https://bootswatch.com/_vendor/bootstrap/dist/css/bootstrap.min.css"
|
10
|
+
BOOTSTRAP_LUX="https://bootswatch.com/4/lux/bootstrap.min.css"
|
11
|
+
BOOTSTRAP_SANDSTONE="https://bootswatch.com/4/sandstone/bootstrap.min.css"
|
12
|
+
BOOTSTRAP_SLATE="https://bootswatch.com/4/slate/bootstrap.min.css"
|
13
|
+
|
data/lib/slight/dsl.rb
CHANGED
@@ -1,169 +1,168 @@
|
|
1
|
-
require 'slight/utils'
|
2
|
-
|
3
|
-
module Slight
|
4
|
-
module DSLEssential
|
5
|
-
def br; echo "<br/>\n"; end
|
6
|
-
|
7
|
-
def hr; echo "<hr/>\n"; end
|
8
|
-
|
9
|
-
def title(str); echo "<title>#{str}</title>\n"; end
|
10
|
-
|
11
|
-
def js(str)
|
12
|
-
echo "<script language=\"javascript\">\n#{str}\n</script>\n"
|
13
|
-
end
|
14
|
-
|
15
|
-
def doctype(type)
|
16
|
-
case type
|
17
|
-
when :html, :h5
|
18
|
-
echo "<!DOCTYPE html>\n"
|
19
|
-
when :h11
|
20
|
-
echo %q[<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">] + "\n"
|
21
|
-
when :strict
|
22
|
-
echo %q[<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">] + "\n"
|
23
|
-
when :frameset
|
24
|
-
echo %q[<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Frameset//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-frameset.dtd">] + "\n"
|
25
|
-
when :mobile
|
26
|
-
echo %q[<!DOCTYPE html PUBLIC "-//WAPFORUM//DTD XHTML Mobile 1.2//EN" "http://www.openmobilealliance.org/tech/DTD/xhtml-mobile12.dtd">] + "\n"
|
27
|
-
when :basic
|
28
|
-
echo %q[<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML Basic 1.1//EN" "http://www.w3.org/TR/xhtml-basic/xhtml-basic11.dtd">] + "\n"
|
29
|
-
when :transitional
|
30
|
-
echo %q[<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">] + "\n"
|
31
|
-
when :xml
|
32
|
-
echo %q[<?xml version="1.0" encoding="utf-8" ?>] + "\n"
|
33
|
-
end
|
34
|
-
|
35
|
-
end
|
36
|
-
|
37
|
-
def use(uri, type=nil)
|
38
|
-
case type ||= uri.split('.')[-1]
|
39
|
-
when "js"
|
40
|
-
echo "<script type=\"text/javascript\" src=\"#{uri}\"></script>\n"
|
41
|
-
when "css"
|
42
|
-
echo "<link rel=\"stylesheet\" href=\"#{uri}\"></link>\n"
|
43
|
-
end
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
#
|
50
|
-
@load_history
|
51
|
-
|
52
|
-
@load_history.
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
#
|
63
|
-
#
|
64
|
-
#
|
65
|
-
|
66
|
-
|
67
|
-
#
|
68
|
-
#
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
include
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
|
114
|
-
|
115
|
-
|
116
|
-
|
117
|
-
|
118
|
-
|
119
|
-
|
120
|
-
|
121
|
-
|
122
|
-
|
123
|
-
|
124
|
-
|
125
|
-
|
126
|
-
|
127
|
-
|
128
|
-
|
129
|
-
|
130
|
-
|
131
|
-
|
132
|
-
|
133
|
-
|
134
|
-
|
135
|
-
|
136
|
-
|
137
|
-
|
138
|
-
|
139
|
-
|
140
|
-
|
141
|
-
|
142
|
-
at_new =
|
143
|
-
|
144
|
-
|
145
|
-
|
146
|
-
|
147
|
-
|
148
|
-
|
149
|
-
|
150
|
-
|
151
|
-
|
152
|
-
|
153
|
-
|
154
|
-
|
155
|
-
|
156
|
-
|
157
|
-
space
|
158
|
-
|
159
|
-
|
160
|
-
|
161
|
-
|
162
|
-
|
163
|
-
|
164
|
-
|
165
|
-
|
166
|
-
|
167
|
-
|
168
|
-
|
169
|
-
end
|
1
|
+
require 'slight/utils'
|
2
|
+
|
3
|
+
module Slight
|
4
|
+
module DSLEssential
|
5
|
+
def br; echo "<br/>\n"; end
|
6
|
+
|
7
|
+
def hr; echo "<hr/>\n"; end
|
8
|
+
|
9
|
+
def title(str); echo "<title>#{str}</title>\n"; end
|
10
|
+
|
11
|
+
def js(str)
|
12
|
+
echo "<script language=\"javascript\">\n#{str}\n</script>\n"
|
13
|
+
end
|
14
|
+
|
15
|
+
def doctype(type)
|
16
|
+
case type
|
17
|
+
when :html, :h5
|
18
|
+
echo "<!DOCTYPE html>\n"
|
19
|
+
when :h11
|
20
|
+
echo %q[<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">] + "\n"
|
21
|
+
when :strict
|
22
|
+
echo %q[<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">] + "\n"
|
23
|
+
when :frameset
|
24
|
+
echo %q[<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Frameset//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-frameset.dtd">] + "\n"
|
25
|
+
when :mobile
|
26
|
+
echo %q[<!DOCTYPE html PUBLIC "-//WAPFORUM//DTD XHTML Mobile 1.2//EN" "http://www.openmobilealliance.org/tech/DTD/xhtml-mobile12.dtd">] + "\n"
|
27
|
+
when :basic
|
28
|
+
echo %q[<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML Basic 1.1//EN" "http://www.w3.org/TR/xhtml-basic/xhtml-basic11.dtd">] + "\n"
|
29
|
+
when :transitional
|
30
|
+
echo %q[<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">] + "\n"
|
31
|
+
when :xml
|
32
|
+
echo %q[<?xml version="1.0" encoding="utf-8" ?>] + "\n"
|
33
|
+
end
|
34
|
+
|
35
|
+
end
|
36
|
+
|
37
|
+
def use(uri, type=nil)
|
38
|
+
case type ||= uri.split('.')[-1]
|
39
|
+
when "js",:js
|
40
|
+
echo "<script type=\"text/javascript\" src=\"#{uri}\"></script>\n"
|
41
|
+
when "css",:css
|
42
|
+
echo "<link rel=\"stylesheet\" href=\"#{uri}\"></link>\n"
|
43
|
+
end
|
44
|
+
end
|
45
|
+
|
46
|
+
# load another page into current page
|
47
|
+
def layout_yield(target_src)
|
48
|
+
#eval(File.new(target_src).read, binding_scope, target_src, __LINE__ - 48)
|
49
|
+
@load_history ||= [] # prevernt recursive page load
|
50
|
+
#unless @load_history[target_src] then
|
51
|
+
@load_history.push target_src
|
52
|
+
unless @load_history.count(target_src) == 2
|
53
|
+
self.instance_eval(File.new(target_src).read, target_src, __LINE__ - 48)
|
54
|
+
else
|
55
|
+
echo "<!--recursive page loading deteced, ignore.-->"
|
56
|
+
end
|
57
|
+
@load_history.pop
|
58
|
+
nil
|
59
|
+
end
|
60
|
+
|
61
|
+
# set the placeholder in current page
|
62
|
+
#def layout_placeholder(ph_alias="default")
|
63
|
+
# echo "<!--######|PLACEHOLDER-#{ph_alias}|######-->"
|
64
|
+
#end
|
65
|
+
|
66
|
+
# attach itself to the placeholder in anther page
|
67
|
+
#def layout_attach(page, ph_alias="default")
|
68
|
+
#end
|
69
|
+
|
70
|
+
end
|
71
|
+
|
72
|
+
class DSLException < ScriptError ; end
|
73
|
+
|
74
|
+
class DSL
|
75
|
+
include DSLEssential
|
76
|
+
include Utils
|
77
|
+
undef :p, :select
|
78
|
+
|
79
|
+
def initialize(io)
|
80
|
+
@output_buffer = io
|
81
|
+
#@root = page_node.new("root")
|
82
|
+
end
|
83
|
+
|
84
|
+
def puts(str); @output_buffer << html_escape(str); nil; end
|
85
|
+
|
86
|
+
def echo(str); @output_buffer << str; nil; end
|
87
|
+
|
88
|
+
def method_missing(fun, *param, &block)
|
89
|
+
__dsl__define(fun)
|
90
|
+
self.send(fun, *param, &block)
|
91
|
+
end
|
92
|
+
|
93
|
+
def binding_scope
|
94
|
+
binding
|
95
|
+
end
|
96
|
+
|
97
|
+
def resolve_shortcutA(shortcutA)
|
98
|
+
@__dsl__attr_replacements = shortcutA
|
99
|
+
end
|
100
|
+
|
101
|
+
def resolve_shortcutT(shortcutT)
|
102
|
+
@__dsl__tag_replacements = shortcutT
|
103
|
+
end
|
104
|
+
|
105
|
+
def resolve_blinding(blinding)
|
106
|
+
blinding.each do |m|
|
107
|
+
undef_method m
|
108
|
+
end
|
109
|
+
end
|
110
|
+
|
111
|
+
def resolve_local(var,val)
|
112
|
+
self.singleton_class.class_eval do
|
113
|
+
define_method(var.to_sym){
|
114
|
+
return val
|
115
|
+
}
|
116
|
+
end
|
117
|
+
end
|
118
|
+
|
119
|
+
private
|
120
|
+
def __dsl__define(tag)
|
121
|
+
self.singleton_class.class_eval do
|
122
|
+
define_method(tag){|*at, &block|
|
123
|
+
__dsl__packup(tag.to_s, *at, &block)
|
124
|
+
}
|
125
|
+
end
|
126
|
+
end
|
127
|
+
|
128
|
+
def __dsl__packup(tag, *at)
|
129
|
+
attr_replacements = @__dsl__attr_replacements||{}
|
130
|
+
tag_replacements = @__dsl__tag_replacements||{}
|
131
|
+
attrs=[]
|
132
|
+
|
133
|
+
if self_close = tag.end_with?("!") then
|
134
|
+
tag = tag[0..-2]
|
135
|
+
end
|
136
|
+
|
137
|
+
at.each do |var|
|
138
|
+
if var.class == Hash then
|
139
|
+
var.each_pair do |a, v|
|
140
|
+
unless a.to_sym == :_ then
|
141
|
+
at_new = attr_replacements.fetch(a, a)
|
142
|
+
at_new = v.class == String ? "#{at_new}=\"#{v}\"" : "#{at_new}=#{v.to_s}"
|
143
|
+
else
|
144
|
+
at_new = "#{v}"
|
145
|
+
end
|
146
|
+
attrs.push at_new
|
147
|
+
end
|
148
|
+
elsif var.class == String
|
149
|
+
attrs.push "class=\"#{var}\""
|
150
|
+
end
|
151
|
+
end
|
152
|
+
|
153
|
+
s_tag = tag_replacements.fetch(tag.to_sym, tag)
|
154
|
+
e_tag = s_tag.split(" ")[0]
|
155
|
+
|
156
|
+
space = attrs.length > 0 ? " " : ""
|
157
|
+
echo "<#{s_tag}#{space}#{attrs.join(" ")}"
|
158
|
+
if self_close then
|
159
|
+
echo "/>\n"
|
160
|
+
else
|
161
|
+
echo ">\n"
|
162
|
+
puts yield.to_s if block_given?
|
163
|
+
echo "</#{e_tag}>\n"
|
164
|
+
end
|
165
|
+
|
166
|
+
end
|
167
|
+
end
|
168
|
+
end
|
data/lib/slight/engine.rb
CHANGED
@@ -1,45 +1,45 @@
|
|
1
|
-
require 'slight/config'
|
2
|
-
require 'slight/template'
|
3
|
-
module Slight
|
4
|
-
class Filter; def self.do(src_data); return src_data; end; end
|
5
|
-
class Engine
|
6
|
-
def initialize(options = {})
|
7
|
-
@options = options
|
8
|
-
Configuration.new(@options) do |c|
|
9
|
-
c.shortcut :A, :css, "style"
|
10
|
-
c.shortcut :A, :ln, "href"
|
11
|
-
c.shortcut :A, :url, "href"
|
12
|
-
c.shortcut :A, :char, "charset"
|
13
|
-
c.shortcut :A, :fn, "src"
|
14
|
-
c.shortcut :A, :lang, "language"
|
15
|
-
c.shortcut :A, :xn, "xmlns"
|
16
|
-
c.shortcut :A, :mf, "manifest"
|
17
|
-
c.shortcut :T, "_", "div"
|
18
|
-
#c.shortcut :T, "js", %q[script language="javascript"]
|
19
|
-
#c.use PrettyHtmlOutput, :after if c.get(:pretty_html)
|
20
|
-
end
|
21
|
-
@template = Template.new(@options)
|
22
|
-
end
|
23
|
-
|
24
|
-
def render(src_file, src_data = nil, local_vars={})
|
25
|
-
# src file name is mainly using for identify issues for debugging
|
26
|
-
# if data not given then read data from src file
|
27
|
-
|
28
|
-
# Data > File
|
29
|
-
|
30
|
-
#src_data = script.call if block_given?
|
31
|
-
src_data ||= File.new(src_file).read
|
32
|
-
|
33
|
-
@options[:before_filter].each do |f|
|
34
|
-
src_data = f.do(src_data)
|
35
|
-
end
|
36
|
-
|
37
|
-
src_data = @template.render(src_data, src_file, local_vars)
|
38
|
-
|
39
|
-
@options[:after_filter].each do |f|
|
40
|
-
src_data = f.do(src_data)
|
41
|
-
end
|
42
|
-
src_data
|
43
|
-
end
|
44
|
-
end
|
45
|
-
end
|
1
|
+
require 'slight/config'
|
2
|
+
require 'slight/template'
|
3
|
+
module Slight
|
4
|
+
class Filter; def self.do(src_data); return src_data; end; end
|
5
|
+
class Engine
|
6
|
+
def initialize(options = {})
|
7
|
+
@options = options
|
8
|
+
Configuration.new(@options) do |c|
|
9
|
+
c.shortcut :A, :css, "style"
|
10
|
+
c.shortcut :A, :ln, "href"
|
11
|
+
c.shortcut :A, :url, "href"
|
12
|
+
c.shortcut :A, :char, "charset"
|
13
|
+
c.shortcut :A, :fn, "src"
|
14
|
+
c.shortcut :A, :lang, "language"
|
15
|
+
c.shortcut :A, :xn, "xmlns"
|
16
|
+
c.shortcut :A, :mf, "manifest"
|
17
|
+
c.shortcut :T, "_", "div"
|
18
|
+
#c.shortcut :T, "js", %q[script language="javascript"]
|
19
|
+
#c.use PrettyHtmlOutput, :after if c.get(:pretty_html)
|
20
|
+
end
|
21
|
+
@template = Template.new(@options)
|
22
|
+
end
|
23
|
+
|
24
|
+
def render(src_file, src_data = nil, local_vars={})
|
25
|
+
# src file name is mainly using for identify issues for debugging
|
26
|
+
# if data not given then read data from src file
|
27
|
+
|
28
|
+
# Data > File
|
29
|
+
|
30
|
+
#src_data = script.call if block_given?
|
31
|
+
src_data ||= File.new(src_file).read
|
32
|
+
|
33
|
+
@options[:before_filter].each do |f|
|
34
|
+
src_data = f.do(src_data)
|
35
|
+
end
|
36
|
+
|
37
|
+
src_data = @template.render(src_data, src_file, local_vars)
|
38
|
+
|
39
|
+
@options[:after_filter].each do |f|
|
40
|
+
src_data = f.do(src_data)
|
41
|
+
end
|
42
|
+
src_data
|
43
|
+
end
|
44
|
+
end
|
45
|
+
end
|
data/lib/slight/template.rb
CHANGED
@@ -1,38 +1,38 @@
|
|
1
|
-
require 'slight/dsl'
|
2
|
-
|
3
|
-
module Slight
|
4
|
-
class Template
|
5
|
-
def initialize(options = {})
|
6
|
-
@options = options
|
7
|
-
@output_buffer = @options[:io_out] || ""
|
8
|
-
@dsl = DSL.new(@output_buffer)
|
9
|
-
|
10
|
-
@dsl.resolve_shortcutA(@options[:shortcutA])
|
11
|
-
@dsl.resolve_shortcutT(@options[:shortcutT])
|
12
|
-
@dsl.resolve_blinding(@options[:blinding])
|
13
|
-
end
|
14
|
-
|
15
|
-
def render(src_data, src_file, local_vars = {})
|
16
|
-
@output_buffer.clear
|
17
|
-
|
18
|
-
local_vars.each_pair do |key, value|
|
19
|
-
if key == :__scope then
|
20
|
-
scope = value
|
21
|
-
scope_vars = scope.instance_variables
|
22
|
-
scope_vars.each do |var|
|
23
|
-
@dsl.instance_variable_set(var, scope.instance_variable_get(var))
|
24
|
-
end
|
25
|
-
else
|
26
|
-
@dsl.resolve_local(key, value)
|
27
|
-
end
|
28
|
-
end
|
29
|
-
|
30
|
-
begin
|
31
|
-
@dsl.instance_eval(src_data, src_file, __LINE__ - 20)
|
32
|
-
rescue => ex
|
33
|
-
raise DSLException.new(ex.message)
|
34
|
-
end
|
35
|
-
@output_buffer
|
36
|
-
end
|
37
|
-
end
|
38
|
-
end
|
1
|
+
require 'slight/dsl'
|
2
|
+
|
3
|
+
module Slight
|
4
|
+
class Template
|
5
|
+
def initialize(options = {})
|
6
|
+
@options = options
|
7
|
+
@output_buffer = @options[:io_out] || ""
|
8
|
+
@dsl = DSL.new(@output_buffer)
|
9
|
+
|
10
|
+
@dsl.resolve_shortcutA(@options[:shortcutA])
|
11
|
+
@dsl.resolve_shortcutT(@options[:shortcutT])
|
12
|
+
@dsl.resolve_blinding(@options[:blinding])
|
13
|
+
end
|
14
|
+
|
15
|
+
def render(src_data, src_file, local_vars = {})
|
16
|
+
@output_buffer.clear
|
17
|
+
|
18
|
+
local_vars.each_pair do |key, value|
|
19
|
+
if key == :__scope then
|
20
|
+
scope = value
|
21
|
+
scope_vars = scope.instance_variables
|
22
|
+
scope_vars.each do |var|
|
23
|
+
@dsl.instance_variable_set(var, scope.instance_variable_get(var))
|
24
|
+
end
|
25
|
+
else
|
26
|
+
@dsl.resolve_local(key, value)
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
begin
|
31
|
+
@dsl.instance_eval(src_data, src_file, __LINE__ - 20)
|
32
|
+
rescue => ex
|
33
|
+
raise DSLException.new(ex.message)
|
34
|
+
end
|
35
|
+
@output_buffer
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|