trenni 1.0.0 → 1.0.1
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.
- data/README.md +7 -8
- data/lib/trenni/builder.rb +19 -8
- data/lib/trenni/version.rb +1 -1
- data/test/test_builder.rb +22 -2
- data/trenni.gemspec +4 -4
- metadata +6 -7
data/README.md
CHANGED
@@ -1,16 +1,13 @@
|
|
1
1
|
# Trenni
|
2
2
|
|
3
|
-
[](http://travis-ci.org/ioquatix/relaxo)
|
4
|
-
|
5
3
|
Trenni is a templating system that evaluates textual strings containing Ruby
|
6
|
-
code. It compiles templates into native
|
7
|
-
|
4
|
+
code. It compiles templates directly into native code which means that you
|
5
|
+
generally get the best possible performance.
|
8
6
|
|
9
7
|
In addition, Trenni includes an SGML/XML builder to assist with the generation
|
10
|
-
of
|
8
|
+
of pleasantly formatted markup.
|
11
9
|
|
12
|
-
|
13
|
-
* Copyright (c) 2012 [Samuel G. D. Williams](http://www.codeotaku.com/samuel-williams/).
|
10
|
+
[](http://travis-ci.org/ioquatix/trenni)
|
14
11
|
|
15
12
|
## Installation
|
16
13
|
|
@@ -48,7 +45,9 @@ The code above demonstraights the only two constructs, `<?r expression ?>` and `
|
|
48
45
|
|
49
46
|
## License
|
50
47
|
|
51
|
-
|
48
|
+
Released under the MIT license.
|
49
|
+
|
50
|
+
Copyright (c) 2012 [Samuel G. D. Williams](http://www.codeotaku.com/samuel-williams/).
|
52
51
|
|
53
52
|
Permission is hereby granted, free of charge, to any person obtaining
|
54
53
|
a copy of this software and associated documentation files (the
|
data/lib/trenni/builder.rb
CHANGED
@@ -50,7 +50,7 @@ module Trenni
|
|
50
50
|
def instruct(attributes = nil)
|
51
51
|
attributes ||= INSTRUCT_ATTRIBUTES
|
52
52
|
|
53
|
-
@output.puts "<?xml#{
|
53
|
+
@output.puts "<?xml#{tag_attributes(attributes)}?>"
|
54
54
|
end
|
55
55
|
|
56
56
|
def doctype(attributes = 'html')
|
@@ -73,7 +73,7 @@ module Trenni
|
|
73
73
|
def tag(name, attributes = {}, &block)
|
74
74
|
if block_given?
|
75
75
|
@output.puts if indent? and @level.last > 0
|
76
|
-
@output.write indent + "<#{name}#{
|
76
|
+
@output.write indent + "<#{name}#{tag_attributes(attributes)}>"
|
77
77
|
@output.puts if indent?
|
78
78
|
|
79
79
|
@level[@level.size-1] += 1
|
@@ -85,7 +85,7 @@ module Trenni
|
|
85
85
|
@output.puts if indent?
|
86
86
|
@output.write indent + "</#{name}>"
|
87
87
|
else
|
88
|
-
@output.write indent + "<#{name}#{
|
88
|
+
@output.write indent + "<#{name}#{tag_attributes(attributes)}/>"
|
89
89
|
end
|
90
90
|
end
|
91
91
|
|
@@ -109,16 +109,27 @@ module Trenni
|
|
109
109
|
@options = saved_options
|
110
110
|
end
|
111
111
|
|
112
|
-
|
112
|
+
def tag_attributes(attributes)
|
113
|
+
self.class.tag_attributes(attributes, @options[:strict])
|
114
|
+
end
|
113
115
|
|
114
|
-
|
115
|
-
|
116
|
+
# Convert a set of attributes into a string suitable for use within a <tag>.
|
117
|
+
def self.tag_attributes(attributes, strict = false)
|
118
|
+
buffer = []
|
116
119
|
|
117
120
|
attributes.each do |key, value|
|
118
|
-
|
121
|
+
if value == true
|
122
|
+
buffer << (strict ? "#{key}=\"#{key}\"" : key)
|
123
|
+
elsif value
|
124
|
+
buffer << "#{key}=\"#{value.to_s.gsub('"', '"')}\""
|
125
|
+
end
|
119
126
|
end
|
120
127
|
|
121
|
-
|
128
|
+
if buffer.size > 0
|
129
|
+
return ' ' + buffer.join(' ')
|
130
|
+
else
|
131
|
+
return ''
|
132
|
+
end
|
122
133
|
end
|
123
134
|
end
|
124
135
|
|
data/lib/trenni/version.rb
CHANGED
data/test/test_builder.rb
CHANGED
@@ -23,6 +23,7 @@
|
|
23
23
|
require 'pathname'
|
24
24
|
require 'test/unit'
|
25
25
|
require 'stringio'
|
26
|
+
require 'digest/md5'
|
26
27
|
|
27
28
|
require 'trenni'
|
28
29
|
|
@@ -37,11 +38,11 @@ class BuilderTest < Test::Unit::TestCase
|
|
37
38
|
builder.text("apples and oranges")
|
38
39
|
end
|
39
40
|
|
40
|
-
assert_equal
|
41
|
+
assert_equal "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<foo bar=\"baz\">apples and oranges</foo>", output.string
|
41
42
|
end
|
42
43
|
|
43
44
|
def test_html
|
44
|
-
output =
|
45
|
+
output = StringIO.new
|
45
46
|
|
46
47
|
builder = Trenni::Builder.new(:output => output, :indent => "\t")
|
47
48
|
builder.options(:indent => "\t") do
|
@@ -56,5 +57,24 @@ class BuilderTest < Test::Unit::TestCase
|
|
56
57
|
end
|
57
58
|
end
|
58
59
|
end
|
60
|
+
|
61
|
+
assert_equal "<!DOCTYPE html>\n<html>\n\t<head>\n\t\t<title>\n\t\t\tHello World\n\t\t</title>\n\t</head>\n\t<body>\n\n\t</body>\n</html>", output.string
|
62
|
+
end
|
63
|
+
|
64
|
+
def test_attributes
|
65
|
+
# Non-strict output (e.g. HTML)
|
66
|
+
text = Trenni::Builder.tag_attributes({:required => true})
|
67
|
+
assert_equal " required", text
|
68
|
+
|
69
|
+
# Strict output (e.g. XML)
|
70
|
+
text = Trenni::Builder.tag_attributes({:required => true}, true)
|
71
|
+
assert_equal " required=\"required\"", text
|
72
|
+
|
73
|
+
text = Trenni::Builder.tag_attributes({:required => false})
|
74
|
+
assert_equal "", text
|
75
|
+
|
76
|
+
# Check the order is correct
|
77
|
+
text = Trenni::Builder.tag_attributes([[:a, 10], [:b, 20]])
|
78
|
+
assert_equal " a=\"10\" b=\"20\"", text
|
59
79
|
end
|
60
80
|
end
|
data/trenni.gemspec
CHANGED
@@ -10,11 +10,11 @@ Gem::Specification.new do |gem|
|
|
10
10
|
gem.email = ["samuel.williams@oriontransfer.co.nz"]
|
11
11
|
gem.description = <<-EOF
|
12
12
|
Trenni is a templating system that evaluates textual strings containing Ruby
|
13
|
-
code. It compiles templates into native
|
14
|
-
|
15
|
-
|
13
|
+
code. It compiles templates directly into native code which means that you
|
14
|
+
generally get the best possible performance.
|
15
|
+
|
16
16
|
In addition, Trenni includes an SGML/XML builder to assist with the generation
|
17
|
-
of
|
17
|
+
of pleasantly formatted markup.
|
18
18
|
EOF
|
19
19
|
gem.summary = %q{A fast native templating system that compiles directly to Ruby code.}
|
20
20
|
gem.homepage = "https://github.com/ioquatix/trenni"
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: trenni
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.0.
|
4
|
+
version: 1.0.1
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -12,10 +12,9 @@ cert_chain: []
|
|
12
12
|
date: 2012-10-25 00:00:00.000000000 Z
|
13
13
|
dependencies: []
|
14
14
|
description: ! "\tTrenni is a templating system that evaluates textual strings containing
|
15
|
-
Ruby\n\tcode. It compiles templates into native
|
16
|
-
|
17
|
-
|
18
|
-
formatted markup.\n"
|
15
|
+
Ruby\n\tcode. It compiles templates directly into native code which means that you\n\tgenerally
|
16
|
+
get the best possible performance.\n\n\tIn addition, Trenni includes an SGML/XML
|
17
|
+
builder to assist with the generation\n\tof pleasantly formatted markup.\n"
|
19
18
|
email:
|
20
19
|
- samuel.williams@oriontransfer.co.nz
|
21
20
|
executables: []
|
@@ -48,7 +47,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
48
47
|
version: '0'
|
49
48
|
segments:
|
50
49
|
- 0
|
51
|
-
hash:
|
50
|
+
hash: -1799901624385534337
|
52
51
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
53
52
|
none: false
|
54
53
|
requirements:
|
@@ -57,7 +56,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
57
56
|
version: '0'
|
58
57
|
segments:
|
59
58
|
- 0
|
60
|
-
hash:
|
59
|
+
hash: -1799901624385534337
|
61
60
|
requirements: []
|
62
61
|
rubyforge_project:
|
63
62
|
rubygems_version: 1.8.24
|