slight-lang 1.0.1 → 1.0.5
Sign up to get free protection for your applications and to get access to all the features.
- 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
data/lib/slight/dsl.rb
CHANGED
@@ -1,161 +1,169 @@
|
|
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
|
-
end
|
46
|
-
|
47
|
-
# load another page into current page
|
48
|
-
def layout_yield(target_src)
|
49
|
-
#eval(File.new(target_src).read, binding_scope, target_src, __LINE__ - 48)
|
50
|
-
@load_history ||= [] # prevernt recursive page load
|
51
|
-
#unless @load_history[target_src] then
|
52
|
-
@load_history.push target_src
|
53
|
-
unless @load_history.count(target_src) == 2
|
54
|
-
self.instance_eval(File.new(target_src).read, target_src, __LINE__ - 48)
|
55
|
-
else
|
56
|
-
echo "<!--recursive page loading deteced, ignore.-->"
|
57
|
-
end
|
58
|
-
@load_history.pop
|
59
|
-
nil
|
60
|
-
end
|
61
|
-
|
62
|
-
# set the placeholder in current page
|
63
|
-
#def layout_placeholder(ph_alias="default")
|
64
|
-
# echo "<!--######|PLACEHOLDER-#{ph_alias}|######-->"
|
65
|
-
#end
|
66
|
-
|
67
|
-
# attach itself to the placeholder in anther page
|
68
|
-
#def layout_attach(page, ph_alias="default")
|
69
|
-
#end
|
70
|
-
|
71
|
-
end
|
72
|
-
|
73
|
-
class DSLException < ScriptError ; end
|
74
|
-
|
75
|
-
class DSL
|
76
|
-
include DSLEssential
|
77
|
-
include Utils
|
78
|
-
undef :p, :select
|
79
|
-
|
80
|
-
def initialize(io)
|
81
|
-
@output_buffer = io
|
82
|
-
#@root = page_node.new("root")
|
83
|
-
end
|
84
|
-
|
85
|
-
def puts(str); @output_buffer << html_escape(str); nil; end
|
86
|
-
|
87
|
-
def echo(str); @output_buffer << str; nil; end
|
88
|
-
|
89
|
-
def method_missing(fun, *param, &block)
|
90
|
-
__dsl__define(fun)
|
91
|
-
self.send(fun, *param, &block)
|
92
|
-
end
|
93
|
-
|
94
|
-
def binding_scope
|
95
|
-
binding
|
96
|
-
end
|
97
|
-
|
98
|
-
def resolve_shortcutA(shortcutA)
|
99
|
-
@__dsl__attr_replacements = shortcutA
|
100
|
-
end
|
101
|
-
|
102
|
-
def resolve_shortcutT(shortcutT)
|
103
|
-
@__dsl__tag_replacements = shortcutT
|
104
|
-
end
|
105
|
-
|
106
|
-
def resolve_blinding(blinding)
|
107
|
-
blinding.each do |m|
|
108
|
-
undef_method m
|
109
|
-
end
|
110
|
-
end
|
111
|
-
|
112
|
-
|
113
|
-
|
114
|
-
|
115
|
-
|
116
|
-
|
117
|
-
|
118
|
-
|
119
|
-
|
120
|
-
|
121
|
-
def
|
122
|
-
|
123
|
-
|
124
|
-
|
125
|
-
|
126
|
-
|
127
|
-
|
128
|
-
|
129
|
-
|
130
|
-
|
131
|
-
|
132
|
-
|
133
|
-
|
134
|
-
|
135
|
-
|
136
|
-
|
137
|
-
|
138
|
-
|
139
|
-
|
140
|
-
|
141
|
-
|
142
|
-
|
143
|
-
|
144
|
-
|
145
|
-
|
146
|
-
|
147
|
-
|
148
|
-
|
149
|
-
|
150
|
-
|
151
|
-
|
152
|
-
|
153
|
-
|
154
|
-
|
155
|
-
|
156
|
-
|
157
|
-
|
158
|
-
|
159
|
-
|
160
|
-
|
161
|
-
|
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
|
+
end
|
46
|
+
|
47
|
+
# load another page into current page
|
48
|
+
def layout_yield(target_src)
|
49
|
+
#eval(File.new(target_src).read, binding_scope, target_src, __LINE__ - 48)
|
50
|
+
@load_history ||= [] # prevernt recursive page load
|
51
|
+
#unless @load_history[target_src] then
|
52
|
+
@load_history.push target_src
|
53
|
+
unless @load_history.count(target_src) == 2
|
54
|
+
self.instance_eval(File.new(target_src).read, target_src, __LINE__ - 48)
|
55
|
+
else
|
56
|
+
echo "<!--recursive page loading deteced, ignore.-->"
|
57
|
+
end
|
58
|
+
@load_history.pop
|
59
|
+
nil
|
60
|
+
end
|
61
|
+
|
62
|
+
# set the placeholder in current page
|
63
|
+
#def layout_placeholder(ph_alias="default")
|
64
|
+
# echo "<!--######|PLACEHOLDER-#{ph_alias}|######-->"
|
65
|
+
#end
|
66
|
+
|
67
|
+
# attach itself to the placeholder in anther page
|
68
|
+
#def layout_attach(page, ph_alias="default")
|
69
|
+
#end
|
70
|
+
|
71
|
+
end
|
72
|
+
|
73
|
+
class DSLException < ScriptError ; end
|
74
|
+
|
75
|
+
class DSL
|
76
|
+
include DSLEssential
|
77
|
+
include Utils
|
78
|
+
undef :p, :select
|
79
|
+
|
80
|
+
def initialize(io)
|
81
|
+
@output_buffer = io
|
82
|
+
#@root = page_node.new("root")
|
83
|
+
end
|
84
|
+
|
85
|
+
def puts(str); @output_buffer << html_escape(str); nil; end
|
86
|
+
|
87
|
+
def echo(str); @output_buffer << str; nil; end
|
88
|
+
|
89
|
+
def method_missing(fun, *param, &block)
|
90
|
+
__dsl__define(fun)
|
91
|
+
self.send(fun, *param, &block)
|
92
|
+
end
|
93
|
+
|
94
|
+
def binding_scope
|
95
|
+
binding
|
96
|
+
end
|
97
|
+
|
98
|
+
def resolve_shortcutA(shortcutA)
|
99
|
+
@__dsl__attr_replacements = shortcutA
|
100
|
+
end
|
101
|
+
|
102
|
+
def resolve_shortcutT(shortcutT)
|
103
|
+
@__dsl__tag_replacements = shortcutT
|
104
|
+
end
|
105
|
+
|
106
|
+
def resolve_blinding(blinding)
|
107
|
+
blinding.each do |m|
|
108
|
+
undef_method m
|
109
|
+
end
|
110
|
+
end
|
111
|
+
|
112
|
+
def resolve_local(var,val)
|
113
|
+
self.singleton_class.class_eval do
|
114
|
+
define_method(var.to_sym){
|
115
|
+
return val
|
116
|
+
}
|
117
|
+
end
|
118
|
+
end
|
119
|
+
|
120
|
+
private
|
121
|
+
def __dsl__define(tag)
|
122
|
+
self.singleton_class.class_eval do
|
123
|
+
define_method(tag){|*at, &block|
|
124
|
+
__dsl__packup(tag.to_s, *at, &block)
|
125
|
+
}
|
126
|
+
end
|
127
|
+
end
|
128
|
+
|
129
|
+
def __dsl__packup(tag, *at)
|
130
|
+
attr_replacements = @__dsl__attr_replacements||{}
|
131
|
+
tag_replacements = @__dsl__tag_replacements||{}
|
132
|
+
attrs=[]
|
133
|
+
|
134
|
+
if self_close = tag.end_with?("!") then
|
135
|
+
tag = tag[0..-2]
|
136
|
+
end
|
137
|
+
|
138
|
+
at.each do |var|
|
139
|
+
if var.class == Hash then
|
140
|
+
var.each_pair do |a, v|
|
141
|
+
unless a.to_sym == :_ then
|
142
|
+
at_new = attr_replacements.fetch(a, a)
|
143
|
+
at_new = v.class == String ? "#{at_new}=\"#{v}\"" : "#{at_new}=#{v.to_s}"
|
144
|
+
else
|
145
|
+
at_new = "#{v}"
|
146
|
+
end
|
147
|
+
attrs.push at_new
|
148
|
+
end
|
149
|
+
elsif var.class == String
|
150
|
+
attrs.push "class=\"#{var}\""
|
151
|
+
end
|
152
|
+
end
|
153
|
+
|
154
|
+
s_tag = tag_replacements.fetch(tag.to_sym, tag)
|
155
|
+
e_tag = s_tag.split(" ")[0]
|
156
|
+
|
157
|
+
space = attrs.length > 0 ? " " : ""
|
158
|
+
echo "<#{s_tag}#{space}#{attrs.join(" ")}"
|
159
|
+
if self_close then
|
160
|
+
echo "/>\n"
|
161
|
+
else
|
162
|
+
echo ">\n"
|
163
|
+
puts yield.to_s if block_given?
|
164
|
+
echo "</#{e_tag}>\n"
|
165
|
+
end
|
166
|
+
|
167
|
+
end
|
168
|
+
end
|
169
|
+
end
|
data/lib/slight/engine.rb
CHANGED
@@ -1,38 +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
|
-
|
29
|
-
|
30
|
-
|
31
|
-
src_data
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
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,28 +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
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
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
|
data/lib/slight/tilt.rb
ADDED
@@ -0,0 +1,26 @@
|
|
1
|
+
require 'tilt'
|
2
|
+
require 'tilt/template'
|
3
|
+
require 'slight'
|
4
|
+
|
5
|
+
module Tilt
|
6
|
+
class SlightTemplate < Template
|
7
|
+
self.default_mime_type = 'text/html'
|
8
|
+
|
9
|
+
def prepare
|
10
|
+
@engine = ::Slight::Engine.new
|
11
|
+
#@engine = ::ERB.new(data, options[:safe], options[:trim], @outvar)
|
12
|
+
end
|
13
|
+
|
14
|
+
def evaluate(scope, locals, &block)
|
15
|
+
#scope_vars = scope.instance_variables
|
16
|
+
#scope_vars.each do |var|
|
17
|
+
# @engine.instance_variable_set(var, scope.instance_variable_get(var))
|
18
|
+
#end
|
19
|
+
locals[:__scope] = scope
|
20
|
+
@output ||= @engine.render(file, data, locals)
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
register_lazy "SlightTemplate", 'slight/tilt', 'slight', 'rb'
|
25
|
+
|
26
|
+
end
|
data/lib/slight/utils.rb
CHANGED
@@ -1,38 +1,38 @@
|
|
1
|
-
# Borrow from ERB Source
|
2
|
-
# ERB::Util
|
3
|
-
module Slight
|
4
|
-
module Utils
|
5
|
-
public
|
6
|
-
# A utility method for escaping HTML tag characters in _s_.
|
7
|
-
#
|
8
|
-
# require "erb"
|
9
|
-
# include ERB::Util
|
10
|
-
#
|
11
|
-
# puts html_escape("is a > 0 & a < 10?")
|
12
|
-
#
|
13
|
-
# _Generates_
|
14
|
-
#
|
15
|
-
# is a > 0 & a < 10?
|
16
|
-
#
|
17
|
-
# [Slight] => Add: gsub(/[[:blank:]]/," ") to support space.
|
18
|
-
def html_escape(s)
|
19
|
-
s.to_s.gsub(/&/, "&").gsub(/[[:blank:]]/," ").gsub(/\"/, """).gsub(/>/, ">").gsub(/</, "<")
|
20
|
-
end
|
21
|
-
module_function :html_escape
|
22
|
-
# A utility method for encoding the String _s_ as a URL.
|
23
|
-
#
|
24
|
-
# require "erb"
|
25
|
-
# include ERB::Util
|
26
|
-
#
|
27
|
-
# puts url_encode("Programming Ruby: The Pragmatic Programmer's Guide")
|
28
|
-
#
|
29
|
-
# _Generates_
|
30
|
-
#
|
31
|
-
# Programming%20Ruby%3A%20%20The%20Pragmatic%20Programmer%27s%20Guide
|
32
|
-
#
|
33
|
-
def url_encode(s)
|
34
|
-
s.to_s.gsub(/[^a-zA-Z0-9_\-.]/n){ sprintf("%%%02X", $&.unpack("C")[0]) }
|
35
|
-
end
|
36
|
-
module_function :url_encode
|
37
|
-
end
|
38
|
-
end
|
1
|
+
# Borrow from ERB Source
|
2
|
+
# ERB::Util
|
3
|
+
module Slight
|
4
|
+
module Utils
|
5
|
+
public
|
6
|
+
# A utility method for escaping HTML tag characters in _s_.
|
7
|
+
#
|
8
|
+
# require "erb"
|
9
|
+
# include ERB::Util
|
10
|
+
#
|
11
|
+
# puts html_escape("is a > 0 & a < 10?")
|
12
|
+
#
|
13
|
+
# _Generates_
|
14
|
+
#
|
15
|
+
# is a > 0 & a < 10?
|
16
|
+
#
|
17
|
+
# [Slight] => Add: gsub(/[[:blank:]]/," ") to support space.
|
18
|
+
def html_escape(s)
|
19
|
+
s.to_s.gsub(/&/, "&").gsub(/[[:blank:]]/," ").gsub(/\"/, """).gsub(/>/, ">").gsub(/</, "<")
|
20
|
+
end
|
21
|
+
module_function :html_escape
|
22
|
+
# A utility method for encoding the String _s_ as a URL.
|
23
|
+
#
|
24
|
+
# require "erb"
|
25
|
+
# include ERB::Util
|
26
|
+
#
|
27
|
+
# puts url_encode("Programming Ruby: The Pragmatic Programmer's Guide")
|
28
|
+
#
|
29
|
+
# _Generates_
|
30
|
+
#
|
31
|
+
# Programming%20Ruby%3A%20%20The%20Pragmatic%20Programmer%27s%20Guide
|
32
|
+
#
|
33
|
+
def url_encode(s)
|
34
|
+
s.to_s.gsub(/[^a-zA-Z0-9_\-.]/n){ sprintf("%%%02X", $&.unpack("C")[0]) }
|
35
|
+
end
|
36
|
+
module_function :url_encode
|
37
|
+
end
|
38
|
+
end
|
data/lib/slight.rb
CHANGED
@@ -1,6 +1,8 @@
|
|
1
|
-
require 'slight/engine'
|
2
|
-
module Slight
|
3
|
-
# Slight version string
|
4
|
-
# @api public
|
5
|
-
VERSION = '1.0.
|
6
|
-
|
1
|
+
require 'slight/engine'
|
2
|
+
module Slight
|
3
|
+
# Slight version string
|
4
|
+
# @api public
|
5
|
+
VERSION = '1.0.5'
|
6
|
+
# 1.0.0 => Basic Template features | 201703
|
7
|
+
# 1.0.5 => Support Tilt, Render Scope Binding | 201704
|
8
|
+
end
|
data/slight.gemspec
CHANGED
@@ -1,21 +1,21 @@
|
|
1
|
-
# -*- encoding: utf-8
|
2
|
-
$:.unshift File.expand_path('../lib', __FILE__)
|
3
|
-
require 'slight'
|
4
|
-
|
5
|
-
Gem::Specification.new do |gem|
|
6
|
-
gem.authors = ["oliver.yu"]
|
7
|
-
gem.email = ["nemo1023@gmail.com"]
|
8
|
-
gem.description = %q{A light and sweet template language}
|
9
|
-
gem.summary = %q{The goal of this is to use ruby syntax and html style shotcut to write template.}
|
10
|
-
gem.homepage = "https://github.com/OliversCat/Slight"
|
11
|
-
gem.files = `git ls-files`.split($\)
|
12
|
-
#gem.files = dir('.')
|
13
|
-
#gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) unless f.end_with? ".rb" }
|
14
|
-
gem.executables = ["slsh","slight"]
|
15
|
-
#gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
|
16
|
-
gem.test_files = ["spec"]
|
17
|
-
gem.name = "slight-lang"
|
18
|
-
gem.require_paths = ["lib"]
|
19
|
-
gem.version = Slight::VERSION
|
20
|
-
gem.license = "MIT"
|
21
|
-
end
|
1
|
+
# -*- encoding: utf-8
|
2
|
+
$:.unshift File.expand_path('../lib', __FILE__)
|
3
|
+
require 'slight'
|
4
|
+
|
5
|
+
Gem::Specification.new do |gem|
|
6
|
+
gem.authors = ["oliver.yu"]
|
7
|
+
gem.email = ["nemo1023@gmail.com"]
|
8
|
+
gem.description = %q{A light and sweet template language}
|
9
|
+
gem.summary = %q{The goal of this is to use ruby syntax and html style shotcut to write template.}
|
10
|
+
gem.homepage = "https://github.com/OliversCat/Slight"
|
11
|
+
gem.files = `git ls-files`.split($\)
|
12
|
+
#gem.files = dir('.')
|
13
|
+
#gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) unless f.end_with? ".rb" }
|
14
|
+
gem.executables = ["slsh","slight"]
|
15
|
+
#gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
|
16
|
+
gem.test_files = ["spec"]
|
17
|
+
gem.name = "slight-lang"
|
18
|
+
gem.require_paths = ["lib"]
|
19
|
+
gem.version = Slight::VERSION
|
20
|
+
gem.license = "MIT"
|
21
|
+
end
|
data/spec/bin_spec.rb
ADDED
File without changes
|
data/spec/dsl_spec.rb
ADDED
File without changes
|
data/spec/engine_spec.rb
ADDED
File without changes
|