1
0
Fork 0

Add Builder and Markaby

This commit is contained in:
Gregory Eremin 2013-12-14 04:12:26 +07:00
parent 0425c8bac9
commit 89467c5c67
No known key found for this signature in database
GPG Key ID: 5EFA427EEC26E86C
15 changed files with 152 additions and 36 deletions

View File

@ -8,3 +8,4 @@ gem 'haml'
gem 'slim' gem 'slim'
gem 'liquid' gem 'liquid'
gem 'mustache' gem 'mustache'
gem 'markaby'

View File

@ -1,6 +1,7 @@
GEM GEM
remote: https://rubygems.org/ remote: https://rubygems.org/
specs: specs:
builder (3.2.2)
erubis (2.7.0) erubis (2.7.0)
faker (1.2.0) faker (1.2.0)
i18n (~> 0.5) i18n (~> 0.5)
@ -8,6 +9,8 @@ GEM
tilt tilt
i18n (0.6.9) i18n (0.6.9)
liquid (2.6.0) liquid (2.6.0)
markaby (0.7.2)
builder (>= 2.0.0)
mustache (0.99.5) mustache (0.99.5)
slim (2.0.2) slim (2.0.2)
temple (~> 0.6.6) temple (~> 0.6.6)
@ -23,6 +26,7 @@ DEPENDENCIES
faker faker
haml haml
liquid liquid
markaby
mustache mustache
slim slim
tilt tilt

View File

@ -2,13 +2,17 @@
#### Ruby implementations. #### Ruby implementations.
## Competitors ## Competitors
- Builder
- ERB - ERB
- Erubis - Erubis
- Haml - Haml
- Liquid - Liquid
- Markaby
- Mustache - Mustache
- Slim - Slim
... and our special guest ... ... and our special guest ...
- String interpolation - String interpolation
## Running ## Running
@ -33,47 +37,55 @@ bundle install
## Compilation (small) (1000 runs) ## ## Compilation (small) (1000 runs) ##
############################################################ ############################################################
user system total real user system total real
string 0.040000 0.020000 0.060000 ( 0.053855) string 0.030000 0.020000 0.050000 ( 0.046353)
erubis 0.060000 0.010000 0.070000 ( 0.075751) erubis 0.060000 0.020000 0.080000 ( 0.079977)
erb 0.240000 0.030000 0.270000 ( 0.262077) erb 0.260000 0.020000 0.280000 ( 0.273492)
haml 0.840000 0.020000 0.860000 ( 0.865688) haml 0.850000 0.020000 0.870000 ( 0.874163)
slim 1.930000 0.040000 1.970000 ( 1.968993) slim 1.970000 0.040000 2.010000 ( 2.003406)
mustache 0.020000 0.010000 0.030000 ( 0.030289) mustache 0.020000 0.010000 0.030000 ( 0.034893)
liquid 0.080000 0.020000 0.100000 ( 0.104174) liquid 0.050000 0.020000 0.070000 ( 0.074104)
markaby 0.030000 0.020000 0.050000 ( 0.039915)
builder 0.020000 0.010000 0.030000 ( 0.039993)
############################################################ ############################################################
## Render (small) (1000 runs) ## ## Render (small) (1000 runs) ##
############################################################ ############################################################
user system total real user system total real
string 0.010000 0.000000 0.010000 ( 0.007824) string 0.010000 0.000000 0.010000 ( 0.009001)
erubis 0.010000 0.000000 0.010000 ( 0.008019) erubis 0.010000 0.000000 0.010000 ( 0.008587)
erb 0.010000 0.000000 0.010000 ( 0.010448) erb 0.010000 0.000000 0.010000 ( 0.012027)
haml 0.020000 0.000000 0.020000 ( 0.019507) haml 0.020000 0.010000 0.030000 ( 0.022236)
slim 0.020000 0.000000 0.020000 ( 0.019644) slim 0.020000 0.000000 0.020000 ( 0.021628)
mustache 0.230000 0.000000 0.230000 ( 0.232938) mustache 0.250000 0.000000 0.250000 ( 0.257850)
liquid 0.040000 0.000000 0.040000 ( 0.044189) liquid 0.050000 0.000000 0.050000 ( 0.045442)
markaby 0.230000 0.000000 0.230000 ( 0.232095)
builder 0.200000 0.000000 0.200000 ( 0.196965)
############################################################ ############################################################
## Compilation (big) (1000 runs) ## ## Compilation (big) (1000 runs) ##
############################################################ ############################################################
user system total real user system total real
string 0.030000 0.020000 0.050000 ( 0.044706) string 0.030000 0.020000 0.050000 ( 0.043935)
erubis 0.140000 0.020000 0.160000 ( 0.161244) erubis 0.150000 0.020000 0.170000 ( 0.176325)
erb 0.320000 0.030000 0.350000 ( 0.341144) erb 0.310000 0.020000 0.330000 ( 0.325486)
haml 1.180000 0.020000 1.200000 ( 1.205595) haml 1.190000 0.030000 1.220000 ( 1.217889)
slim 2.410000 0.040000 2.450000 ( 2.449355) slim 2.430000 0.030000 2.460000 ( 2.468188)
mustache 0.020000 0.010000 0.030000 ( 0.028152) mustache 0.020000 0.020000 0.040000 ( 0.031460)
liquid 0.110000 0.020000 0.130000 ( 0.133382) liquid 0.110000 0.020000 0.130000 ( 0.134760)
markaby 0.030000 0.010000 0.040000 ( 0.039455)
builder 0.020000 0.020000 0.040000 ( 0.040826)
############################################################ ############################################################
## Render (big) (100 runs) ## ## Render (big) (100 runs) ##
############################################################ ############################################################
user system total real user system total real
string 0.390000 0.020000 0.410000 ( 0.408272) string 0.370000 0.020000 0.390000 ( 0.392442)
erubis 0.440000 0.020000 0.460000 ( 0.457214) erubis 0.450000 0.020000 0.470000 ( 0.463274)
erb 0.640000 0.020000 0.660000 ( 0.656181) erb 0.630000 0.020000 0.650000 ( 0.651563)
haml 0.940000 0.020000 0.960000 ( 0.965373) haml 0.970000 0.010000 0.980000 ( 0.982174)
slim 1.390000 0.000000 1.390000 ( 1.395409) slim 1.410000 0.010000 1.420000 ( 1.422800)
mustache 3.770000 0.010000 3.780000 ( 3.778392) mustache 3.760000 0.000000 3.760000 ( 3.757236)
liquid 10.460000 0.050000 10.510000 ( 10.507224) liquid 10.440000 0.040000 10.480000 ( 10.480874)
markaby 11.560000 0.020000 11.580000 ( 11.576669)
builder 18.300000 0.030000 18.330000 ( 18.326396)
``` ```

View File

@ -31,7 +31,7 @@ unless File.exist?(big_data_file)
raise 'Big data file not found. Please generate it with "./fakedata.rb 10000 > data/big.yml"' raise 'Big data file not found. Please generate it with "./fakedata.rb 10000 > data/big.yml"'
end end
small_data = {title: 'Greetings!', username: '%username%'} small_data = {window_title: 'Greetings!', username: '%username%'}
big_data = YAML.load_file(big_data_file) big_data = YAML.load_file(big_data_file)
def banner title def banner title
@ -97,6 +97,14 @@ ENGINES = {
class: Tilt::LiquidTemplate, class: Tilt::LiquidTemplate,
extension: 'liquid' extension: 'liquid'
}, },
markaby: {
class: Tilt::MarkabyTemplate,
extension: 'mab'
},
builder: {
class: Tilt::BuilderTemplate,
extension: 'builder'
},
} }
banner 'Compilation (small) (%d runs)' % COMPILE_LOOPS banner 'Compilation (small) (%d runs)' % COMPILE_LOOPS

View File

@ -0,0 +1,27 @@
xml.html do
xml.head do
xml.title 'Customers List'
end
xml.body do
customers.each do |customer|
xml.dl do
xml.dt 'Name:'
xml.dd customer['name']
xml.dt 'Age:'
xml.dd customer['age']
xml.dt 'Address:'
xml.dd do
[
customer['zip'],
customer['country'],
customer['city'],
customer['address']
].join("\n")
end
xml.dt 'Employer:'
xml.dd customer['employer']
end
end
end
end

View File

@ -0,0 +1,19 @@
xml.html do
xml.head do
xml.title window_title
end
xml.body do
xml.h1 "Hello, #{username}!"
xml.p do
<<-END
Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod
tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim
veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea
commodo consequat. Duis aute irure dolor in reprehenderit in voluptate
velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint
occaecat cupidatat non proident, sunt in culpa qui officia deserunt
mollit anim id est laborum.
END
end
end
end

View File

@ -1,7 +1,7 @@
<!DOCTYPE html> <!DOCTYPE html>
<html> <html>
<head> <head>
<title><%= title %></title> <title><%= window_title %></title>
</head> </head>
<body> <body>
<h1>Hello, <%= username %>!</h1> <h1>Hello, <%= username %>!</h1>

View File

@ -1,7 +1,7 @@
<!DOCTYPE html> <!DOCTYPE html>
<html> <html>
<head> <head>
<title><%= title %></title> <title><%= window_title %></title>
</head> </head>
<body> <body>
<h1>Hello, <%= username %>!</h1> <h1>Hello, <%= username %>!</h1>

View File

@ -1,7 +1,7 @@
!!! !!!
%html %html
%head %head
%title= title %title= window_title
%body %body
%h1 %h1
Hello, Hello,

View File

@ -1,7 +1,7 @@
<!DOCTYPE html> <!DOCTYPE html>
<html> <html>
<head> <head>
<title>{{ title }}</title> <title>{{ window_title }}</title>
</head> </head>
<body> <body>
<h1>Hello, {{ username }}!</h1> <h1>Hello, {{ username }}!</h1>

26
templates/markaby/big.mab Normal file
View File

@ -0,0 +1,26 @@
html do
head do
title 'Customers List'
end
body do
customers.each do |customer|
dl do
dt 'Name:'
dd customer['name']
dt 'Age:'
dd customer['age']
dt 'Address:'
dd do
[
customer['zip'],
customer['country'],
customer['city'],
customer['address']
].join("\n")
end
dt 'Employer:'
dd customer['employer']
end
end
end
end

View File

@ -0,0 +1,19 @@
html do
head do
title window_title
end
body do
h1 "Hello, #{username}!"
p do
<<-END
Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod
tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim
veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea
commodo consequat. Duis aute irure dolor in reprehenderit in voluptate
velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint
occaecat cupidatat non proident, sunt in culpa qui officia deserunt
mollit anim id est laborum.
END
end
end
end

View File

@ -1,7 +1,7 @@
<!DOCTYPE html> <!DOCTYPE html>
<html> <html>
<head> <head>
<title>{{ title }}</title> <title>{{ window_title }}</title>
</head> </head>
<body> <body>
<h1>Hello, {{ username }}!</h1> <h1>Hello, {{ username }}!</h1>

View File

@ -1,7 +1,7 @@
doctype html doctype html
html html
head head
title = title title = window_title
body body
h1 Hello, #{username}! h1 Hello, #{username}!
p p

View File

@ -1,7 +1,7 @@
<!DOCTYPE html> <!DOCTYPE html>
<html> <html>
<head> <head>
<title>#{title}</title> <title>#{window_title}</title>
</head> </head>
<body> <body>
<h1>Hello, #{username}!</h1> <h1>Hello, #{username}!</h1>