smtlaissezfaire-simply 0.1.1 → 0.2.1
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +1 -0
- data/Rakefile +4 -4
- data/VERSION.yml +2 -2
- data/benchmarks/001_7a22450a80d6253bf9f0aabb2ee0110c2d67c8a6.out +23 -0
- data/benchmarks/002_e462499cd6bd8dface62e433311b3bc0b0b55a42 +27 -0
- data/benchmarks/003_fd604401b1b03096ec35cdb3036821b92a71791b.out +27 -0
- data/benchmarks/004_b75e031f96b342559036444f502d44da7e7104f0.out +27 -0
- data/benchmarks/comparison.rb +224 -0
- data/lib/simply.rb +1 -2
- data/lib/simply/escaping.rb +20 -0
- data/lib/simply/html_builder.rb +3 -6
- data/lib/simply/version.rb +3 -1
- data/profiling/run_static.rb +18 -0
- data/profiling/run_static_001_0e246c3de41a891c206c8cb5a552d17d78e4b8ec.out +157 -0
- data/reference/ABOUT +5 -0
- data/reference/xhtml1-frameset.xsd +2847 -0
- data/reference/xhtml1-strict.xsd +2211 -0
- data/reference/xhtml1-transitional.xsd +2755 -0
- data/simply.gemspec +72 -0
- data/spec/simply/html_builder/indentation_spec.rb +7 -7
- data/spec/simply/html_builder/locals_spec.rb +14 -3
- data/spec/simply/html_builder_spec.rb +13 -1
- data/spec/simply/version_spec.rb +2 -2
- metadata +23 -8
data/.gitignore
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
pkg
|
data/Rakefile
CHANGED
@@ -5,11 +5,11 @@ PROJECT_NAME = "simply"
|
|
5
5
|
begin
|
6
6
|
require 'jeweler'
|
7
7
|
Jeweler::Tasks.new do |s|
|
8
|
-
s.name = "
|
9
|
-
s.summary = "
|
8
|
+
s.name = "simply"
|
9
|
+
s.summary = "A minimal markaby-esq ruby templating language"
|
10
10
|
s.email = "scott@railsnewbie.com"
|
11
|
-
s.homepage = "http://github.com/smtlaissezfaire
|
12
|
-
s.description = "
|
11
|
+
s.homepage = "http://github.com/smtlaissezfaire/simply"
|
12
|
+
s.description = "A minimal markaby-esq ruby templating language"
|
13
13
|
s.authors = ["Scott Taylor"]
|
14
14
|
end
|
15
15
|
rescue LoadError
|
data/VERSION.yml
CHANGED
@@ -0,0 +1,23 @@
|
|
1
|
+
# of iterations = 10000
|
2
|
+
Rehearsal ------------------------------------------------------------------------------
|
3
|
+
counter time 0.000000 0.000000 0.000000 ( 0.001091)
|
4
|
+
counter time + function call overhead time 0.000000 0.000000 0.000000 ( 0.002866)
|
5
|
+
tagz 2.340000 0.020000 2.360000 ( 2.356264)
|
6
|
+
markaby 8.720000 0.030000 8.750000 ( 8.764424)
|
7
|
+
builder 2.140000 0.010000 2.150000 ( 2.154632)
|
8
|
+
haml 5.620000 0.010000 5.630000 ( 5.652289)
|
9
|
+
erb 2.240000 0.010000 2.250000 ( 2.248454)
|
10
|
+
erubis 0.420000 0.000000 0.420000 ( 0.418306)
|
11
|
+
simply 2.010000 0.000000 2.010000 ( 2.018264)
|
12
|
+
-------------------------------------------------------------------- total: 23.570000sec
|
13
|
+
|
14
|
+
user system total real
|
15
|
+
counter time 0.000000 0.000000 0.000000 ( 0.001062)
|
16
|
+
counter time + function call overhead time 0.000000 0.000000 0.000000 ( 0.002849)
|
17
|
+
tagz 2.220000 0.010000 2.230000 ( 2.238662)
|
18
|
+
markaby 9.210000 0.030000 9.240000 ( 9.261845)
|
19
|
+
builder 1.930000 0.000000 1.930000 ( 1.934298)
|
20
|
+
haml 5.220000 0.010000 5.230000 ( 5.235850)
|
21
|
+
erb 2.330000 0.010000 2.340000 ( 2.339981)
|
22
|
+
erubis 0.430000 0.000000 0.430000 ( 0.437849)
|
23
|
+
simply 2.210000 0.010000 2.220000 ( 2.223844)
|
@@ -0,0 +1,27 @@
|
|
1
|
+
# of iterations = 10000
|
2
|
+
Rehearsal ------------------------------------------------------------------------------
|
3
|
+
counter time 0.000000 0.000000 0.000000 ( 0.001055)
|
4
|
+
counter time + function call overhead time 0.010000 0.000000 0.010000 ( 0.003877)
|
5
|
+
tagz 2.620000 0.020000 2.640000 ( 2.675130)
|
6
|
+
markaby 10.220000 0.070000 10.290000 ( 10.403767)
|
7
|
+
builder 1.070000 0.000000 1.070000 ( 1.089509)
|
8
|
+
haml 5.690000 0.040000 5.730000 ( 5.770631)
|
9
|
+
erb 2.400000 0.010000 2.410000 ( 2.436488)
|
10
|
+
erubis 0.470000 0.000000 0.470000 ( 0.476391)
|
11
|
+
nokogiri 1.930000 0.010000 1.940000 ( 1.961594)
|
12
|
+
simply 1.450000 0.010000 1.460000 ( 1.465180)
|
13
|
+
erector 0.150000 0.000000 0.150000 ( 0.155925)
|
14
|
+
-------------------------------------------------------------------- total: 26.170000sec
|
15
|
+
|
16
|
+
user system total real
|
17
|
+
counter time 0.000000 0.000000 0.000000 ( 0.001063)
|
18
|
+
counter time + function call overhead time 0.000000 0.000000 0.000000 ( 0.003963)
|
19
|
+
tagz 2.630000 0.020000 2.650000 ( 2.669872)
|
20
|
+
markaby 10.200000 0.060000 10.260000 ( 10.367525)
|
21
|
+
builder 1.070000 0.010000 1.080000 ( 1.093933)
|
22
|
+
haml 5.650000 0.040000 5.690000 ( 5.745920)
|
23
|
+
erb 2.420000 0.020000 2.440000 ( 2.462542)
|
24
|
+
erubis 0.430000 0.000000 0.430000 ( 0.439791)
|
25
|
+
nokogiri 1.930000 0.010000 1.940000 ( 1.967485)
|
26
|
+
simply 1.380000 0.010000 1.390000 ( 1.405759)
|
27
|
+
erector 0.160000 0.000000 0.160000 ( 0.155949)
|
@@ -0,0 +1,27 @@
|
|
1
|
+
# of iterations = 10000
|
2
|
+
Rehearsal ------------------------------------------------------------------------------
|
3
|
+
counter time 0.000000 0.000000 0.000000 ( 0.001055)
|
4
|
+
counter time + function call overhead time 0.000000 0.000000 0.000000 ( 0.002811)
|
5
|
+
tagz 2.540000 0.020000 2.560000 ( 2.744199)
|
6
|
+
markaby 9.940000 0.080000 10.020000 ( 10.658650)
|
7
|
+
builder 1.020000 0.010000 1.030000 ( 1.171982)
|
8
|
+
haml 5.500000 0.050000 5.550000 ( 6.917135)
|
9
|
+
erb 2.270000 0.010000 2.280000 ( 2.797811)
|
10
|
+
erubis 0.430000 0.010000 0.440000 ( 0.463208)
|
11
|
+
nokogiri 1.950000 0.020000 1.970000 ( 2.138772)
|
12
|
+
simply 2.330000 0.020000 2.350000 ( 2.550994)
|
13
|
+
erector 0.220000 0.000000 0.220000 ( 0.223103)
|
14
|
+
-------------------------------------------------------------------- total: 26.420000sec
|
15
|
+
|
16
|
+
user system total real
|
17
|
+
counter time 0.000000 0.000000 0.000000 ( 0.001063)
|
18
|
+
counter time + function call overhead time 0.000000 0.000000 0.000000 ( 0.004023)
|
19
|
+
tagz 2.480000 0.020000 2.500000 ( 3.047870)
|
20
|
+
markaby 9.880000 0.070000 9.950000 ( 10.771271)
|
21
|
+
builder 1.030000 0.010000 1.040000 ( 1.093748)
|
22
|
+
haml 5.650000 0.040000 5.690000 ( 6.100592)
|
23
|
+
erb 2.370000 0.030000 2.400000 ( 2.575887)
|
24
|
+
erubis 0.400000 0.000000 0.400000 ( 0.479711)
|
25
|
+
nokogiri 1.910000 0.020000 1.930000 ( 2.054972)
|
26
|
+
simply 2.320000 0.020000 2.340000 ( 2.604975)
|
27
|
+
erector 0.150000 0.000000 0.150000 ( 0.172422)
|
@@ -0,0 +1,27 @@
|
|
1
|
+
# of iterations = 10000
|
2
|
+
Rehearsal ------------------------------------------------------------------------------
|
3
|
+
counter time 0.000000 0.000000 0.000000 ( 0.001575)
|
4
|
+
counter time + function call overhead time 0.000000 0.000000 0.000000 ( 0.003454)
|
5
|
+
tagz 2.560000 0.020000 2.580000 ( 2.703877)
|
6
|
+
markaby 9.950000 0.070000 10.020000 ( 10.547215)
|
7
|
+
builder 1.030000 0.020000 1.050000 ( 1.096580)
|
8
|
+
haml 5.700000 0.030000 5.730000 ( 5.992496)
|
9
|
+
erb 2.400000 0.020000 2.420000 ( 2.540554)
|
10
|
+
erubis 0.420000 0.000000 0.420000 ( 0.441572)
|
11
|
+
nokogiri 1.940000 0.020000 1.960000 ( 2.038399)
|
12
|
+
simply 2.340000 0.010000 2.350000 ( 2.482033)
|
13
|
+
erector 0.210000 0.000000 0.210000 ( 0.212933)
|
14
|
+
-------------------------------------------------------------------- total: 26.740000sec
|
15
|
+
|
16
|
+
user system total real
|
17
|
+
counter time 0.000000 0.000000 0.000000 ( 0.001111)
|
18
|
+
counter time + function call overhead time 0.010000 0.000000 0.010000 ( 0.002913)
|
19
|
+
tagz 2.570000 0.020000 2.590000 ( 2.706161)
|
20
|
+
markaby 9.770000 0.060000 9.830000 ( 10.536178)
|
21
|
+
builder 1.030000 0.010000 1.040000 ( 1.083472)
|
22
|
+
haml 5.690000 0.040000 5.730000 ( 6.061707)
|
23
|
+
erb 2.380000 0.010000 2.390000 ( 2.513181)
|
24
|
+
erubis 0.420000 0.010000 0.430000 ( 0.445088)
|
25
|
+
nokogiri 1.890000 0.010000 1.900000 ( 2.005374)
|
26
|
+
simply 2.340000 0.020000 2.360000 ( 2.466595)
|
27
|
+
erector 0.160000 0.000000 0.160000 ( 0.164743)
|
@@ -0,0 +1,224 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
require 'benchmark'
|
3
|
+
require "erb"
|
4
|
+
require 'rubygems'
|
5
|
+
require 'markaby'
|
6
|
+
require 'tagz'
|
7
|
+
require 'builder'
|
8
|
+
require 'haml'
|
9
|
+
require 'erubis'
|
10
|
+
require "nokogiri"
|
11
|
+
require "erector"
|
12
|
+
require File.dirname(__FILE__) + "/../lib/simply"
|
13
|
+
|
14
|
+
MAX = (ARGV.shift || 10_000).to_i
|
15
|
+
|
16
|
+
def do_nothing
|
17
|
+
# do nothing
|
18
|
+
end
|
19
|
+
|
20
|
+
def do_erb
|
21
|
+
str = <<-EOF
|
22
|
+
<html>
|
23
|
+
<head>
|
24
|
+
<title>happy title</title>
|
25
|
+
</head>
|
26
|
+
<body>
|
27
|
+
<h1>happy heading</h1>
|
28
|
+
<a href='<%= 'url' %>'>a link</a>
|
29
|
+
</body>
|
30
|
+
</html>
|
31
|
+
EOF
|
32
|
+
ERB.new(str)
|
33
|
+
end
|
34
|
+
|
35
|
+
def do_erubis
|
36
|
+
str = <<-EOF
|
37
|
+
<html>
|
38
|
+
<head>
|
39
|
+
<title>happy title</title>
|
40
|
+
</head>
|
41
|
+
<body>
|
42
|
+
<h1>happy heading</h1>
|
43
|
+
<a href='<%= 'url' %>'>a link</a>
|
44
|
+
</body>
|
45
|
+
</html>
|
46
|
+
EOF
|
47
|
+
Erubis::Eruby.new(str)
|
48
|
+
end
|
49
|
+
|
50
|
+
def do_haml
|
51
|
+
str = <<-EOF
|
52
|
+
%html
|
53
|
+
%head
|
54
|
+
%title_ "happy title"
|
55
|
+
%body
|
56
|
+
%h1 "happy heading"
|
57
|
+
%a "a link", :href => "url"
|
58
|
+
EOF
|
59
|
+
Haml::Engine.new(str)
|
60
|
+
end
|
61
|
+
|
62
|
+
def do_tagz
|
63
|
+
Tagz {
|
64
|
+
html_ {
|
65
|
+
head_ {
|
66
|
+
title_ "happy title"
|
67
|
+
}
|
68
|
+
body_ {
|
69
|
+
h1_ "happy heading"
|
70
|
+
a_ "a link", :href => "url"
|
71
|
+
}
|
72
|
+
}
|
73
|
+
}
|
74
|
+
end
|
75
|
+
|
76
|
+
def do_builder
|
77
|
+
Builder::XmlMarkup.new.html do |xm|
|
78
|
+
xm.head do
|
79
|
+
xm.title "happy title"
|
80
|
+
end
|
81
|
+
xm.body do
|
82
|
+
xm.h1 "happy heading"
|
83
|
+
xm.a "a link", :href => "url"
|
84
|
+
end
|
85
|
+
end
|
86
|
+
end
|
87
|
+
|
88
|
+
def do_markaby
|
89
|
+
mab = Markaby::Builder.new :output_meta_tag => false
|
90
|
+
|
91
|
+
mab.html {
|
92
|
+
head {
|
93
|
+
title "happy title"
|
94
|
+
}
|
95
|
+
body {
|
96
|
+
h1 "happy heading"
|
97
|
+
a "a link", :href => "url"
|
98
|
+
}
|
99
|
+
}.to_s
|
100
|
+
end
|
101
|
+
|
102
|
+
def do_simply
|
103
|
+
Simply do
|
104
|
+
html do
|
105
|
+
head do
|
106
|
+
title "happy title"
|
107
|
+
end
|
108
|
+
|
109
|
+
body do
|
110
|
+
h1 "happy heading"
|
111
|
+
a "a link", :href => "url"
|
112
|
+
end
|
113
|
+
end
|
114
|
+
end
|
115
|
+
end
|
116
|
+
|
117
|
+
def do_nokogiri
|
118
|
+
Nokogiri do
|
119
|
+
html do
|
120
|
+
head do
|
121
|
+
title "happy title"
|
122
|
+
end
|
123
|
+
|
124
|
+
body do
|
125
|
+
h1 "happy heading"
|
126
|
+
a :href => "url" do
|
127
|
+
text "a link"
|
128
|
+
end
|
129
|
+
end
|
130
|
+
end
|
131
|
+
end
|
132
|
+
end
|
133
|
+
|
134
|
+
def do_erector
|
135
|
+
Erector::Widget.new do
|
136
|
+
html do
|
137
|
+
head do
|
138
|
+
title "happy title"
|
139
|
+
end
|
140
|
+
|
141
|
+
body do
|
142
|
+
h1 "happy heading"
|
143
|
+
a "a link", :href => "url"
|
144
|
+
end
|
145
|
+
end
|
146
|
+
end.to_pretty
|
147
|
+
end
|
148
|
+
|
149
|
+
|
150
|
+
x = do_tagz
|
151
|
+
y = do_markaby
|
152
|
+
z = do_builder
|
153
|
+
|
154
|
+
raise "bad!\n\n#{x}\n\n#{y}" unless x == y
|
155
|
+
raise "bad!\n\n#{x}\n\n#{z}" unless x == z
|
156
|
+
|
157
|
+
puts "# of iterations = #{MAX}"
|
158
|
+
Benchmark.bmbm do |x|
|
159
|
+
x.report("counter time") do
|
160
|
+
for i in 0..MAX
|
161
|
+
# do nothing
|
162
|
+
end
|
163
|
+
end
|
164
|
+
|
165
|
+
x.report("counter time + function call overhead time") do
|
166
|
+
for i in 0..MAX do
|
167
|
+
do_nothing
|
168
|
+
end
|
169
|
+
end
|
170
|
+
|
171
|
+
x.report("tagz") do
|
172
|
+
for i in 0..MAX do
|
173
|
+
do_tagz
|
174
|
+
end
|
175
|
+
end
|
176
|
+
|
177
|
+
x.report("markaby") do
|
178
|
+
for i in 0..MAX do
|
179
|
+
do_markaby
|
180
|
+
end
|
181
|
+
end
|
182
|
+
|
183
|
+
x.report("builder") do
|
184
|
+
for i in 0..MAX do
|
185
|
+
do_builder
|
186
|
+
end
|
187
|
+
end
|
188
|
+
|
189
|
+
x.report("haml") do
|
190
|
+
for i in 0..MAX do
|
191
|
+
do_haml
|
192
|
+
end
|
193
|
+
end
|
194
|
+
|
195
|
+
x.report("erb") do
|
196
|
+
for i in 0..MAX do
|
197
|
+
do_erb
|
198
|
+
end
|
199
|
+
end
|
200
|
+
|
201
|
+
x.report("erubis") do
|
202
|
+
for i in 0..MAX do
|
203
|
+
do_erubis
|
204
|
+
end
|
205
|
+
end
|
206
|
+
|
207
|
+
x.report("nokogiri") do
|
208
|
+
for i in 0..MAX do
|
209
|
+
do_nokogiri
|
210
|
+
end
|
211
|
+
end
|
212
|
+
|
213
|
+
x.report("simply") do
|
214
|
+
for i in 0..MAX do
|
215
|
+
do_simply
|
216
|
+
end
|
217
|
+
end
|
218
|
+
|
219
|
+
x.report("erector") do
|
220
|
+
for i in 0..MAX do
|
221
|
+
do_erector
|
222
|
+
end
|
223
|
+
end
|
224
|
+
end
|
data/lib/simply.rb
CHANGED
@@ -0,0 +1,20 @@
|
|
1
|
+
module Simply
|
2
|
+
module Escaping
|
3
|
+
#
|
4
|
+
# A utility method for escaping HTML tag characters in _s_.
|
5
|
+
#
|
6
|
+
# Taken from ERB::Util
|
7
|
+
#
|
8
|
+
# puts html_escape("is a > 0 & a < 10?")
|
9
|
+
#
|
10
|
+
# _Generates_
|
11
|
+
#
|
12
|
+
# is a > 0 & a < 10?
|
13
|
+
#
|
14
|
+
def html_escape(s)
|
15
|
+
s.to_s.gsub(/&/, "&").gsub(/\"/, """).gsub(/>/, ">").gsub(/</, "<")
|
16
|
+
end
|
17
|
+
|
18
|
+
alias_method :h, :html_escape
|
19
|
+
end
|
20
|
+
end
|
data/lib/simply/html_builder.rb
CHANGED
@@ -1,6 +1,7 @@
|
|
1
1
|
module Simply
|
2
2
|
class HTMLBuilder
|
3
3
|
include Locals
|
4
|
+
include Escaping
|
4
5
|
|
5
6
|
unless defined?(SELF_CLOSING_TAGS)
|
6
7
|
SELF_CLOSING_TAGS = HTMLTags::SELF_CLOSING_TAGS
|
@@ -14,7 +15,7 @@ module Simply
|
|
14
15
|
self.locals = locals_hash
|
15
16
|
end
|
16
17
|
|
17
|
-
@indented =
|
18
|
+
@indented = options[:indented].equal?(false) ? false : true
|
18
19
|
@out.extend Indentation if indented?
|
19
20
|
|
20
21
|
instance_eval(&block) if block_given?
|
@@ -71,17 +72,13 @@ module Simply
|
|
71
72
|
####################
|
72
73
|
|
73
74
|
def text(out)
|
74
|
-
@out << out
|
75
|
+
@out << out.to_s
|
75
76
|
end
|
76
77
|
|
77
78
|
def clean_text(out)
|
78
79
|
text html_escape(out)
|
79
80
|
end
|
80
81
|
|
81
|
-
def html_escape(out)
|
82
|
-
out.to_s.to_xs
|
83
|
-
end
|
84
|
-
|
85
82
|
def to_s
|
86
83
|
@out
|
87
84
|
end
|
data/lib/simply/version.rb
CHANGED