slight-lang 1.0.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: aee03d439807e155008d14dfb189c1bbb51fe5e0
4
+ data.tar.gz: 8213f0db1ad28ec7b51e99194562198f7c9c9b1a
5
+ SHA512:
6
+ metadata.gz: 9e2e037e06073b9a16b6216d2f6b1e34a0ae25d5e5d4d9782b97d2e657b4006b97488d150ecf668316d27350bff4902feadae944ba963378a0c4efa636f5d10e
7
+ data.tar.gz: 16c67e121dcd5355802b349dd6dc4fbfbf5d96b508d0e65d5ecdffafe7f03a5b58b49f7ebce4d161f7360cb84d93f125a997b58a626749ef6eb54e07551fb947
data/.gitignore ADDED
@@ -0,0 +1 @@
1
+ *.gem
data/Gemfile ADDED
File without changes
data/LICENSE ADDED
@@ -0,0 +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
+
data/README.md ADDED
@@ -0,0 +1 @@
1
+ # Slight
data/bin/repl/repl.rb ADDED
@@ -0,0 +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
data/bin/repl/utils.rb ADDED
@@ -0,0 +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
data/bin/slight ADDED
@@ -0,0 +1,2 @@
1
+ #!/usr/bin/env ruby
2
+ require_relative '../example/default_engine.rb'
data/bin/slsh ADDED
@@ -0,0 +1,2 @@
1
+ #!/usr/bin/env ruby
2
+ require_relative 'repl/repl.rb'
@@ -0,0 +1,2 @@
1
+ button "btn btn-success btn-lg" do; "submit"; end
2
+ layout_yield("#{File.dirname(__FILE__)}/component.slight.rb")
data/example/core.rb ADDED
@@ -0,0 +1,29 @@
1
+ $:.unshift File.expand_path('../../lib', __FILE__)
2
+ require 'slight/dsl'
3
+
4
+ module Slight
5
+ class DSL
6
+ def run
7
+ doctype :html
8
+ html do
9
+ head do
10
+ title "Example"
11
+ use "/css/bootstrap.css"
12
+ use "/script/jquery.js"
13
+ use "/script/angular.js"
14
+ end
15
+ body do
16
+ div "panel" do
17
+ nav "nav nav-pill", id:"NavMenu", css:"color: red" do
18
+ img! src:"/images/icon1.png"
19
+ end
20
+ end
21
+ br
22
+ hr
23
+ end
24
+ end
25
+ end
26
+ end
27
+ end
28
+
29
+ Slight::DSL.new(STDOUT).run
@@ -0,0 +1,37 @@
1
+ require 'slight/config'
2
+ require 'slight/engine'
3
+
4
+ module Slight
5
+ class PrettyRender < Filter
6
+ def self.do(src_data); end
7
+ end
8
+
9
+ class PrettyOutput < Filter
10
+ end
11
+
12
+ conf = Slight::Configuration.new do |c|
13
+ c.use PrettyRender
14
+ c.use PrettyOutput, :after
15
+ #c.set :pretty_html, true
16
+ end
17
+
18
+ custom_engine = Slight::Engine.new(conf)
19
+ io_out = STDOUT
20
+
21
+ at_exit{
22
+ io_out.close
23
+ }
24
+
25
+ begin
26
+ raise IOError, "source file was not given." if ARGV.length == 0
27
+ src_file = ARGV[0]
28
+ io_out = File.open("#{ARGV[1]}", 'w') if ARGV.size == 2
29
+ io_out.puts default_engine.render(src_file)
30
+ rescue Exception => err
31
+ STDERR.puts err.message
32
+ STDERR.puts [err.inspect, err.backtrace.join("\n")].join("\n")
33
+ exit 1
34
+ end
35
+
36
+ exit 0
37
+ end
@@ -0,0 +1,28 @@
1
+ $:.unshift File.expand_path('../../lib', __FILE__)
2
+ require 'slight'
3
+
4
+ module Slight
5
+ default_engine = Slight::Engine.new
6
+ io_out = STDOUT
7
+
8
+ at_exit{
9
+ io_out.close
10
+ }
11
+
12
+ begin
13
+ if ARGV[0] == "-v" then
14
+ io_out.puts VERSION
15
+ else
16
+ raise IOError, "source file was not given." if ARGV.length == 0
17
+ src_file = ARGV[0]
18
+ io_out = File.open("#{ARGV[1]}", 'w') if ARGV.size == 2
19
+ io_out.puts default_engine.render(src_file)
20
+ end
21
+ rescue Exception => err
22
+ STDERR.puts err.message
23
+ #STDERR.puts [err.inspect, err.backtrace.join("\n")].join("\n")
24
+ exit 1
25
+ end
26
+
27
+ exit 0
28
+ end
@@ -0,0 +1,33 @@
1
+ doctype :html
2
+ html do
3
+ head do
4
+ title "Example"
5
+ use "resource/css/bootstrap.css"
6
+ use "resource/script/jquery.js"
7
+ use "resource/script/angular.js"
8
+ end
9
+ body do
10
+ div "panel" do
11
+ nav "nav nav-pill", id:"NavMenu", css:"color: red" do
12
+ img! src:"resource/images/icon1.png"
13
+ end
14
+ end
15
+ div css:'border 1 bold blue' do
16
+ layout_yield("#{File.dirname(__FILE__)}/component.slight.rb")
17
+ end
18
+ div css:'border 1 bold green' do
19
+ layout_yield("#{File.dirname(__FILE__)}/component.slight.rb")
20
+ end
21
+ span do
22
+ "Hello Span"
23
+ end
24
+ br
25
+ hr
26
+ end
27
+
28
+ js %{
29
+ let a =1;
30
+ console.log(a);
31
+ }
32
+
33
+ end
@@ -0,0 +1,38 @@
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 use(t, flag = :before)
18
+ if flag == :before then
19
+ @options[:before_filter].push(t)
20
+ else
21
+ @options[:after_filter].push(t)
22
+ end
23
+ end
24
+
25
+ def shortcut(type, pattern, replacement)
26
+ case(type)
27
+ when :A
28
+ @options[:shortcutA][pattern.to_sym] = replacement
29
+ when :T
30
+ @options[:shortcutT][pattern.to_sym] = replacement
31
+ end
32
+ end
33
+
34
+ def blinding(*system_fun)
35
+ @options[:blinding] = system_fun.map(&:to_sym)
36
+ end
37
+ end
38
+ end
data/lib/slight/dsl.rb ADDED
@@ -0,0 +1,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
+ private
113
+ def __dsl__define(tag)
114
+ DSL.class_eval do
115
+ define_method(tag){|*at, &block|
116
+ __dsl__packup(tag.to_s, *at, &block)
117
+ }
118
+ end
119
+ end
120
+
121
+ def __dsl__packup(tag, *at)
122
+ attr_replacements = @__dsl__attr_replacements||{}
123
+ tag_replacements = @__dsl__tag_replacements||{}
124
+ attrs=[]
125
+
126
+ if self_close = tag.end_with?("!") then
127
+ tag = tag[0..-2]
128
+ end
129
+
130
+ at.each do |var|
131
+ if var.class == Hash then
132
+ var.each_pair do |a, v|
133
+ unless a.to_sym == :_ then
134
+ at_new = attr_replacements.fetch(a, a)
135
+ at_new = v.class == String ? "#{at_new}=\"#{v}\"" : "#{at_new}=#{v.to_s}"
136
+ else
137
+ at_new = "#{v}"
138
+ end
139
+ attrs.push at_new
140
+ end
141
+ elsif var.class == String
142
+ attrs.push "class=\"#{var}\""
143
+ end
144
+ end
145
+
146
+ s_tag = tag_replacements.fetch(tag.to_sym, tag)
147
+ e_tag = s_tag.split(" ")[0]
148
+
149
+ space = attrs.length > 0 ? " " : ""
150
+ echo "<#{s_tag}#{space}#{attrs.join(" ")}"
151
+ if self_close then
152
+ echo "/>\n"
153
+ else
154
+ echo ">\n"
155
+ puts yield.to_s if block_given?
156
+ echo "</#{e_tag}>\n"
157
+ end
158
+
159
+ end
160
+ end
161
+ end
@@ -0,0 +1,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
+ src_data ||= File.new(src_file).read
28
+ @options[:before_filter].each do |f|
29
+ src_data = f.do(src_data)
30
+ end
31
+ src_data = @template.render(src_data, src_file, local_vars)
32
+ @options[:after_filter].each do |f|
33
+ src_data = f.do(src_data)
34
+ end
35
+ src_data
36
+ end
37
+ end
38
+ end
@@ -0,0 +1,28 @@
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
+ local_vars.each_pair do |key, value|
18
+ @dsl.binding_scope.local_variable_set(key.to_sym, value)
19
+ end
20
+ begin
21
+ eval(src_data, @dsl.binding_scope, src_file, __LINE__ - 20)
22
+ rescue => ex
23
+ raise DSLException.new(ex.message)
24
+ end
25
+ @output_buffer
26
+ end
27
+ end
28
+ end
@@ -0,0 +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 &gt; 0 &amp; a &lt; 10?
16
+ #
17
+ # [Slight] => Add: gsub(/[[:blank:]]/,"&nbsp;") to support space.
18
+ def html_escape(s)
19
+ s.to_s.gsub(/&/, "&amp;").gsub(/[[:blank:]]/,"&nbsp;").gsub(/\"/, "&quot;").gsub(/>/, "&gt;").gsub(/</, "&lt;")
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 ADDED
@@ -0,0 +1,6 @@
1
+ require 'slight/engine'
2
+ module Slight
3
+ # Slight version string
4
+ # @api public
5
+ VERSION = '1.0.1'
6
+ end
data/slight.gemspec ADDED
@@ -0,0 +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
metadata ADDED
@@ -0,0 +1,66 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: slight-lang
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.0.1
5
+ platform: ruby
6
+ authors:
7
+ - oliver.yu
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2016-11-13 00:00:00.000000000 Z
12
+ dependencies: []
13
+ description: A light and sweet template language
14
+ email:
15
+ - nemo1023@gmail.com
16
+ executables:
17
+ - slsh
18
+ - slight
19
+ extensions: []
20
+ extra_rdoc_files: []
21
+ files:
22
+ - ".gitignore"
23
+ - Gemfile
24
+ - LICENSE
25
+ - README.md
26
+ - bin/repl/repl.rb
27
+ - bin/repl/utils.rb
28
+ - bin/slight
29
+ - bin/slsh
30
+ - example/component.slight.rb
31
+ - example/core.rb
32
+ - example/custom_engine.rb
33
+ - example/default_engine.rb
34
+ - example/index.slight.rb
35
+ - lib/slight.rb
36
+ - lib/slight/config.rb
37
+ - lib/slight/dsl.rb
38
+ - lib/slight/engine.rb
39
+ - lib/slight/template.rb
40
+ - lib/slight/utils.rb
41
+ - slight.gemspec
42
+ homepage: https://github.com/OliversCat/Slight
43
+ licenses:
44
+ - MIT
45
+ metadata: {}
46
+ post_install_message:
47
+ rdoc_options: []
48
+ require_paths:
49
+ - lib
50
+ required_ruby_version: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ required_rubygems_version: !ruby/object:Gem::Requirement
56
+ requirements:
57
+ - - ">="
58
+ - !ruby/object:Gem::Version
59
+ version: '0'
60
+ requirements: []
61
+ rubyforge_project:
62
+ rubygems_version: 2.5.1
63
+ signing_key:
64
+ specification_version: 4
65
+ summary: The goal of this is to use ruby syntax and html style shotcut to write template.
66
+ test_files: []