trenni 1.2.0 → 1.3.0
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 +7 -0
- data/.travis.yml +3 -7
- data/Gemfile +0 -4
- data/README.md +19 -20
- data/Rakefile +3 -6
- data/lib/trenni/builder.rb +0 -5
- data/lib/trenni/extensions/symbol-1.8.7.rb +19 -0
- data/lib/trenni/parser.rb +0 -1
- data/lib/trenni/version.rb +1 -1
- data/spec/trenni/builder_spec.rb +105 -0
- data/spec/trenni/parser_spec.rb +102 -0
- data/spec/trenni/strings_spec.rb +64 -0
- data/{test/test_template.rb → spec/trenni/template_spec.rb} +7 -9
- data/trenni.gemspec +16 -12
- metadata +61 -27
- data/test/test_builder.rb +0 -109
- data/test/test_parser.rb +0 -110
- data/test/test_strings.rb +0 -70
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 5917823eba63297304f0339d680b595ed3dcb7f4
|
4
|
+
data.tar.gz: 8a55538fa29a65c720d3d119001e28a77998a912
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 120b4e8119e886c2d0670e5a628eef6e2240f429cf9ab538454cb09a66764d4d9ec8c1600ca5836d99adaafec830e4fcfb9b50fce5610ae3f5801386e28bc66f
|
7
|
+
data.tar.gz: 517bb05f624b2d053e518881dafc9aa2154d4ddd5f577800fd0569788e54b3d409367d4e74ebe38a467b13bed969ffa47ee0a1b85f1f3497faddb789674b6042
|
data/.travis.yml
CHANGED
data/Gemfile
CHANGED
data/README.md
CHANGED
@@ -47,23 +47,22 @@ The code above demonstraights the only two constructs, `<?r expression ?>` and `
|
|
47
47
|
|
48
48
|
Released under the MIT license.
|
49
49
|
|
50
|
-
Copyright
|
51
|
-
|
52
|
-
Permission is hereby granted, free of charge, to any person obtaining
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
50
|
+
Copyright, 2012, by [Samuel G. D. Williams](http://www.codeotaku.com/samuel-williams).
|
51
|
+
|
52
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
53
|
+
of this software and associated documentation files (the "Software"), to deal
|
54
|
+
in the Software without restriction, including without limitation the rights
|
55
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
56
|
+
copies of the Software, and to permit persons to whom the Software is
|
57
|
+
furnished to do so, subject to the following conditions:
|
58
|
+
|
59
|
+
The above copyright notice and this permission notice shall be included in
|
60
|
+
all copies or substantial portions of the Software.
|
61
|
+
|
62
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
63
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
64
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
65
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
66
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
67
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
68
|
+
THE SOFTWARE.
|
data/Rakefile
CHANGED
data/lib/trenni/builder.rb
CHANGED
@@ -132,11 +132,6 @@ module Trenni
|
|
132
132
|
def tag_attributes(attributes)
|
133
133
|
buffer = []
|
134
134
|
|
135
|
-
# Ensure consistent order
|
136
|
-
unless Array === attributes
|
137
|
-
attributes = attributes.sort
|
138
|
-
end
|
139
|
-
|
140
135
|
attributes.each do |key, value|
|
141
136
|
if value == true
|
142
137
|
buffer << Strings::to_simple_attribute(key, @strict)
|
@@ -1,3 +1,22 @@
|
|
1
|
+
# Copyright, 2012, by Samuel G. D. Williams. <http://www.codeotaku.com>
|
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.
|
1
20
|
|
2
21
|
class Symbol
|
3
22
|
def <=>(with)
|
data/lib/trenni/parser.rb
CHANGED
data/lib/trenni/version.rb
CHANGED
@@ -0,0 +1,105 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
# Copyright, 2012, by Samuel G. D. Williams. <http://www.codeotaku.com>
|
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 'trenni'
|
24
|
+
|
25
|
+
module Trenni::BuilderSpec
|
26
|
+
describe Trenni::Builder do
|
27
|
+
it "should produce valid xml output" do
|
28
|
+
builder = Trenni::Builder.new(:indent => false)
|
29
|
+
|
30
|
+
builder.instruct
|
31
|
+
builder.tag('foo', 'bar' => 'baz') do
|
32
|
+
builder.text("apples and oranges")
|
33
|
+
end
|
34
|
+
|
35
|
+
expect(builder.output.string).to be == "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<foo bar=\"baz\">apples and oranges</foo>"
|
36
|
+
end
|
37
|
+
|
38
|
+
it "should produce valid html" do
|
39
|
+
builder = Trenni::Builder.new(:indent => true)
|
40
|
+
|
41
|
+
builder.doctype
|
42
|
+
builder.tag('html') do
|
43
|
+
builder.tag('head') do
|
44
|
+
builder.inline('title') do
|
45
|
+
builder.text('Hello World')
|
46
|
+
end
|
47
|
+
end
|
48
|
+
builder.tag('body') do
|
49
|
+
end
|
50
|
+
end
|
51
|
+
|
52
|
+
expect(builder.output.string).to be == "<!DOCTYPE html>\n<html>\n\t<head>\n\t\t<title>Hello World</title>\n\t</head>\n\t<body>\n\t</body>\n</html>"
|
53
|
+
end
|
54
|
+
|
55
|
+
it "should produce inline html" do
|
56
|
+
builder = Trenni::Builder.new(:indent => true)
|
57
|
+
|
58
|
+
builder.inline("div") do
|
59
|
+
builder.tag("strong") do
|
60
|
+
builder.text("Hello")
|
61
|
+
end
|
62
|
+
|
63
|
+
builder.text "World!"
|
64
|
+
end
|
65
|
+
|
66
|
+
expect(builder.output.string).to be == "<div><strong>Hello</strong>World!</div>"
|
67
|
+
end
|
68
|
+
|
69
|
+
it "escapes attributes and text correctly" do
|
70
|
+
builder = Trenni::Builder.new(:escape => true)
|
71
|
+
|
72
|
+
builder.inline :foo, :bar => %Q{"Hello World"} do
|
73
|
+
builder.text %Q{if x < 10}
|
74
|
+
end
|
75
|
+
|
76
|
+
expect(builder.output.string).to be == %Q{<foo bar=""Hello World"">if x < 10</foo>}
|
77
|
+
end
|
78
|
+
|
79
|
+
it "should support strict attributes" do
|
80
|
+
builder = Trenni::Builder.new(:strict => true)
|
81
|
+
|
82
|
+
builder.tag :option, :required => true
|
83
|
+
|
84
|
+
expect(builder.output.string).to be == %Q{<option required="required"/>}
|
85
|
+
end
|
86
|
+
|
87
|
+
it "should support compact attributes" do
|
88
|
+
builder = Trenni::Builder.new(:strict => false)
|
89
|
+
|
90
|
+
builder.tag :option, :required => true
|
91
|
+
|
92
|
+
expect(builder.output.string).to be == %Q{<option required/>}
|
93
|
+
end
|
94
|
+
|
95
|
+
it "should order attributes as specified" do
|
96
|
+
builder = Trenni::Builder.new(:strict => true)
|
97
|
+
builder.tag :t, [[:a, 10], [:b, 20]]
|
98
|
+
expect(builder.output.string).to be == %Q{<t a="10" b="20"/>}
|
99
|
+
|
100
|
+
builder = Trenni::Builder.new(:strict => true)
|
101
|
+
builder.tag :t, :b => 20, :a => 10
|
102
|
+
expect(builder.output.string).to be == %Q{<t b="20" a="10"/>}
|
103
|
+
end
|
104
|
+
end
|
105
|
+
end
|
@@ -0,0 +1,102 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
# Copyright, 2012, by Samuel G. D. Williams. <http://www.codeotaku.com>
|
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 'trenni/parser'
|
24
|
+
|
25
|
+
module Trenni::ParserSpec
|
26
|
+
class ParserDelegate
|
27
|
+
def initialize
|
28
|
+
@events = []
|
29
|
+
end
|
30
|
+
|
31
|
+
attr :events
|
32
|
+
|
33
|
+
def method_missing(*args)
|
34
|
+
@events << args
|
35
|
+
end
|
36
|
+
|
37
|
+
def begin_parse(scanner)
|
38
|
+
# ignore this event
|
39
|
+
end
|
40
|
+
end
|
41
|
+
|
42
|
+
describe Trenni::Parser do
|
43
|
+
it "should parse markup correctly" do
|
44
|
+
delegate = ParserDelegate.new
|
45
|
+
scanner = Trenni::Parser.new(delegate)
|
46
|
+
|
47
|
+
scanner.parse(%Q{<foo bar="20" baz>Hello World</foo>})
|
48
|
+
|
49
|
+
expected_events = [
|
50
|
+
[:begin_tag, "foo", :opened],
|
51
|
+
[:attribute, "bar", "20"],
|
52
|
+
[:attribute, "baz", true],
|
53
|
+
[:finish_tag, :opened, :opened],
|
54
|
+
[:text, "Hello World"],
|
55
|
+
[:begin_tag, "foo", :closed],
|
56
|
+
[:finish_tag, :closed, :opened],
|
57
|
+
]
|
58
|
+
|
59
|
+
expect(delegate.events).to be == expected_events
|
60
|
+
end
|
61
|
+
|
62
|
+
it "should parse CDATA correctly" do
|
63
|
+
delegate = ParserDelegate.new
|
64
|
+
scanner = Trenni::Parser.new(delegate)
|
65
|
+
|
66
|
+
scanner.parse(%Q{<test><![CDATA[Hello World]]></test>})
|
67
|
+
|
68
|
+
expected_events = [
|
69
|
+
[:begin_tag, "test", :opened],
|
70
|
+
[:finish_tag, :opened, :opened],
|
71
|
+
[:cdata, "Hello World"],
|
72
|
+
[:begin_tag, "test", :closed],
|
73
|
+
[:finish_tag, :closed, :opened],
|
74
|
+
]
|
75
|
+
|
76
|
+
expect(delegate.events).to be == expected_events
|
77
|
+
end
|
78
|
+
|
79
|
+
it "should generate errors on incorrect input" do
|
80
|
+
delegate = ParserDelegate.new
|
81
|
+
scanner = Trenni::Parser.new(delegate)
|
82
|
+
|
83
|
+
expect{scanner.parse(%Q{<foo})}.to raise_error Trenni::Parser::ParseError
|
84
|
+
|
85
|
+
expect{scanner.parse(%Q{<foo bar=>})}.to raise_error Trenni::Parser::ParseError
|
86
|
+
|
87
|
+
expect{scanner.parse(%Q{<foo bar="" baz>})}.to_not raise_error
|
88
|
+
end
|
89
|
+
|
90
|
+
it "should know about line numbers" do
|
91
|
+
data = %Q{Hello\nWorld\nFoo\nBar!}
|
92
|
+
|
93
|
+
line = Trenni::Parser.line_at_offset(data, 7)
|
94
|
+
|
95
|
+
expect(line[:text]).to be == "World"
|
96
|
+
|
97
|
+
expect(line[:line_number]).to be == 2
|
98
|
+
expect(line[:line_offset]).to be == 6
|
99
|
+
expect(line[:character_offset]).to be == 1
|
100
|
+
end
|
101
|
+
end
|
102
|
+
end
|
@@ -0,0 +1,64 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
# Copyright, 2012, by Samuel G. D. Williams. <http://www.codeotaku.com>
|
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 'trenni/strings'
|
24
|
+
|
25
|
+
module Trenni::StringsSpec
|
26
|
+
describe Trenni::Strings do
|
27
|
+
it "should escape html sensitive characters" do
|
28
|
+
text = Trenni::Strings.to_html("<foobar>")
|
29
|
+
expect(text).to be == "<foobar>"
|
30
|
+
|
31
|
+
text = Trenni::Strings.to_html(%q{"I'd like to do this & that :p", she said.})
|
32
|
+
expect(text).to be == %q{"I'd like to do this & that :p", she said.}
|
33
|
+
end
|
34
|
+
|
35
|
+
it "should generate quoted strings" do
|
36
|
+
text = Trenni::Strings.to_quoted_string(%Q{"Hello World"})
|
37
|
+
expect(text).to be == %q{"\"Hello World\""}
|
38
|
+
|
39
|
+
text = Trenni::Strings.to_quoted_string(%Q{"Hello\r\nWorld"})
|
40
|
+
expect(text).to be == %q{"\"Hello\r\nWorld\""}
|
41
|
+
end
|
42
|
+
|
43
|
+
it "should generate quoted attributes" do
|
44
|
+
text = Trenni::Strings.to_attribute(:foo, 'bar')
|
45
|
+
expect(text).to be == %Q{foo="bar"}
|
46
|
+
|
47
|
+
text = Trenni::Strings.to_simple_attribute(:foo, false)
|
48
|
+
expect(text).to be == %Q{foo}
|
49
|
+
|
50
|
+
text = Trenni::Strings.to_simple_attribute(:foo, true)
|
51
|
+
expect(text).to be == %Q{foo="foo"}
|
52
|
+
end
|
53
|
+
|
54
|
+
it "should generate nice titles" do
|
55
|
+
text = Trenni::Strings.to_title("foo bar")
|
56
|
+
expect(text).to be == "Foo Bar"
|
57
|
+
end
|
58
|
+
|
59
|
+
it "should generate nice identifiers" do
|
60
|
+
text = Trenni::Strings.to_snake("Happy::Go::Lucky")
|
61
|
+
expect(text).to be == "happy_go_lucky"
|
62
|
+
end
|
63
|
+
end
|
64
|
+
end
|
@@ -20,17 +20,15 @@
|
|
20
20
|
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
21
21
|
# THE SOFTWARE.
|
22
22
|
|
23
|
-
require 'pathname'
|
24
|
-
require 'test/unit'
|
25
|
-
require 'stringio'
|
26
|
-
|
27
23
|
require 'trenni'
|
28
24
|
|
29
|
-
|
30
|
-
|
31
|
-
|
25
|
+
module Trenni::TemplateSpec
|
26
|
+
describe Trenni::Template do
|
27
|
+
it "should process list of items" do
|
28
|
+
template = Trenni::Template.new('<?r items.each do |item| ?>#{item}<?r end ?>')
|
32
29
|
|
33
|
-
|
34
|
-
|
30
|
+
items = 1..4
|
31
|
+
expect(template.result(binding)).to be == "1234"
|
32
|
+
end
|
35
33
|
end
|
36
34
|
end
|
data/trenni.gemspec
CHANGED
@@ -3,12 +3,12 @@ lib = File.expand_path('../lib', __FILE__)
|
|
3
3
|
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
4
|
require 'trenni/version'
|
5
5
|
|
6
|
-
Gem::Specification.new do |
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "trenni"
|
8
|
+
spec.version = Trenni::VERSION
|
9
|
+
spec.authors = ["Samuel Williams"]
|
10
|
+
spec.email = ["samuel.williams@oriontransfer.co.nz"]
|
11
|
+
spec.description = <<-EOF
|
12
12
|
Trenni is a templating system that evaluates textual strings containing Ruby
|
13
13
|
code. It compiles templates directly into native code which means that you
|
14
14
|
generally get the best possible performance.
|
@@ -16,11 +16,15 @@ Gem::Specification.new do |gem|
|
|
16
16
|
In addition, Trenni includes an SGML/XML builder to assist with the generation
|
17
17
|
of pleasantly formatted markup.
|
18
18
|
EOF
|
19
|
-
|
20
|
-
|
19
|
+
spec.summary = %q{A fast native templating system that compiles directly to Ruby code.}
|
20
|
+
spec.homepage = "https://github.com/ioquatix/trenni"
|
21
21
|
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
22
|
+
spec.files = `git ls-files`.split($/)
|
23
|
+
spec.executables = spec.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
|
24
|
+
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
25
|
+
spec.require_paths = ["lib"]
|
26
|
+
|
27
|
+
spec.add_development_dependency "bundler", "~> 1.3"
|
28
|
+
spec.add_development_dependency "rspec", "~> 3.0.0.rc1"
|
29
|
+
spec.add_development_dependency "rake"
|
26
30
|
end
|
metadata
CHANGED
@@ -1,17 +1,58 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: trenni
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
5
|
-
prerelease:
|
4
|
+
version: 1.3.0
|
6
5
|
platform: ruby
|
7
6
|
authors:
|
8
7
|
- Samuel Williams
|
9
8
|
autorequire:
|
10
9
|
bindir: bin
|
11
10
|
cert_chain: []
|
12
|
-
date:
|
13
|
-
dependencies:
|
14
|
-
|
11
|
+
date: 2014-05-27 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: bundler
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '1.3'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '1.3'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rspec
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: 3.0.0.rc1
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: 3.0.0.rc1
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: rake
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - ">="
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '0'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - ">="
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '0'
|
55
|
+
description: "\tTrenni is a templating system that evaluates textual strings containing
|
15
56
|
Ruby\n\tcode. It compiles templates directly into native code which means that you\n\tgenerally
|
16
57
|
get the best possible performance.\n\n\tIn addition, Trenni includes an SGML/XML
|
17
58
|
builder to assist with the generation\n\tof pleasantly formatted markup.\n"
|
@@ -21,8 +62,8 @@ executables: []
|
|
21
62
|
extensions: []
|
22
63
|
extra_rdoc_files: []
|
23
64
|
files:
|
24
|
-
- .gitignore
|
25
|
-
- .travis.yml
|
65
|
+
- ".gitignore"
|
66
|
+
- ".travis.yml"
|
26
67
|
- Gemfile
|
27
68
|
- README.md
|
28
69
|
- Rakefile
|
@@ -33,43 +74,36 @@ files:
|
|
33
74
|
- lib/trenni/strings.rb
|
34
75
|
- lib/trenni/template.rb
|
35
76
|
- lib/trenni/version.rb
|
36
|
-
-
|
37
|
-
-
|
38
|
-
-
|
39
|
-
-
|
77
|
+
- spec/trenni/builder_spec.rb
|
78
|
+
- spec/trenni/parser_spec.rb
|
79
|
+
- spec/trenni/strings_spec.rb
|
80
|
+
- spec/trenni/template_spec.rb
|
40
81
|
- trenni.gemspec
|
41
82
|
homepage: https://github.com/ioquatix/trenni
|
42
83
|
licenses: []
|
84
|
+
metadata: {}
|
43
85
|
post_install_message:
|
44
86
|
rdoc_options: []
|
45
87
|
require_paths:
|
46
88
|
- lib
|
47
89
|
required_ruby_version: !ruby/object:Gem::Requirement
|
48
|
-
none: false
|
49
90
|
requirements:
|
50
|
-
- -
|
91
|
+
- - ">="
|
51
92
|
- !ruby/object:Gem::Version
|
52
93
|
version: '0'
|
53
|
-
segments:
|
54
|
-
- 0
|
55
|
-
hash: -514891289960522672
|
56
94
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
57
|
-
none: false
|
58
95
|
requirements:
|
59
|
-
- -
|
96
|
+
- - ">="
|
60
97
|
- !ruby/object:Gem::Version
|
61
98
|
version: '0'
|
62
|
-
segments:
|
63
|
-
- 0
|
64
|
-
hash: -514891289960522672
|
65
99
|
requirements: []
|
66
100
|
rubyforge_project:
|
67
|
-
rubygems_version:
|
101
|
+
rubygems_version: 2.2.2
|
68
102
|
signing_key:
|
69
|
-
specification_version:
|
103
|
+
specification_version: 4
|
70
104
|
summary: A fast native templating system that compiles directly to Ruby code.
|
71
105
|
test_files:
|
72
|
-
-
|
73
|
-
-
|
74
|
-
-
|
75
|
-
-
|
106
|
+
- spec/trenni/builder_spec.rb
|
107
|
+
- spec/trenni/parser_spec.rb
|
108
|
+
- spec/trenni/strings_spec.rb
|
109
|
+
- spec/trenni/template_spec.rb
|
data/test/test_builder.rb
DELETED
@@ -1,109 +0,0 @@
|
|
1
|
-
#!/usr/bin/env ruby
|
2
|
-
|
3
|
-
# Copyright, 2012, by Samuel G. D. Williams. <http://www.codeotaku.com>
|
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
|
-
require 'digest/md5'
|
27
|
-
|
28
|
-
require 'trenni'
|
29
|
-
|
30
|
-
class TestBuilder < Test::Unit::TestCase
|
31
|
-
def test_tags
|
32
|
-
builder = Trenni::Builder.new(:indent => false)
|
33
|
-
|
34
|
-
builder.instruct
|
35
|
-
builder.tag('foo', 'bar' => 'baz') do
|
36
|
-
builder.text("apples and oranges")
|
37
|
-
end
|
38
|
-
|
39
|
-
assert_equal "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<foo bar=\"baz\">apples and oranges</foo>", builder.output.string
|
40
|
-
end
|
41
|
-
|
42
|
-
def test_full_html
|
43
|
-
builder = Trenni::Builder.new(:indent => true)
|
44
|
-
|
45
|
-
builder.doctype
|
46
|
-
builder.tag('html') do
|
47
|
-
builder.tag('head') do
|
48
|
-
builder.inline('title') do
|
49
|
-
builder.text('Hello World')
|
50
|
-
end
|
51
|
-
end
|
52
|
-
builder.tag('body') do
|
53
|
-
end
|
54
|
-
end
|
55
|
-
|
56
|
-
assert_equal "<!DOCTYPE html>\n<html>\n\t<head>\n\t\t<title>Hello World</title>\n\t</head>\n\t<body>\n\t</body>\n</html>", builder.output.string
|
57
|
-
end
|
58
|
-
|
59
|
-
def test_inline_html
|
60
|
-
builder = Trenni::Builder.new(:indent => true)
|
61
|
-
|
62
|
-
builder.inline("div") do
|
63
|
-
builder.tag("strong") do
|
64
|
-
builder.text("Hello")
|
65
|
-
end
|
66
|
-
|
67
|
-
builder.text "World!"
|
68
|
-
end
|
69
|
-
|
70
|
-
assert_equal "<div><strong>Hello</strong>World!</div>", builder.output.string
|
71
|
-
end
|
72
|
-
|
73
|
-
def test_indentation
|
74
|
-
builder = Trenni::Builder.new(:indent => "\t")
|
75
|
-
|
76
|
-
puts builder.output.string
|
77
|
-
end
|
78
|
-
|
79
|
-
def test_escaping
|
80
|
-
builder = Trenni::Builder.new(:escape => true)
|
81
|
-
builder.inline :foo, :bar => %Q{"Hello World"} do
|
82
|
-
builder.text %Q{if x < 10}
|
83
|
-
end
|
84
|
-
|
85
|
-
assert_equal %Q{<foo bar=""Hello World"">if x < 10</foo>}, builder.output.string
|
86
|
-
end
|
87
|
-
|
88
|
-
def test_attributes_strict
|
89
|
-
builder = Trenni::Builder.new(:strict => true)
|
90
|
-
builder.tag :option, :required => true
|
91
|
-
assert_equal %Q{<option required="required"/>}, builder.output.string
|
92
|
-
end
|
93
|
-
|
94
|
-
def test_attributes_compact
|
95
|
-
builder = Trenni::Builder.new(:strict => false)
|
96
|
-
builder.tag :option, :required => true
|
97
|
-
assert_equal %Q{<option required/>}, builder.output.string
|
98
|
-
end
|
99
|
-
|
100
|
-
def test_attributes_order
|
101
|
-
builder = Trenni::Builder.new(:strict => true)
|
102
|
-
builder.tag :t, [[:a, 10], [:b, 20]]
|
103
|
-
assert_equal %Q{<t a="10" b="20"/>}, builder.output.string
|
104
|
-
|
105
|
-
builder = Trenni::Builder.new(:strict => true)
|
106
|
-
builder.tag :t, :b => 20, :a => 10
|
107
|
-
assert_equal %Q{<t a="10" b="20"/>}, builder.output.string
|
108
|
-
end
|
109
|
-
end
|
data/test/test_parser.rb
DELETED
@@ -1,110 +0,0 @@
|
|
1
|
-
#!/usr/bin/env ruby
|
2
|
-
|
3
|
-
# Copyright, 2012, by Samuel G. D. Williams. <http://www.codeotaku.com>
|
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
|
-
require 'digest/md5'
|
27
|
-
|
28
|
-
require 'trenni/parser'
|
29
|
-
|
30
|
-
class TestParser < Test::Unit::TestCase
|
31
|
-
class ParserDelegate
|
32
|
-
def initialize
|
33
|
-
@events = []
|
34
|
-
end
|
35
|
-
|
36
|
-
attr :events
|
37
|
-
|
38
|
-
def method_missing(*args)
|
39
|
-
@events << args
|
40
|
-
end
|
41
|
-
|
42
|
-
def begin_parse(scanner)
|
43
|
-
# ignore this event
|
44
|
-
end
|
45
|
-
end
|
46
|
-
|
47
|
-
def test_markup
|
48
|
-
delegate = ParserDelegate.new
|
49
|
-
scanner = Trenni::Parser.new(delegate)
|
50
|
-
|
51
|
-
scanner.parse(%Q{<foo bar="20" baz>Hello World</foo>})
|
52
|
-
|
53
|
-
expected_events = [
|
54
|
-
[:begin_tag, "foo", :opened],
|
55
|
-
[:attribute, "bar", "20"],
|
56
|
-
[:attribute, "baz", true],
|
57
|
-
[:finish_tag, :opened, :opened],
|
58
|
-
[:text, "Hello World"],
|
59
|
-
[:begin_tag, "foo", :closed],
|
60
|
-
[:finish_tag, :closed, :opened],
|
61
|
-
]
|
62
|
-
|
63
|
-
assert_equal expected_events, delegate.events
|
64
|
-
end
|
65
|
-
|
66
|
-
def test_cdata
|
67
|
-
delegate = ParserDelegate.new
|
68
|
-
scanner = Trenni::Parser.new(delegate)
|
69
|
-
|
70
|
-
scanner.parse(%Q{<test><![CDATA[Hello World]]></test>})
|
71
|
-
|
72
|
-
expected_events = [
|
73
|
-
[:begin_tag, "test", :opened],
|
74
|
-
[:finish_tag, :opened, :opened],
|
75
|
-
[:cdata, "Hello World"],
|
76
|
-
[:begin_tag, "test", :closed],
|
77
|
-
[:finish_tag, :closed, :opened],
|
78
|
-
]
|
79
|
-
|
80
|
-
assert_equal expected_events, delegate.events
|
81
|
-
end
|
82
|
-
|
83
|
-
def test_errors
|
84
|
-
delegate = ParserDelegate.new
|
85
|
-
scanner = Trenni::Parser.new(delegate)
|
86
|
-
|
87
|
-
assert_raise Trenni::Parser::ParseError do
|
88
|
-
scanner.parse(%Q{<foo})
|
89
|
-
end
|
90
|
-
|
91
|
-
assert_raise Trenni::Parser::ParseError do
|
92
|
-
scanner.parse(%Q{<foo bar=>})
|
93
|
-
end
|
94
|
-
|
95
|
-
assert_nothing_raised Trenni::Parser::ParseError do
|
96
|
-
scanner.parse(%Q{<foo bar="" baz>})
|
97
|
-
end
|
98
|
-
end
|
99
|
-
|
100
|
-
def test_line_at_offset
|
101
|
-
data = %Q{Hello\nWorld\nFoo\nBar!}
|
102
|
-
|
103
|
-
line = Trenni::Parser.line_at_offset(data, 7)
|
104
|
-
|
105
|
-
assert_equal "World", line[:text]
|
106
|
-
assert_equal 2, line[:line_number]
|
107
|
-
assert_equal 6, line[:line_offset]
|
108
|
-
assert_equal 1, line[:character_offset]
|
109
|
-
end
|
110
|
-
end
|
data/test/test_strings.rb
DELETED
@@ -1,70 +0,0 @@
|
|
1
|
-
#!/usr/bin/env ruby
|
2
|
-
|
3
|
-
# Copyright, 2012, by Samuel G. D. Williams. <http://www.codeotaku.com>
|
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/strings'
|
28
|
-
|
29
|
-
class TestStrings < Test::Unit::TestCase
|
30
|
-
def test_to_html
|
31
|
-
text = Trenni::Strings.to_html("<foobar>")
|
32
|
-
assert_equal "<foobar>", text
|
33
|
-
|
34
|
-
text = Trenni::Strings.to_html(%q{"I'd like to do this & that :p", she said.})
|
35
|
-
assert_equal %q{"I'd like to do this & that :p", she said.}, text
|
36
|
-
end
|
37
|
-
|
38
|
-
def test_to_quoted_string
|
39
|
-
text = Trenni::Strings.to_quoted_string(%Q{"Hello World"})
|
40
|
-
assert_equal %q{"\"Hello World\""}, text
|
41
|
-
|
42
|
-
text = Trenni::Strings.to_quoted_string(%Q{"Hello\r\nWorld"})
|
43
|
-
assert_equal %q{"\"Hello\r\nWorld\""}, text
|
44
|
-
end
|
45
|
-
|
46
|
-
def test_to_attribute
|
47
|
-
text = Trenni::Strings.to_attribute(:foo, 'bar')
|
48
|
-
assert_equal %Q{foo="bar"}, text
|
49
|
-
|
50
|
-
text = Trenni::Strings.to_simple_attribute(:foo, false)
|
51
|
-
assert_equal %Q{foo}, text
|
52
|
-
|
53
|
-
text = Trenni::Strings.to_simple_attribute(:foo, true)
|
54
|
-
assert_equal %Q{foo="foo"}, text
|
55
|
-
end
|
56
|
-
|
57
|
-
def self.to_simple_attribute
|
58
|
-
strict ? %Q{#{key}="#{key}"} : key.to_s
|
59
|
-
end
|
60
|
-
|
61
|
-
def test_to_title
|
62
|
-
text = Trenni::Strings.to_title("foo bar")
|
63
|
-
assert_equal "Foo Bar", text
|
64
|
-
end
|
65
|
-
|
66
|
-
def test_to_snake
|
67
|
-
text = Trenni::Strings.to_snake("Happy::Go::Lucky")
|
68
|
-
assert_equal "happy_go_lucky", text
|
69
|
-
end
|
70
|
-
end
|