trenni 1.0.0
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +17 -0
- data/.travis.yml +9 -0
- data/Gemfile +8 -0
- data/README.md +70 -0
- data/Rakefile +9 -0
- data/lib/trenni.rb +22 -0
- data/lib/trenni/builder.rb +125 -0
- data/lib/trenni/template.rb +169 -0
- data/lib/trenni/version.rb +23 -0
- data/test/test_builder.rb +60 -0
- data/test/test_template.rb +36 -0
- data/trenni.gemspec +26 -0
- metadata +69 -0
data/.gitignore
ADDED
data/.travis.yml
ADDED
data/Gemfile
ADDED
data/README.md
ADDED
@@ -0,0 +1,70 @@
|
|
1
|
+
# Trenni
|
2
|
+
|
3
|
+
[![Build Status](https://secure.travis-ci.org/ioquatix/relaxo.png)](http://travis-ci.org/ioquatix/relaxo)
|
4
|
+
|
5
|
+
Trenni is a templating system that evaluates textual strings containing Ruby
|
6
|
+
code. It compiles templates into native Ruby code including string
|
7
|
+
interpolations which means that you generally get the best possible speed.
|
8
|
+
|
9
|
+
In addition, Trenni includes an SGML/XML builder to assist with the generation
|
10
|
+
of valid nicely formatted markup.
|
11
|
+
|
12
|
+
* Released under the MIT license.
|
13
|
+
* Copyright (c) 2012 [Samuel G. D. Williams](http://www.codeotaku.com/samuel-williams/).
|
14
|
+
|
15
|
+
## Installation
|
16
|
+
|
17
|
+
Add this line to your application's Gemfile:
|
18
|
+
|
19
|
+
gem 'trenni'
|
20
|
+
|
21
|
+
And then execute:
|
22
|
+
|
23
|
+
$ bundle
|
24
|
+
|
25
|
+
Or install it yourself as:
|
26
|
+
|
27
|
+
$ gem install trenni
|
28
|
+
|
29
|
+
## Usage
|
30
|
+
|
31
|
+
Trenni templates work essentially the same way as all other templating systems:
|
32
|
+
|
33
|
+
template = Trenni::Template.new('<?r items.each do |item| ?>#{item}<?r end ?>')
|
34
|
+
|
35
|
+
items = 1..4
|
36
|
+
|
37
|
+
assert_equal "1234", template.result(binding)
|
38
|
+
|
39
|
+
The code above demonstraights the only two constructs, `<?r expression ?>` and `#{output}`.
|
40
|
+
|
41
|
+
## Contributing
|
42
|
+
|
43
|
+
1. Fork it
|
44
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
45
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
46
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
47
|
+
5. Create new Pull Request
|
48
|
+
|
49
|
+
## License
|
50
|
+
|
51
|
+
Copyright (c) 2012 Samuel G. D. Williams.
|
52
|
+
|
53
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
54
|
+
a copy of this software and associated documentation files (the
|
55
|
+
"Software"), to deal in the Software without restriction, including
|
56
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
57
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
58
|
+
permit persons to whom the Software is furnished to do so, subject to
|
59
|
+
the following conditions:
|
60
|
+
|
61
|
+
The above copyright notice and this permission notice shall be
|
62
|
+
included in all copies or substantial portions of the Software.
|
63
|
+
|
64
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
65
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
66
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
67
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
68
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
69
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
70
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/Rakefile
ADDED
data/lib/trenni.rb
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
# Copyright (c) 2012 Samuel G. D. Williams. <http://www.oriontransfer.co.nz>
|
2
|
+
#
|
3
|
+
# Permission is hereby granted, free of charge, to any person obtaining a copy
|
4
|
+
# of this software and associated documentation files (the "Software"), to deal
|
5
|
+
# in the Software without restriction, including without limitation the rights
|
6
|
+
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
7
|
+
# copies of the Software, and to permit persons to whom the Software is
|
8
|
+
# furnished to do so, subject to the following conditions:
|
9
|
+
#
|
10
|
+
# The above copyright notice and this permission notice shall be included in
|
11
|
+
# all copies or substantial portions of the Software.
|
12
|
+
#
|
13
|
+
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
14
|
+
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
15
|
+
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
16
|
+
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
17
|
+
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
18
|
+
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
19
|
+
# THE SOFTWARE.
|
20
|
+
|
21
|
+
require 'trenni/builder'
|
22
|
+
require 'trenni/template'
|
@@ -0,0 +1,125 @@
|
|
1
|
+
# Copyright (c) 2011 Samuel G. D. Williams. <http://www.oriontransfer.co.nz>
|
2
|
+
#
|
3
|
+
# Permission is hereby granted, free of charge, to any person obtaining a copy
|
4
|
+
# of this software and associated documentation files (the "Software"), to deal
|
5
|
+
# in the Software without restriction, including without limitation the rights
|
6
|
+
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
7
|
+
# copies of the Software, and to permit persons to whom the Software is
|
8
|
+
# furnished to do so, subject to the following conditions:
|
9
|
+
#
|
10
|
+
# The above copyright notice and this permission notice shall be included in
|
11
|
+
# all copies or substantial portions of the Software.
|
12
|
+
#
|
13
|
+
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
14
|
+
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
15
|
+
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
16
|
+
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
17
|
+
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
18
|
+
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
19
|
+
# THE SOFTWARE.
|
20
|
+
|
21
|
+
module Trenni
|
22
|
+
|
23
|
+
INSTRUCT_ATTRIBUTES = [
|
24
|
+
['version', '1.0'],
|
25
|
+
['encoding', 'UTF-8']
|
26
|
+
].freeze
|
27
|
+
|
28
|
+
class Builder
|
29
|
+
def initialize(options = {})
|
30
|
+
@output = options[:output] || StringIO.new
|
31
|
+
|
32
|
+
@options = options
|
33
|
+
|
34
|
+
@level = [0]
|
35
|
+
@children = [0]
|
36
|
+
end
|
37
|
+
|
38
|
+
def indent?
|
39
|
+
@options[:indent] != nil
|
40
|
+
end
|
41
|
+
|
42
|
+
def indent
|
43
|
+
if indent?
|
44
|
+
@options[:indent] * (@level.size - 1)
|
45
|
+
else
|
46
|
+
''
|
47
|
+
end
|
48
|
+
end
|
49
|
+
|
50
|
+
def instruct(attributes = nil)
|
51
|
+
attributes ||= INSTRUCT_ATTRIBUTES
|
52
|
+
|
53
|
+
@output.puts "<?xml#{attributes_xml(attributes)}?>"
|
54
|
+
end
|
55
|
+
|
56
|
+
def doctype(attributes = 'html')
|
57
|
+
if Array === attributes
|
58
|
+
text = ''
|
59
|
+
attributes.each do |value|
|
60
|
+
if value.match(/[\s"]/)
|
61
|
+
value = '"' + value.gsub('"', '"') + '"'
|
62
|
+
end
|
63
|
+
|
64
|
+
text += ' ' + value
|
65
|
+
end
|
66
|
+
else
|
67
|
+
text = ' ' + attributes
|
68
|
+
end
|
69
|
+
|
70
|
+
@output.puts "<!DOCTYPE#{text}>"
|
71
|
+
end
|
72
|
+
|
73
|
+
def tag(name, attributes = {}, &block)
|
74
|
+
if block_given?
|
75
|
+
@output.puts if indent? and @level.last > 0
|
76
|
+
@output.write indent + "<#{name}#{attributes_xml(attributes)}>"
|
77
|
+
@output.puts if indent?
|
78
|
+
|
79
|
+
@level[@level.size-1] += 1
|
80
|
+
|
81
|
+
@level << 0
|
82
|
+
yield self
|
83
|
+
@level.pop
|
84
|
+
|
85
|
+
@output.puts if indent?
|
86
|
+
@output.write indent + "</#{name}>"
|
87
|
+
else
|
88
|
+
@output.write indent + "<#{name}#{attributes_xml(attributes)}/>"
|
89
|
+
end
|
90
|
+
end
|
91
|
+
|
92
|
+
def text(data)
|
93
|
+
if indent?
|
94
|
+
data.split(/\n/).each_with_index do |line, i|
|
95
|
+
@output.puts if i > 0
|
96
|
+
@output.write indent + line
|
97
|
+
end
|
98
|
+
else
|
99
|
+
@output.write data
|
100
|
+
end
|
101
|
+
end
|
102
|
+
|
103
|
+
def options(options)
|
104
|
+
saved_options = @options
|
105
|
+
@options = options
|
106
|
+
|
107
|
+
yield
|
108
|
+
|
109
|
+
@options = saved_options
|
110
|
+
end
|
111
|
+
|
112
|
+
protected
|
113
|
+
|
114
|
+
def attributes_xml(attributes)
|
115
|
+
buffer = ''
|
116
|
+
|
117
|
+
attributes.each do |key, value|
|
118
|
+
buffer += " #{key}=\"#{value.gsub('"', '"')}\""
|
119
|
+
end
|
120
|
+
|
121
|
+
return buffer
|
122
|
+
end
|
123
|
+
end
|
124
|
+
|
125
|
+
end
|
@@ -0,0 +1,169 @@
|
|
1
|
+
# Copyright (c) 2011 Samuel G. D. Williams. <http://www.oriontransfer.co.nz>
|
2
|
+
#
|
3
|
+
# Permission is hereby granted, free of charge, to any person obtaining a copy
|
4
|
+
# of this software and associated documentation files (the "Software"), to deal
|
5
|
+
# in the Software without restriction, including without limitation the rights
|
6
|
+
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
7
|
+
# copies of the Software, and to permit persons to whom the Software is
|
8
|
+
# furnished to do so, subject to the following conditions:
|
9
|
+
#
|
10
|
+
# The above copyright notice and this permission notice shall be included in
|
11
|
+
# all copies or substantial portions of the Software.
|
12
|
+
#
|
13
|
+
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
14
|
+
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
15
|
+
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
16
|
+
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
17
|
+
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
18
|
+
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
19
|
+
# THE SOFTWARE.
|
20
|
+
|
21
|
+
require 'strscan'
|
22
|
+
|
23
|
+
module Trenni
|
24
|
+
# The output variable that will be used in templates:
|
25
|
+
OUT = '_out'
|
26
|
+
|
27
|
+
class Template
|
28
|
+
# Returns the output produced by calling the given block.
|
29
|
+
def self.capture(*args, &block)
|
30
|
+
out = eval(OUT, block.binding)
|
31
|
+
top = out.size
|
32
|
+
|
33
|
+
block.call *args
|
34
|
+
|
35
|
+
return out.pop(out.size - top).join
|
36
|
+
end
|
37
|
+
|
38
|
+
# Returns the buffer used for capturing output.
|
39
|
+
def self.buffer(binding)
|
40
|
+
eval(OUT, binding)
|
41
|
+
end
|
42
|
+
|
43
|
+
class Buffer
|
44
|
+
def initialize
|
45
|
+
@parts = []
|
46
|
+
end
|
47
|
+
|
48
|
+
attr :parts
|
49
|
+
|
50
|
+
def text(text)
|
51
|
+
text = text.gsub('\\', '\\\\\\').gsub('@', '\\@')
|
52
|
+
|
53
|
+
@parts << "#{OUT} << %q@#{text}@ ; "
|
54
|
+
end
|
55
|
+
|
56
|
+
def expression(text)
|
57
|
+
@parts << "#{text} ; "
|
58
|
+
end
|
59
|
+
|
60
|
+
def output(text)
|
61
|
+
@parts << "#{OUT} << (#{text}) ; "
|
62
|
+
end
|
63
|
+
|
64
|
+
def code
|
65
|
+
parts = ["#{OUT} = [] ; "] + @parts + ["#{OUT}.join"]
|
66
|
+
|
67
|
+
code = parts.join
|
68
|
+
end
|
69
|
+
end
|
70
|
+
|
71
|
+
class Scanner < StringScanner
|
72
|
+
TEXT = /([^<#]|<(?!\?r)|#(?!\{)){1,1024}/m
|
73
|
+
|
74
|
+
def initialize(callback, string)
|
75
|
+
@callback = callback
|
76
|
+
super(string)
|
77
|
+
end
|
78
|
+
|
79
|
+
def parse
|
80
|
+
until eos?
|
81
|
+
pos = self.pos
|
82
|
+
|
83
|
+
scan_text
|
84
|
+
scan_expression
|
85
|
+
|
86
|
+
if pos == self.pos
|
87
|
+
raise StandardError.new "Could not scan current input #{self.pos} #{eos?}!"
|
88
|
+
end
|
89
|
+
end
|
90
|
+
end
|
91
|
+
|
92
|
+
def scan_text
|
93
|
+
if scan(TEXT)
|
94
|
+
@callback.text(matched)
|
95
|
+
end
|
96
|
+
end
|
97
|
+
|
98
|
+
def scan_expression
|
99
|
+
if scan(/\#\{/)
|
100
|
+
level = 1
|
101
|
+
code = ""
|
102
|
+
|
103
|
+
until eos? || level == 0
|
104
|
+
if scan(/[^"'\{\}]+/m)
|
105
|
+
code << matched
|
106
|
+
end
|
107
|
+
|
108
|
+
if scan(/"(\\"|[^"])*"/m)
|
109
|
+
code << matched
|
110
|
+
end
|
111
|
+
|
112
|
+
if scan(/'(\\'|[^'])*'/m)
|
113
|
+
code << matched
|
114
|
+
end
|
115
|
+
|
116
|
+
if scan(/\{/)
|
117
|
+
code << matched
|
118
|
+
level += 1
|
119
|
+
end
|
120
|
+
|
121
|
+
if scan(/\}/)
|
122
|
+
code << matched if level > 1
|
123
|
+
level -= 1
|
124
|
+
end
|
125
|
+
end
|
126
|
+
|
127
|
+
if level == 0
|
128
|
+
@callback.output(code)
|
129
|
+
else
|
130
|
+
raise StandardError.new "Could not find end of expression #{self}!"
|
131
|
+
end
|
132
|
+
elsif scan(/<\?r/)
|
133
|
+
if scan_until(/(.*?)\?>/m)
|
134
|
+
@callback.expression(self[1])
|
135
|
+
else
|
136
|
+
raise StandardError.new "Could not find end of expression #{self}!"
|
137
|
+
end
|
138
|
+
end
|
139
|
+
end
|
140
|
+
end
|
141
|
+
|
142
|
+
def self.load(path)
|
143
|
+
return self.new(File.read(path), path)
|
144
|
+
end
|
145
|
+
|
146
|
+
def initialize(template, filename = '<Trenni>')
|
147
|
+
@template = template
|
148
|
+
@filename = filename
|
149
|
+
compile!
|
150
|
+
end
|
151
|
+
|
152
|
+
def evaluate(binding)
|
153
|
+
eval(@code, binding, @filename)
|
154
|
+
end
|
155
|
+
|
156
|
+
alias result evaluate
|
157
|
+
|
158
|
+
protected
|
159
|
+
|
160
|
+
def compile!(filename = @filename)
|
161
|
+
buffer = Buffer.new
|
162
|
+
scanner = Scanner.new(buffer, @template)
|
163
|
+
|
164
|
+
scanner.parse
|
165
|
+
|
166
|
+
@code = buffer.code
|
167
|
+
end
|
168
|
+
end
|
169
|
+
end
|
@@ -0,0 +1,23 @@
|
|
1
|
+
# Copyright 2012 Samuel G. D. Williams. <http://www.oriontransfer.co.nz>
|
2
|
+
#
|
3
|
+
# Permission is hereby granted, free of charge, to any person obtaining a copy
|
4
|
+
# of this software and associated documentation files (the "Software"), to deal
|
5
|
+
# in the Software without restriction, including without limitation the rights
|
6
|
+
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
7
|
+
# copies of the Software, and to permit persons to whom the Software is
|
8
|
+
# furnished to do so, subject to the following conditions:
|
9
|
+
#
|
10
|
+
# The above copyright notice and this permission notice shall be included in
|
11
|
+
# all copies or substantial portions of the Software.
|
12
|
+
#
|
13
|
+
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
14
|
+
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
15
|
+
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
16
|
+
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
17
|
+
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
18
|
+
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
19
|
+
# THE SOFTWARE.
|
20
|
+
|
21
|
+
module Trenni
|
22
|
+
VERSION = "1.0.0"
|
23
|
+
end
|
@@ -0,0 +1,60 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
# Copyright (c) 2007, 2012 Samuel G. D. Williams. <http://www.oriontransfer.co.nz>
|
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
|
+
|
23
|
+
require 'pathname'
|
24
|
+
require 'test/unit'
|
25
|
+
require 'stringio'
|
26
|
+
|
27
|
+
require 'trenni'
|
28
|
+
|
29
|
+
class BuilderTest < Test::Unit::TestCase
|
30
|
+
def test_tags
|
31
|
+
output = StringIO.new
|
32
|
+
|
33
|
+
builder = Trenni::Builder.new(:output => output)
|
34
|
+
|
35
|
+
builder.instruct
|
36
|
+
builder.tag('foo', 'bar' => 'baz') do
|
37
|
+
builder.text("apples and oranges")
|
38
|
+
end
|
39
|
+
|
40
|
+
assert_equal output.string, "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<foo bar=\"baz\">apples and oranges</foo>"
|
41
|
+
end
|
42
|
+
|
43
|
+
def test_html
|
44
|
+
output = $stdout
|
45
|
+
|
46
|
+
builder = Trenni::Builder.new(:output => output, :indent => "\t")
|
47
|
+
builder.options(:indent => "\t") do
|
48
|
+
builder.doctype
|
49
|
+
builder.tag('html') do
|
50
|
+
builder.tag('head') do
|
51
|
+
builder.tag('title') do
|
52
|
+
builder.text('Hello World')
|
53
|
+
end
|
54
|
+
end
|
55
|
+
builder.tag('body') do
|
56
|
+
end
|
57
|
+
end
|
58
|
+
end
|
59
|
+
end
|
60
|
+
end
|
@@ -0,0 +1,36 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
# Copyright (c) 2007, 2012 Samuel G. D. Williams. <http://www.oriontransfer.co.nz>
|
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
|
+
|
23
|
+
require 'pathname'
|
24
|
+
require 'test/unit'
|
25
|
+
require 'stringio'
|
26
|
+
|
27
|
+
require 'trenni'
|
28
|
+
|
29
|
+
class TemplateTest < Test::Unit::TestCase
|
30
|
+
def test_template_each
|
31
|
+
template = Trenni::Template.new('<?r items.each do |item| ?>#{item}<?r end ?>')
|
32
|
+
|
33
|
+
items = 1..4
|
34
|
+
assert_equal "1234", template.result(binding)
|
35
|
+
end
|
36
|
+
end
|
data/trenni.gemspec
ADDED
@@ -0,0 +1,26 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'trenni/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |gem|
|
7
|
+
gem.name = "trenni"
|
8
|
+
gem.version = Trenni::VERSION
|
9
|
+
gem.authors = ["Samuel Williams"]
|
10
|
+
gem.email = ["samuel.williams@oriontransfer.co.nz"]
|
11
|
+
gem.description = <<-EOF
|
12
|
+
Trenni is a templating system that evaluates textual strings containing Ruby
|
13
|
+
code. It compiles templates into native Ruby code including string
|
14
|
+
interpolations which means that you generally get the best possible speed.
|
15
|
+
|
16
|
+
In addition, Trenni includes an SGML/XML builder to assist with the generation
|
17
|
+
of valid nicely formatted markup.
|
18
|
+
EOF
|
19
|
+
gem.summary = %q{A fast native templating system that compiles directly to Ruby code.}
|
20
|
+
gem.homepage = "https://github.com/ioquatix/trenni"
|
21
|
+
|
22
|
+
gem.files = `git ls-files`.split($/)
|
23
|
+
gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
|
24
|
+
gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
|
25
|
+
gem.require_paths = ["lib"]
|
26
|
+
end
|
metadata
ADDED
@@ -0,0 +1,69 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: trenni
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 1.0.0
|
5
|
+
prerelease:
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- Samuel Williams
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2012-10-25 00:00:00.000000000 Z
|
13
|
+
dependencies: []
|
14
|
+
description: ! "\tTrenni is a templating system that evaluates textual strings containing
|
15
|
+
Ruby\n\tcode. It compiles templates into native Ruby code including string \n\tinterpolations
|
16
|
+
which means that you generally get the best possible speed.\n\t\n\tIn addition,
|
17
|
+
Trenni includes an SGML/XML builder to assist with the generation\n\tof valid nicely
|
18
|
+
formatted markup.\n"
|
19
|
+
email:
|
20
|
+
- samuel.williams@oriontransfer.co.nz
|
21
|
+
executables: []
|
22
|
+
extensions: []
|
23
|
+
extra_rdoc_files: []
|
24
|
+
files:
|
25
|
+
- .gitignore
|
26
|
+
- .travis.yml
|
27
|
+
- Gemfile
|
28
|
+
- README.md
|
29
|
+
- Rakefile
|
30
|
+
- lib/trenni.rb
|
31
|
+
- lib/trenni/builder.rb
|
32
|
+
- lib/trenni/template.rb
|
33
|
+
- lib/trenni/version.rb
|
34
|
+
- test/test_builder.rb
|
35
|
+
- test/test_template.rb
|
36
|
+
- trenni.gemspec
|
37
|
+
homepage: https://github.com/ioquatix/trenni
|
38
|
+
licenses: []
|
39
|
+
post_install_message:
|
40
|
+
rdoc_options: []
|
41
|
+
require_paths:
|
42
|
+
- lib
|
43
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
44
|
+
none: false
|
45
|
+
requirements:
|
46
|
+
- - ! '>='
|
47
|
+
- !ruby/object:Gem::Version
|
48
|
+
version: '0'
|
49
|
+
segments:
|
50
|
+
- 0
|
51
|
+
hash: 4320630080508960898
|
52
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
53
|
+
none: false
|
54
|
+
requirements:
|
55
|
+
- - ! '>='
|
56
|
+
- !ruby/object:Gem::Version
|
57
|
+
version: '0'
|
58
|
+
segments:
|
59
|
+
- 0
|
60
|
+
hash: 4320630080508960898
|
61
|
+
requirements: []
|
62
|
+
rubyforge_project:
|
63
|
+
rubygems_version: 1.8.24
|
64
|
+
signing_key:
|
65
|
+
specification_version: 3
|
66
|
+
summary: A fast native templating system that compiles directly to Ruby code.
|
67
|
+
test_files:
|
68
|
+
- test/test_builder.rb
|
69
|
+
- test/test_template.rb
|