slight-lang 1.0.1 → 1.0.5
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 +223 -1
- 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/core.rb +29 -29
- data/example/custom_engine.rb +37 -37
- data/example/default_engine.rb +28 -28
- data/example/index.slight.rb +28 -33
- data/example/tilt_example.rb +18 -0
- data/lib/slight/config.rb +39 -38
- data/lib/slight/dsl.rb +169 -161
- data/lib/slight/engine.rb +45 -38
- data/lib/slight/template.rb +38 -28
- data/lib/slight/tilt.rb +26 -0
- data/lib/slight/utils.rb +38 -38
- data/lib/slight.rb +8 -6
- data/slight.gemspec +21 -21
- data/spec/bin_spec.rb +0 -0
- data/spec/dsl_spec.rb +0 -0
- data/spec/engine_spec.rb +0 -0
- metadata +8 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: c879ef00340954d40021fd0a09592e77e6a2ae64
|
4
|
+
data.tar.gz: 3db13c8f77e7fa90297f6e449fae62cf25aacf43
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: e1421b653fb2043448cdfcd18ea31206cca601173e6ceaae4c24fd7c1bcba09dba4177693da3ff367e928a6413ab3ea44c639ed8a9387b28b4c1b32632ae8dd1
|
7
|
+
data.tar.gz: 207e469de27f2ac0a9dd9a020d993728ef8e3ff4f55ad0be4df624ad9cf0704c311be59b9df5fe7dc8001a1a3df87acf226d95e12754e531248005fc28c9f8b7
|
data/.gitignore
CHANGED
@@ -1 +1 @@
|
|
1
|
-
*.gem
|
1
|
+
*.gem
|
data/LICENSE
CHANGED
@@ -1,22 +1,22 @@
|
|
1
|
-
The MIT License
|
2
|
-
|
3
|
-
Copyright (c) 2016 Slight
|
4
|
-
|
5
|
-
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
-
of this software and associated documentation files (the "Software"), to deal
|
7
|
-
in the Software without restriction, including without limitation the rights
|
8
|
-
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
-
copies of the Software, and to permit persons to whom the Software is
|
10
|
-
furnished to do so, subject to the following conditions:
|
11
|
-
|
12
|
-
The above copyright notice and this permission notice shall be included in
|
13
|
-
all copies or substantial portions of the Software.
|
14
|
-
|
15
|
-
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
-
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
-
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
-
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
-
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
-
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
21
|
-
THE SOFTWARE.
|
22
|
-
|
1
|
+
The MIT License
|
2
|
+
|
3
|
+
Copyright (c) 2016 Slight
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
7
|
+
in the Software without restriction, including without limitation the rights
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
10
|
+
furnished to do so, subject to the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be included in
|
13
|
+
all copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
21
|
+
THE SOFTWARE.
|
22
|
+
|
data/README.md
CHANGED
@@ -1 +1,223 @@
|
|
1
|
-
# Slight
|
1
|
+
# Slight-lang
|
2
|
+
A light and sweet template language.
|
3
|
+
|
4
|
+
## Description
|
5
|
+
Slight is a very simple and easy to use template language.
|
6
|
+
Advantage of Slight:
|
7
|
+
- Pure Ruby syntax
|
8
|
+
- Html friendly
|
9
|
+
- Nearly 0 learning cost
|
10
|
+
|
11
|
+
## Quick Start
|
12
|
+
#### [Installation]
|
13
|
+
```
|
14
|
+
gem install slight-lang
|
15
|
+
|
16
|
+
# you can also build gem from gemspec
|
17
|
+
gem build slight.gemspec
|
18
|
+
gem install ./slight-lang-1.0.1.gem
|
19
|
+
```
|
20
|
+
|
21
|
+
#### [Command]
|
22
|
+
###### Slight
|
23
|
+
```bash
|
24
|
+
slight [-v] <source> [<output>]
|
25
|
+
|
26
|
+
e.g.
|
27
|
+
slight index.slight index.htm
|
28
|
+
=> index.htm
|
29
|
+
|
30
|
+
slight index.slight
|
31
|
+
=> <tag>abcde</tag>
|
32
|
+
|
33
|
+
slight -v
|
34
|
+
=> v 1.0.1
|
35
|
+
```
|
36
|
+
|
37
|
+
###### REPL
|
38
|
+
```
|
39
|
+
slsh
|
40
|
+
```
|
41
|
+
- build-in commands
|
42
|
+
|
43
|
+
```ruby
|
44
|
+
# help
|
45
|
+
sl:> \h
|
46
|
+
@file => load and compile file dynamically. E.g. @/tmp/page.slight
|
47
|
+
>@ => set output. E.g. Open: >@/tmp/output. Turn off: >@off
|
48
|
+
\eg => example
|
49
|
+
\q => exit
|
50
|
+
\v => show version (also: \ver, \version)
|
51
|
+
|
52
|
+
|
53
|
+
# exit
|
54
|
+
sl:> \q (ctrl + c)
|
55
|
+
*** Exit now ***
|
56
|
+
--bye--
|
57
|
+
|
58
|
+
|
59
|
+
# show example
|
60
|
+
sl:> \eg
|
61
|
+
button "btn btn-primary" do
|
62
|
+
"Click me"
|
63
|
+
end
|
64
|
+
=>
|
65
|
+
<button class="btn btn-primary">Click me</button>
|
66
|
+
|
67
|
+
|
68
|
+
# compile slight file
|
69
|
+
sl:> @../../example/component.slight.rb
|
70
|
+
LOAD PATH="../../example/component.slight.rb"
|
71
|
+
<button class="btn btn-success btn-lg">
|
72
|
+
submit</button>
|
73
|
+
|
74
|
+
|
75
|
+
# redirect output to file
|
76
|
+
sl:> >@output.htm (>@off to turn off)
|
77
|
+
spool turned on
|
78
|
+
OUTPUT PATH="output.htm"
|
79
|
+
```
|
80
|
+
- Run Slight in REPL
|
81
|
+
|
82
|
+
```ruby
|
83
|
+
sl:> button 'btn btn-success btn-lg', name:'btn_submit', type:'submit' do
|
84
|
+
sl:> "Submit"
|
85
|
+
sl:> end
|
86
|
+
sl:> ; (Enter ';' to run the script)
|
87
|
+
|
88
|
+
<button class="btn btn-success btn-lg" name="btn_submit" type="submit">
|
89
|
+
Submit</button>
|
90
|
+
```
|
91
|
+
|
92
|
+
#### [Syntax]
|
93
|
+
|
94
|
+
- Pure Ruby Syntax
|
95
|
+
|
96
|
+
```ruby
|
97
|
+
tag_name "class", [attributes: id, name, style, etc.] do; <content>; end
|
98
|
+
|
99
|
+
e.g.
|
100
|
+
div "panel panel-lg", css: "border: 5 dotted green", id: "msgbox" do
|
101
|
+
button "btn btn-primary" do
|
102
|
+
"Ok"
|
103
|
+
end
|
104
|
+
button "btn btn-default" do
|
105
|
+
"Cancel"
|
106
|
+
end
|
107
|
+
end
|
108
|
+
|
109
|
+
(of course {} syntax is also spported)
|
110
|
+
```
|
111
|
+
- All html tags are supported
|
112
|
+
|
113
|
+
- Default Build-in Html Shortcuts
|
114
|
+
|
115
|
+
```ruby
|
116
|
+
[attribute]
|
117
|
+
css => "style"
|
118
|
+
ln => "href"
|
119
|
+
url => "href"
|
120
|
+
char => "charset"
|
121
|
+
fn => "src"
|
122
|
+
lang => "language"
|
123
|
+
xn => "xmlns"
|
124
|
+
mf => "manifest"
|
125
|
+
|
126
|
+
e.g.
|
127
|
+
|
128
|
+
div css:'border: 10 solid blue' do; "hello"; end
|
129
|
+
=>
|
130
|
+
<div style="border: 10 solid blue">
|
131
|
+
Hello
|
132
|
+
<div>
|
133
|
+
|
134
|
+
[tag]
|
135
|
+
_ => "<div>$content</div>"
|
136
|
+
js => "<script language='javscript'>$content</script>"
|
137
|
+
use => "<script type='text/javascript' src='$content'></script>"
|
138
|
+
use => "<link rel='stylesheet' href='$content'></link>"
|
139
|
+
# depends on which file loaded 'use' will determine which tag to replace.
|
140
|
+
|
141
|
+
e.g.
|
142
|
+
|
143
|
+
_ do; "hello"; end
|
144
|
+
=>
|
145
|
+
<div>hello</div>
|
146
|
+
|
147
|
+
|
148
|
+
js %{
|
149
|
+
console.log("hello slight");
|
150
|
+
}
|
151
|
+
=>
|
152
|
+
<script language="javascript">
|
153
|
+
console.log("hello slight");
|
154
|
+
</script>
|
155
|
+
|
156
|
+
|
157
|
+
use 'resource/bootstrap.js'
|
158
|
+
=>
|
159
|
+
<script type='text/javascript' src='resource/bootstrap.js'></script>
|
160
|
+
|
161
|
+
|
162
|
+
use 'resource/bootstrap.css'
|
163
|
+
=>
|
164
|
+
<link rel='stylesheet' href='resource/bootstrap.css'></link>
|
165
|
+
```
|
166
|
+
|
167
|
+
#### [Customize]
|
168
|
+
- general usage (more details please refer to example)
|
169
|
+
|
170
|
+
```ruby
|
171
|
+
conf = Slight::Configuration.new do |c|
|
172
|
+
c.shortcut :A, :endpoint, "href" #add an attribute shortcut
|
173
|
+
c.shortcut :T, "box", "div" #add a tag shortcut
|
174
|
+
end
|
175
|
+
|
176
|
+
custom_engine = Slight::Engine.new(conf)
|
177
|
+
```
|
178
|
+
|
179
|
+
- supported configuration
|
180
|
+
|
181
|
+
```ruby
|
182
|
+
conf = Slight::Configuration.new do |c|
|
183
|
+
c.shortcut :A, :endpoint, "href" #add an attribute shortcut
|
184
|
+
c.shortcut :T, "box", "div" #add a tag shotcut
|
185
|
+
|
186
|
+
# set output IO
|
187
|
+
c.setIO STDOUT
|
188
|
+
|
189
|
+
# undef ruby methods in slight context
|
190
|
+
c.blinding :p, :select, :puts, :send, :class
|
191
|
+
|
192
|
+
# use Filter
|
193
|
+
# Before-Filters accept original source pass the output to Slight compiler.
|
194
|
+
# After-Filters accept output from Slight compiler pass the output to end user.
|
195
|
+
c.use FilterA, :before
|
196
|
+
c.use FilterB, :after
|
197
|
+
end
|
198
|
+
```
|
199
|
+
|
200
|
+
#### [Tilt]
|
201
|
+
- Working with Tilt
|
202
|
+
```ruby
|
203
|
+
require 'slight/tilt'
|
204
|
+
|
205
|
+
script = %q{
|
206
|
+
div "btn btn-succes #{btn_size}" do
|
207
|
+
@btn_txt
|
208
|
+
end
|
209
|
+
}
|
210
|
+
|
211
|
+
@btn_txt = 'Pls,Click-Me.'
|
212
|
+
body = Proc.new { script }
|
213
|
+
|
214
|
+
template = Tilt.new('tilt_example.rb', 5, {}, &body)
|
215
|
+
puts template.render(self, :btn_size => "btn-lg")
|
216
|
+
|
217
|
+
# <div class="btn btn-succes btn-lg">
|
218
|
+
# Pls,Click-Me.
|
219
|
+
# </div>
|
220
|
+
```
|
221
|
+
|
222
|
+
|
223
|
+
Any questions or suggestions are welcome. You can reach me at: nemo1023#gmail.com
|
data/bin/repl/repl.rb
CHANGED
@@ -1,170 +1,170 @@
|
|
1
|
-
$:.unshift File.expand_path('../../../lib', __FILE__)
|
2
|
-
|
3
|
-
require_relative 'utils.rb'
|
4
|
-
require 'slight'
|
5
|
-
@default_engine = Slight::Engine.new
|
6
|
-
@slout = STDOUT
|
7
|
-
|
8
|
-
at_exit{
|
9
|
-
puts "\n--bye--".light_blue
|
10
|
-
@slout.close
|
11
|
-
}
|
12
|
-
|
13
|
-
Signal.trap("INT") do
|
14
|
-
puts "Terminating...".light_blue
|
15
|
-
puts "*** Exit now ***".light_blue
|
16
|
-
exit 1
|
17
|
-
end
|
18
|
-
|
19
|
-
def main
|
20
|
-
print_logo
|
21
|
-
buff = ""
|
22
|
-
loop do
|
23
|
-
print "sl:> "
|
24
|
-
case line = STDIN.readline.sub(/[\n\r]/,'').strip
|
25
|
-
when /^\\/ # build-in commands
|
26
|
-
case line
|
27
|
-
when "\\h"
|
28
|
-
print_help
|
29
|
-
when "\\eg"
|
30
|
-
print_example
|
31
|
-
when "\\q"
|
32
|
-
puts "*** Exit now ***".light_blue
|
33
|
-
exit 0
|
34
|
-
when /\\(v|version|ver)/
|
35
|
-
puts "ver #{Slight::VERSION}\n\n"
|
36
|
-
else
|
37
|
-
puts "Invalid command. type \\h for help.".red
|
38
|
-
end
|
39
|
-
when /^@/
|
40
|
-
if buff.size == 0 then
|
41
|
-
fn = line.sub('@','')
|
42
|
-
puts "LOAD PATH=\"#{fn}\"".light_blue
|
43
|
-
sl_handler(fn, is_file=true)
|
44
|
-
buff.clear
|
45
|
-
puts ""
|
46
|
-
else
|
47
|
-
buff << line << "\n"
|
48
|
-
end
|
49
|
-
when /^>@/
|
50
|
-
fn = line.split('@')[1] || ""
|
51
|
-
case fn.strip
|
52
|
-
when "off"
|
53
|
-
unless @slout == STDOUT
|
54
|
-
puts "spool turned off".light_blue
|
55
|
-
@slout.close
|
56
|
-
@slout = STDOUT
|
57
|
-
else
|
58
|
-
puts "spool was alread turned off".red
|
59
|
-
end
|
60
|
-
when ""
|
61
|
-
puts "spool turned off. output path not set.".red
|
62
|
-
else
|
63
|
-
unless @slout == STDOUT then
|
64
|
-
puts "spool was alread turned on".red
|
65
|
-
else
|
66
|
-
puts "spool turned on".light_blue
|
67
|
-
puts "OUTPUT PATH=\"#{fn}\"".light_blue
|
68
|
-
@slout = File.open(fn, 'w+')
|
69
|
-
end
|
70
|
-
end
|
71
|
-
when ";"
|
72
|
-
if buff.size > 0 then
|
73
|
-
sl_handler(buff)
|
74
|
-
buff.clear
|
75
|
-
@slout.flush #if @slout == STDOUT
|
76
|
-
puts ""
|
77
|
-
end
|
78
|
-
else
|
79
|
-
buff << line << "\n"
|
80
|
-
end
|
81
|
-
end
|
82
|
-
end
|
83
|
-
|
84
|
-
def sl_handler(buff, is_file=false)
|
85
|
-
if is_file
|
86
|
-
output = @default_engine.render(buff)
|
87
|
-
else
|
88
|
-
output = @default_engine.render("console",buff)
|
89
|
-
end
|
90
|
-
|
91
|
-
if @slout == STDOUT
|
92
|
-
@slout.puts output.green
|
93
|
-
else
|
94
|
-
@slout.puts output
|
95
|
-
end
|
96
|
-
rescue Exception => err
|
97
|
-
errno = err.message.split(":")[1].to_i - 1
|
98
|
-
buff.split("\n").each_with_index do |line, i|
|
99
|
-
if i == errno then
|
100
|
-
puts "=>#{i+1} #{line}".red
|
101
|
-
else
|
102
|
-
puts " #{i+1} #{line}".yellow
|
103
|
-
end
|
104
|
-
end
|
105
|
-
puts ""
|
106
|
-
STDERR.puts err.message.red
|
107
|
-
#STDERR.puts [err.inspect, err.backtrace.join("\n")].join("\n")
|
108
|
-
end
|
109
|
-
|
110
|
-
def print_help
|
111
|
-
puts " @file => load and compile file dynamically. E.g. @/tmp/page.slight".green
|
112
|
-
puts " >@ => set output. E.g. Open: >@/tmp/output. Turn off: >@off".green
|
113
|
-
puts " \\eg => example".green
|
114
|
-
puts " \\q => exit".green
|
115
|
-
puts " \\v => show version (also: \\ver, \\version)".green
|
116
|
-
puts
|
117
|
-
end
|
118
|
-
|
119
|
-
def print_example
|
120
|
-
eg1_in=%{
|
121
|
-
html do
|
122
|
-
head do
|
123
|
-
titile "My Page"
|
124
|
-
end
|
125
|
-
body do
|
126
|
-
button "btn btn-primary" do
|
127
|
-
"Click me"
|
128
|
-
end
|
129
|
-
end
|
130
|
-
end
|
131
|
-
}
|
132
|
-
|
133
|
-
eg1_out=%{
|
134
|
-
<html>
|
135
|
-
<head>
|
136
|
-
<title>My Page</title>
|
137
|
-
</head>
|
138
|
-
<body>
|
139
|
-
<button class="btn btn-primary">Click me</button>
|
140
|
-
</body>
|
141
|
-
</html>
|
142
|
-
}.green
|
143
|
-
|
144
|
-
eg2_in=%{
|
145
|
-
div("panel panel-lg", css:"color:green"){
|
146
|
-
span{"Hello World"}
|
147
|
-
}
|
148
|
-
}
|
149
|
-
|
150
|
-
eg2_out=%{
|
151
|
-
<div class="panel panel-lg", style="color:green">
|
152
|
-
<span>Hello World</span>
|
153
|
-
</div>
|
154
|
-
}.green
|
155
|
-
|
156
|
-
puts eg1_in
|
157
|
-
puts "=>\n" + eg1_out
|
158
|
-
puts
|
159
|
-
puts eg2_in
|
160
|
-
puts "=>\n" + eg2_out
|
161
|
-
|
162
|
-
end
|
163
|
-
|
164
|
-
def print_logo
|
165
|
-
puts "**************************\n* Welcome to Slight REPL *".green
|
166
|
-
puts "**************************".green
|
167
|
-
puts "\\h for help.\n\n".green
|
168
|
-
end
|
169
|
-
|
170
|
-
main
|
1
|
+
$:.unshift File.expand_path('../../../lib', __FILE__)
|
2
|
+
|
3
|
+
require_relative 'utils.rb'
|
4
|
+
require 'slight'
|
5
|
+
@default_engine = Slight::Engine.new
|
6
|
+
@slout = STDOUT
|
7
|
+
|
8
|
+
at_exit{
|
9
|
+
puts "\n--bye--".light_blue
|
10
|
+
@slout.close
|
11
|
+
}
|
12
|
+
|
13
|
+
Signal.trap("INT") do
|
14
|
+
puts "Terminating...".light_blue
|
15
|
+
puts "*** Exit now ***".light_blue
|
16
|
+
exit 1
|
17
|
+
end
|
18
|
+
|
19
|
+
def main
|
20
|
+
print_logo
|
21
|
+
buff = ""
|
22
|
+
loop do
|
23
|
+
print "sl:> "
|
24
|
+
case line = STDIN.readline.sub(/[\n\r]/,'').strip
|
25
|
+
when /^\\/ # build-in commands
|
26
|
+
case line
|
27
|
+
when "\\h"
|
28
|
+
print_help
|
29
|
+
when "\\eg"
|
30
|
+
print_example
|
31
|
+
when "\\q"
|
32
|
+
puts "*** Exit now ***".light_blue
|
33
|
+
exit 0
|
34
|
+
when /\\(v|version|ver)/
|
35
|
+
puts "ver #{Slight::VERSION}\n\n"
|
36
|
+
else
|
37
|
+
puts "Invalid command. type \\h for help.".red
|
38
|
+
end
|
39
|
+
when /^@/
|
40
|
+
if buff.size == 0 then
|
41
|
+
fn = line.sub('@','')
|
42
|
+
puts "LOAD PATH=\"#{fn}\"".light_blue
|
43
|
+
sl_handler(fn, is_file=true)
|
44
|
+
buff.clear
|
45
|
+
puts ""
|
46
|
+
else
|
47
|
+
buff << line << "\n"
|
48
|
+
end
|
49
|
+
when /^>@/
|
50
|
+
fn = line.split('@')[1] || ""
|
51
|
+
case fn.strip
|
52
|
+
when "off"
|
53
|
+
unless @slout == STDOUT
|
54
|
+
puts "spool turned off".light_blue
|
55
|
+
@slout.close
|
56
|
+
@slout = STDOUT
|
57
|
+
else
|
58
|
+
puts "spool was alread turned off".red
|
59
|
+
end
|
60
|
+
when ""
|
61
|
+
puts "spool turned off. output path not set.".red
|
62
|
+
else
|
63
|
+
unless @slout == STDOUT then
|
64
|
+
puts "spool was alread turned on".red
|
65
|
+
else
|
66
|
+
puts "spool turned on".light_blue
|
67
|
+
puts "OUTPUT PATH=\"#{fn}\"".light_blue
|
68
|
+
@slout = File.open(fn, 'w+')
|
69
|
+
end
|
70
|
+
end
|
71
|
+
when ";"
|
72
|
+
if buff.size > 0 then
|
73
|
+
sl_handler(buff)
|
74
|
+
buff.clear
|
75
|
+
@slout.flush #if @slout == STDOUT
|
76
|
+
puts ""
|
77
|
+
end
|
78
|
+
else
|
79
|
+
buff << line << "\n"
|
80
|
+
end
|
81
|
+
end
|
82
|
+
end
|
83
|
+
|
84
|
+
def sl_handler(buff, is_file=false)
|
85
|
+
if is_file
|
86
|
+
output = @default_engine.render(buff)
|
87
|
+
else
|
88
|
+
output = @default_engine.render("console",buff)
|
89
|
+
end
|
90
|
+
|
91
|
+
if @slout == STDOUT
|
92
|
+
@slout.puts output.green
|
93
|
+
else
|
94
|
+
@slout.puts output
|
95
|
+
end
|
96
|
+
rescue Exception => err
|
97
|
+
errno = err.message.split(":")[1].to_i - 1
|
98
|
+
buff.split("\n").each_with_index do |line, i|
|
99
|
+
if i == errno then
|
100
|
+
puts "=>#{i+1} #{line}".red
|
101
|
+
else
|
102
|
+
puts " #{i+1} #{line}".yellow
|
103
|
+
end
|
104
|
+
end
|
105
|
+
puts ""
|
106
|
+
STDERR.puts err.message.red
|
107
|
+
#STDERR.puts [err.inspect, err.backtrace.join("\n")].join("\n")
|
108
|
+
end
|
109
|
+
|
110
|
+
def print_help
|
111
|
+
puts " @file => load and compile file dynamically. E.g. @/tmp/page.slight".green
|
112
|
+
puts " >@ => set output. E.g. Open: >@/tmp/output. Turn off: >@off".green
|
113
|
+
puts " \\eg => example".green
|
114
|
+
puts " \\q => exit".green
|
115
|
+
puts " \\v => show version (also: \\ver, \\version)".green
|
116
|
+
puts
|
117
|
+
end
|
118
|
+
|
119
|
+
def print_example
|
120
|
+
eg1_in=%{
|
121
|
+
html do
|
122
|
+
head do
|
123
|
+
titile "My Page"
|
124
|
+
end
|
125
|
+
body do
|
126
|
+
button "btn btn-primary" do
|
127
|
+
"Click me"
|
128
|
+
end
|
129
|
+
end
|
130
|
+
end
|
131
|
+
}
|
132
|
+
|
133
|
+
eg1_out=%{
|
134
|
+
<html>
|
135
|
+
<head>
|
136
|
+
<title>My Page</title>
|
137
|
+
</head>
|
138
|
+
<body>
|
139
|
+
<button class="btn btn-primary">Click me</button>
|
140
|
+
</body>
|
141
|
+
</html>
|
142
|
+
}.green
|
143
|
+
|
144
|
+
eg2_in=%{
|
145
|
+
div("panel panel-lg", css:"color:green"){
|
146
|
+
span{"Hello World"}
|
147
|
+
}
|
148
|
+
}
|
149
|
+
|
150
|
+
eg2_out=%{
|
151
|
+
<div class="panel panel-lg", style="color:green">
|
152
|
+
<span>Hello World</span>
|
153
|
+
</div>
|
154
|
+
}.green
|
155
|
+
|
156
|
+
puts eg1_in
|
157
|
+
puts "=>\n" + eg1_out
|
158
|
+
puts
|
159
|
+
puts eg2_in
|
160
|
+
puts "=>\n" + eg2_out
|
161
|
+
|
162
|
+
end
|
163
|
+
|
164
|
+
def print_logo
|
165
|
+
puts "**************************\n* Welcome to Slight REPL *".green
|
166
|
+
puts "**************************".green
|
167
|
+
puts "\\h for help.\n\n".green
|
168
|
+
end
|
169
|
+
|
170
|
+
main
|
data/bin/repl/utils.rb
CHANGED
@@ -1,29 +1,29 @@
|
|
1
|
-
# from stack overflow
|
2
|
-
class String
|
3
|
-
# colorization
|
4
|
-
def colorize(color_code); "\e[#{color_code}m#{self}\e[0m"; end
|
5
|
-
def light_blue; "\e[36m#{self}\e[0m"; end
|
6
|
-
def black; "\e[30m#{self}\e[0m"; end
|
7
|
-
def red; "\e[31m#{self}\e[0m"; end
|
8
|
-
def green; "\e[32m#{self}\e[0m"; end
|
9
|
-
def yellow; "\e[33m#{self}\e[0m"; end
|
10
|
-
def blue; "\e[34m#{self}\e[0m"; end
|
11
|
-
def magenta; "\e[35m#{self}\e[0m"; end
|
12
|
-
def cyan; "\e[36m#{self}\e[0m"; end
|
13
|
-
def gray; "\e[37m#{self}\e[0m"; end
|
14
|
-
|
15
|
-
def bg_black; "\e[40m#{self}\e[0m"; end
|
16
|
-
def bg_red; "\e[41m#{self}\e[0m"; end
|
17
|
-
def bg_green; "\e[42m#{self}\e[0m"; end
|
18
|
-
def bg_brown; "\e[43m#{self}\e[0m"; end
|
19
|
-
def bg_blue; "\e[44m#{self}\e[0m"; end
|
20
|
-
def bg_magenta; "\e[45m#{self}\e[0m"; end
|
21
|
-
def bg_cyan; "\e[46m#{self}\e[0m"; end
|
22
|
-
def bg_gray; "\e[47m#{self}\e[0m"; end
|
23
|
-
|
24
|
-
def bold; "\e[1m#{self}\e[22m"; end
|
25
|
-
def italic; "\e[3m#{self}\e[23m"; end
|
26
|
-
def underline; "\e[4m#{self}\e[24m"; end
|
27
|
-
def blink; "\e[5m#{self}\e[25m"; end
|
28
|
-
def reverse_color; "\e[7m#{self}\e[27m"; end
|
29
|
-
end
|
1
|
+
# from stack overflow
|
2
|
+
class String
|
3
|
+
# colorization
|
4
|
+
def colorize(color_code); "\e[#{color_code}m#{self}\e[0m"; end
|
5
|
+
def light_blue; "\e[36m#{self}\e[0m"; end
|
6
|
+
def black; "\e[30m#{self}\e[0m"; end
|
7
|
+
def red; "\e[31m#{self}\e[0m"; end
|
8
|
+
def green; "\e[32m#{self}\e[0m"; end
|
9
|
+
def yellow; "\e[33m#{self}\e[0m"; end
|
10
|
+
def blue; "\e[34m#{self}\e[0m"; end
|
11
|
+
def magenta; "\e[35m#{self}\e[0m"; end
|
12
|
+
def cyan; "\e[36m#{self}\e[0m"; end
|
13
|
+
def gray; "\e[37m#{self}\e[0m"; end
|
14
|
+
|
15
|
+
def bg_black; "\e[40m#{self}\e[0m"; end
|
16
|
+
def bg_red; "\e[41m#{self}\e[0m"; end
|
17
|
+
def bg_green; "\e[42m#{self}\e[0m"; end
|
18
|
+
def bg_brown; "\e[43m#{self}\e[0m"; end
|
19
|
+
def bg_blue; "\e[44m#{self}\e[0m"; end
|
20
|
+
def bg_magenta; "\e[45m#{self}\e[0m"; end
|
21
|
+
def bg_cyan; "\e[46m#{self}\e[0m"; end
|
22
|
+
def bg_gray; "\e[47m#{self}\e[0m"; end
|
23
|
+
|
24
|
+
def bold; "\e[1m#{self}\e[22m"; end
|
25
|
+
def italic; "\e[3m#{self}\e[23m"; end
|
26
|
+
def underline; "\e[4m#{self}\e[24m"; end
|
27
|
+
def blink; "\e[5m#{self}\e[25m"; end
|
28
|
+
def reverse_color; "\e[7m#{self}\e[27m"; end
|
29
|
+
end
|
data/bin/slight
CHANGED
@@ -1,2 +1,2 @@
|
|
1
|
-
#!/usr/bin/env ruby
|
2
|
-
require_relative '../example/default_engine.rb'
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
require_relative '../example/default_engine.rb'
|