haml 1.8.0 → 2.0.3
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/FAQ +138 -0
- data/MIT-LICENSE +1 -1
- data/{README → README.rdoc} +66 -3
- data/REVISION +1 -0
- data/Rakefile +115 -147
- data/VERSION +1 -1
- data/bin/css2sass +0 -0
- data/bin/haml +2 -1
- data/bin/html2haml +0 -0
- data/bin/sass +0 -0
- data/init.rb +6 -1
- data/lib/haml/buffer.rb +122 -64
- data/lib/haml/engine.rb +77 -46
- data/lib/haml/error.rb +15 -6
- data/lib/haml/exec.rb +61 -10
- data/lib/haml/filters.rb +229 -74
- data/lib/haml/helpers/action_view_extensions.rb +1 -1
- data/lib/haml/helpers/action_view_mods.rb +109 -24
- data/lib/haml/helpers.rb +137 -76
- data/lib/haml/html.rb +8 -8
- data/lib/haml/precompiler.rb +280 -153
- data/lib/haml/template/patch.rb +10 -3
- data/lib/haml/template/plugin.rb +61 -10
- data/lib/haml/template.rb +14 -9
- data/lib/haml.rb +483 -214
- data/lib/sass/constant/color.rb +13 -13
- data/lib/sass/constant/literal.rb +8 -7
- data/lib/sass/constant/nil.rb +9 -0
- data/lib/sass/constant/number.rb +10 -10
- data/lib/sass/constant/operation.rb +4 -4
- data/lib/sass/constant/string.rb +3 -3
- data/lib/sass/constant.rb +46 -77
- data/lib/sass/css.rb +130 -56
- data/lib/sass/engine.rb +131 -43
- data/lib/sass/plugin/merb.rb +48 -12
- data/lib/sass/plugin/rails.rb +10 -4
- data/lib/sass/plugin.rb +33 -10
- data/lib/sass/tree/attr_node.rb +5 -5
- data/lib/sass/tree/directive_node.rb +2 -7
- data/lib/sass/tree/node.rb +1 -12
- data/lib/sass/tree/rule_node.rb +39 -31
- data/lib/sass/tree/value_node.rb +1 -1
- data/lib/sass.rb +194 -19
- data/rails/init.rb +1 -0
- data/test/benchmark.rb +67 -80
- data/test/haml/engine_test.rb +368 -152
- data/test/haml/helper_test.rb +68 -16
- data/test/haml/html2haml_test.rb +3 -4
- data/test/haml/results/content_for_layout.xhtml +1 -2
- data/test/haml/results/eval_suppressed.xhtml +2 -4
- data/test/haml/results/filters.xhtml +38 -30
- data/test/haml/results/helpers.xhtml +4 -8
- data/test/haml/results/just_stuff.xhtml +8 -7
- data/test/haml/results/nuke_inner_whitespace.xhtml +40 -0
- data/test/haml/results/nuke_outer_whitespace.xhtml +148 -0
- data/test/haml/results/original_engine.xhtml +3 -7
- data/test/haml/results/partials.xhtml +1 -0
- data/test/haml/results/tag_parsing.xhtml +1 -6
- data/test/haml/results/very_basic.xhtml +2 -4
- data/test/haml/results/whitespace_handling.xhtml +13 -21
- data/test/haml/template_test.rb +42 -57
- data/test/haml/templates/_partial.haml +1 -0
- data/test/haml/templates/filters.haml +39 -21
- data/test/haml/templates/helpers.haml +10 -10
- data/test/haml/templates/just_stuff.haml +8 -3
- data/test/haml/templates/nuke_inner_whitespace.haml +32 -0
- data/test/haml/templates/nuke_outer_whitespace.haml +144 -0
- data/test/haml/templates/partials.haml +1 -1
- data/test/haml/templates/tag_parsing.haml +0 -3
- data/test/haml/templates/whitespace_handling.haml +10 -10
- data/test/sass/engine_test.rb +97 -39
- data/test/sass/plugin_test.rb +4 -7
- data/test/sass/results/constants.css +2 -0
- data/test/sass/results/import.css +2 -2
- data/test/sass/results/mixins.css +95 -0
- data/test/sass/results/multiline.css +24 -0
- data/test/sass/templates/constants.sass +3 -0
- data/test/sass/templates/import.sass +4 -1
- data/test/sass/templates/importee.sass +4 -0
- data/test/sass/templates/mixins.sass +76 -0
- data/test/sass/templates/multiline.sass +20 -0
- data/test/test_helper.rb +18 -0
- metadata +70 -53
- data/lib/haml/helpers/action_view_mods.rb.rej +0 -30
- data/lib/haml/util.rb +0 -18
- data/lib/sass/constant.rb.rej +0 -42
- data/test/haml/runner.rb +0 -16
- data/test/profile.rb +0 -65
- data/test/sass/engine_test.rb.rej +0 -18
data/lib/sass.rb
CHANGED
|
@@ -11,7 +11,7 @@ $LOAD_PATH << dir unless $LOAD_PATH.include?(dir)
|
|
|
11
11
|
# and implements various features that are useful
|
|
12
12
|
# for creating manageable stylesheets.
|
|
13
13
|
#
|
|
14
|
-
# == Features
|
|
14
|
+
# == Features
|
|
15
15
|
#
|
|
16
16
|
# * Whitespace active
|
|
17
17
|
# * Well-formatted output
|
|
@@ -20,9 +20,10 @@ $LOAD_PATH << dir unless $LOAD_PATH.include?(dir)
|
|
|
20
20
|
#
|
|
21
21
|
# == Using Sass
|
|
22
22
|
#
|
|
23
|
-
# Sass can be used in
|
|
24
|
-
#
|
|
25
|
-
#
|
|
23
|
+
# Sass can be used in three ways:
|
|
24
|
+
# as a plugin for Ruby on Rails,
|
|
25
|
+
# as a standalone Ruby module,
|
|
26
|
+
# and as a command-line tool.
|
|
26
27
|
# Sass is bundled with Haml,
|
|
27
28
|
# so if the Haml plugin or RubyGem is installed,
|
|
28
29
|
# Sass will already be installed as a plugin or gem, respectively.
|
|
@@ -32,17 +33,17 @@ $LOAD_PATH << dir unless $LOAD_PATH.include?(dir)
|
|
|
32
33
|
#
|
|
33
34
|
# To enable it as a Rails plugin,
|
|
34
35
|
# then run
|
|
35
|
-
#
|
|
36
|
+
#
|
|
36
37
|
# haml --rails path/to/rails/app
|
|
37
|
-
#
|
|
38
|
+
#
|
|
38
39
|
# To enable Sass in Merb,
|
|
39
40
|
# add
|
|
40
41
|
#
|
|
41
|
-
# dependency "haml"
|
|
42
|
+
# dependency "merb-haml"
|
|
42
43
|
#
|
|
43
44
|
# to config/dependencies.rb.
|
|
44
45
|
#
|
|
45
|
-
# Sass templates in Rails
|
|
46
|
+
# Sass templates in Rails don't quite function in the same way as views,
|
|
46
47
|
# because they don't contain dynamic content,
|
|
47
48
|
# and so only need to be compiled when the template file has been updated.
|
|
48
49
|
# By default (see options, below),
|
|
@@ -50,6 +51,12 @@ $LOAD_PATH << dir unless $LOAD_PATH.include?(dir)
|
|
|
50
51
|
# Then, whenever necessary, they're compiled into corresponding CSS files in public/stylesheets.
|
|
51
52
|
# For instance, public/stylesheets/sass/main.sass would be compiled to public/stylesheets/main.css.
|
|
52
53
|
#
|
|
54
|
+
# To run Sass from the commandline, just use
|
|
55
|
+
#
|
|
56
|
+
# sass input.sass output.css
|
|
57
|
+
#
|
|
58
|
+
# Use <tt>sass --help</tt> for full documentation.
|
|
59
|
+
#
|
|
53
60
|
# Using Sass in Ruby code is very simple.
|
|
54
61
|
# After installing the Haml gem,
|
|
55
62
|
# you can use it by running <tt>require "sass"</tt>
|
|
@@ -128,7 +135,7 @@ $LOAD_PATH << dir unless $LOAD_PATH.include?(dir)
|
|
|
128
135
|
#
|
|
129
136
|
# By default, either attribute syntax may be used.
|
|
130
137
|
# If you want to force one or the other,
|
|
131
|
-
# see the
|
|
138
|
+
# see the <tt>:attribute_syntax</tt> option below.
|
|
132
139
|
#
|
|
133
140
|
# === Nested Rules
|
|
134
141
|
#
|
|
@@ -157,12 +164,12 @@ $LOAD_PATH << dir unless $LOAD_PATH.include?(dir)
|
|
|
157
164
|
#
|
|
158
165
|
# #main
|
|
159
166
|
# :width 97%
|
|
160
|
-
#
|
|
167
|
+
#
|
|
161
168
|
# p, div
|
|
162
169
|
# :font-size 2em
|
|
163
170
|
# a
|
|
164
171
|
# :font-weight bold
|
|
165
|
-
#
|
|
172
|
+
#
|
|
166
173
|
# pre
|
|
167
174
|
# :font-size 3em
|
|
168
175
|
#
|
|
@@ -253,6 +260,22 @@ $LOAD_PATH << dir unless $LOAD_PATH.include?(dir)
|
|
|
253
260
|
# font-size: 30em;
|
|
254
261
|
# font-weight: bold; }
|
|
255
262
|
#
|
|
263
|
+
# === Rule Escaping
|
|
264
|
+
#
|
|
265
|
+
# In case, for whatever reason, you need to write a rule
|
|
266
|
+
# that begins with a Sass-meaningful character,
|
|
267
|
+
# you can escape it with a backslash (<tt>\</tt>).
|
|
268
|
+
# For example:
|
|
269
|
+
#
|
|
270
|
+
# #main
|
|
271
|
+
# \+div
|
|
272
|
+
# clear: both
|
|
273
|
+
#
|
|
274
|
+
# is compiled to:
|
|
275
|
+
#
|
|
276
|
+
# #main +div {
|
|
277
|
+
# clear: both; }
|
|
278
|
+
#
|
|
256
279
|
# == Constants
|
|
257
280
|
#
|
|
258
281
|
# Sass has support for setting document-wide constants.
|
|
@@ -363,6 +386,39 @@ $LOAD_PATH << dir unless $LOAD_PATH.include?(dir)
|
|
|
363
386
|
# #main {
|
|
364
387
|
# content: string(Hello, "Hubert" Bean.) }
|
|
365
388
|
#
|
|
389
|
+
# === Optional Assignment
|
|
390
|
+
#
|
|
391
|
+
# You can assign Sass constants if they aren't already assigned
|
|
392
|
+
# using the ||= assignment operator.
|
|
393
|
+
# This means that if the constant has already been assigned to,
|
|
394
|
+
# it won't be re-assigned,
|
|
395
|
+
# but if it doesn't have a value yet,
|
|
396
|
+
# it will be given one.
|
|
397
|
+
# For example:
|
|
398
|
+
#
|
|
399
|
+
# !content = "First content"
|
|
400
|
+
# !content ||= "Second content?"
|
|
401
|
+
#
|
|
402
|
+
# #main
|
|
403
|
+
# content = content
|
|
404
|
+
#
|
|
405
|
+
# is compiled to:
|
|
406
|
+
#
|
|
407
|
+
# #main {
|
|
408
|
+
# content: First content; }
|
|
409
|
+
#
|
|
410
|
+
# However,
|
|
411
|
+
#
|
|
412
|
+
# !content ||= "Second content?"
|
|
413
|
+
#
|
|
414
|
+
# #main
|
|
415
|
+
# content = content
|
|
416
|
+
#
|
|
417
|
+
# is compiled to:
|
|
418
|
+
#
|
|
419
|
+
# #main {
|
|
420
|
+
# content: Second content?; }
|
|
421
|
+
#
|
|
366
422
|
# === Default Concatenation
|
|
367
423
|
#
|
|
368
424
|
# All those plusses and quotes for concatenating strings
|
|
@@ -453,6 +509,40 @@ $LOAD_PATH << dir unless $LOAD_PATH.include?(dir)
|
|
|
453
509
|
# might compile to either,
|
|
454
510
|
# depending on whether a file called "foo.sass" existed.
|
|
455
511
|
#
|
|
512
|
+
# === @font-face, @media, etc.
|
|
513
|
+
#
|
|
514
|
+
# Sass behaves as you'd expect for normal CSS @-directives.
|
|
515
|
+
# For example:
|
|
516
|
+
#
|
|
517
|
+
# @font-face
|
|
518
|
+
# font-family: "Bitstream Vera Sans"
|
|
519
|
+
# src: url(http://foo.bar/bvs")
|
|
520
|
+
#
|
|
521
|
+
# compiles to:
|
|
522
|
+
#
|
|
523
|
+
# @font-face {
|
|
524
|
+
# font-family: "Bitstream Vera Sans";
|
|
525
|
+
# src: url(http://foo.bar/bvs"); }
|
|
526
|
+
#
|
|
527
|
+
# and
|
|
528
|
+
#
|
|
529
|
+
# @media print
|
|
530
|
+
# #sidebar
|
|
531
|
+
# display: none
|
|
532
|
+
#
|
|
533
|
+
# #main
|
|
534
|
+
# background-color: white
|
|
535
|
+
#
|
|
536
|
+
# compiles to:
|
|
537
|
+
#
|
|
538
|
+
# @media print {
|
|
539
|
+
# #sidebar {
|
|
540
|
+
# display: none; }
|
|
541
|
+
#
|
|
542
|
+
# #main {
|
|
543
|
+
# background-color: white; }
|
|
544
|
+
# }
|
|
545
|
+
#
|
|
456
546
|
# == Comments
|
|
457
547
|
#
|
|
458
548
|
# === Silent Comments
|
|
@@ -528,6 +618,84 @@ $LOAD_PATH << dir unless $LOAD_PATH.include?(dir)
|
|
|
528
618
|
# background-image: url(/images/pbj.png);
|
|
529
619
|
# color: red; }
|
|
530
620
|
#
|
|
621
|
+
# == Mixins
|
|
622
|
+
#
|
|
623
|
+
# Mixins enable you to define groups of CSS attributes and
|
|
624
|
+
# then include them inline in any number of selectors
|
|
625
|
+
# throughout the document.
|
|
626
|
+
#
|
|
627
|
+
# === Defining a Mixin
|
|
628
|
+
#
|
|
629
|
+
# To define a mixin you use a slightly modified form of selector syntax.
|
|
630
|
+
# For example the 'large-text' mixin is defined as follows:
|
|
631
|
+
#
|
|
632
|
+
# =large-text
|
|
633
|
+
# :font
|
|
634
|
+
# :family Arial
|
|
635
|
+
# :size 20px
|
|
636
|
+
# :weight bold
|
|
637
|
+
# :color #ff0000
|
|
638
|
+
#
|
|
639
|
+
# The initial '=' marks this as a mixin rather than a standard selector.
|
|
640
|
+
# The CSS rules that follow won't be included until the mixin is referenced later on.
|
|
641
|
+
# Anything you can put into a standard selector,
|
|
642
|
+
# you can put into a mixin definition. e.g.
|
|
643
|
+
#
|
|
644
|
+
# =clearfix
|
|
645
|
+
# display: inline-block
|
|
646
|
+
# &:after
|
|
647
|
+
# content: "."
|
|
648
|
+
# display: block
|
|
649
|
+
# height: 0
|
|
650
|
+
# clear: both
|
|
651
|
+
# visibility: hidden
|
|
652
|
+
# * html &
|
|
653
|
+
# height: 1px
|
|
654
|
+
#
|
|
655
|
+
#
|
|
656
|
+
# === Mixing it in
|
|
657
|
+
#
|
|
658
|
+
# Inlining a defined mixin is simple,
|
|
659
|
+
# just prepend a '+' symbol to the name of a mixin defined earlier in the document.
|
|
660
|
+
# So to inline the 'large-text' defined earlier,
|
|
661
|
+
# we include the statment '+large-text' in our selector definition thus:
|
|
662
|
+
#
|
|
663
|
+
# .page-title
|
|
664
|
+
# +large-text
|
|
665
|
+
# :padding 4px
|
|
666
|
+
# :margin
|
|
667
|
+
# :top 10px
|
|
668
|
+
#
|
|
669
|
+
#
|
|
670
|
+
# This will produce the following CSS output:
|
|
671
|
+
#
|
|
672
|
+
# .page-title {
|
|
673
|
+
# font-family: Arial;
|
|
674
|
+
# font-size: 20px;
|
|
675
|
+
# font-weight: bold;
|
|
676
|
+
# color: #ff0000;
|
|
677
|
+
# padding: 4px;
|
|
678
|
+
# margin-top: 10px;
|
|
679
|
+
# }
|
|
680
|
+
#
|
|
681
|
+
# Any number of mixins may be defined and there is no limit on
|
|
682
|
+
# the number that can be included in a particular selector.
|
|
683
|
+
#
|
|
684
|
+
# Mixin definitions can also include references to other mixins defined earlier in the file.
|
|
685
|
+
# E.g.
|
|
686
|
+
#
|
|
687
|
+
# =highlighted-background
|
|
688
|
+
# background:
|
|
689
|
+
# color: #fc0
|
|
690
|
+
# =header-text
|
|
691
|
+
# font:
|
|
692
|
+
# size: 20px
|
|
693
|
+
#
|
|
694
|
+
# =compound
|
|
695
|
+
# +highlighted-background
|
|
696
|
+
# +header-text
|
|
697
|
+
#
|
|
698
|
+
#
|
|
531
699
|
# == Output Style
|
|
532
700
|
#
|
|
533
701
|
# Although the default CSS style that Sass outputs is very nice,
|
|
@@ -601,7 +769,7 @@ $LOAD_PATH << dir unless $LOAD_PATH.include?(dir)
|
|
|
601
769
|
# #main { color: #fff; background-color: #000; }
|
|
602
770
|
# #main p { width: 10em; }
|
|
603
771
|
#
|
|
604
|
-
# .huge { font-size: 10em; font-weight: bold; text-decoration: underline; }
|
|
772
|
+
# .huge { font-size: 10em; font-weight: bold; text-decoration: underline; }
|
|
605
773
|
#
|
|
606
774
|
# === <tt>:compressed</tt>
|
|
607
775
|
#
|
|
@@ -611,13 +779,20 @@ $LOAD_PATH << dir unless $LOAD_PATH.include?(dir)
|
|
|
611
779
|
# It's not meant to be human-readable.
|
|
612
780
|
# For example:
|
|
613
781
|
#
|
|
614
|
-
# #main{color:#fff;background-color:#000}#main p{width:10em}.huge{font-size:10em;font-weight:bold;text-decoration:underline}
|
|
782
|
+
# #main{color:#fff;background-color:#000}#main p{width:10em}.huge{font-size:10em;font-weight:bold;text-decoration:underline}
|
|
615
783
|
#
|
|
616
784
|
# == Sass Options
|
|
617
785
|
#
|
|
618
|
-
# Options can be set by setting the
|
|
619
|
-
#
|
|
620
|
-
#
|
|
786
|
+
# Options can be set by setting the <tt>Sass::Plugin.options</tt> hash
|
|
787
|
+
# in <tt>environment.rb</tt> in Rails...
|
|
788
|
+
#
|
|
789
|
+
# Sass::Plugin.options[:style] = :compact
|
|
790
|
+
#
|
|
791
|
+
# ...or by setting the <tt>Merb::Config[:sass]</tt> hash in <tt>init.rb</tt> in Merb...
|
|
792
|
+
#
|
|
793
|
+
# Merb::Config[:sass][:style] = :compact
|
|
794
|
+
#
|
|
795
|
+
# ...or by passing an options hash to Sass::Engine.new.
|
|
621
796
|
# Available options are:
|
|
622
797
|
#
|
|
623
798
|
# [<tt>:style</tt>] Sets the style of the CSS output.
|
|
@@ -634,7 +809,7 @@ $LOAD_PATH << dir unless $LOAD_PATH.include?(dir)
|
|
|
634
809
|
# For example: <tt>color: #0f3</tt>
|
|
635
810
|
# or <tt>width = !main_width</tt>.
|
|
636
811
|
# By default, either syntax is valid.
|
|
637
|
-
#
|
|
812
|
+
#
|
|
638
813
|
# [<tt>:never_update</tt>] Whether the CSS files should never be updated,
|
|
639
814
|
# even if the template file changes.
|
|
640
815
|
# Setting this to true may give small performance gains.
|
|
@@ -646,7 +821,7 @@ $LOAD_PATH << dir unless $LOAD_PATH.include?(dir)
|
|
|
646
821
|
# as opposed to only when the template has been modified.
|
|
647
822
|
# Defaults to false.
|
|
648
823
|
# Only has meaning within Ruby on Rails or Merb.
|
|
649
|
-
#
|
|
824
|
+
#
|
|
650
825
|
# [<tt>:always_check</tt>] Whether a Sass template should be checked for updates every
|
|
651
826
|
# time a controller is accessed,
|
|
652
827
|
# as opposed to only when the Rails server starts.
|
|
@@ -681,7 +856,7 @@ $LOAD_PATH << dir unless $LOAD_PATH.include?(dir)
|
|
|
681
856
|
# for Sass templates imported with the "@import" directive.
|
|
682
857
|
# This defaults to the working directory and, in Rails or Merb,
|
|
683
858
|
# whatever <tt>:template_location</tt> is.
|
|
684
|
-
#
|
|
859
|
+
#
|
|
685
860
|
module Sass; end
|
|
686
861
|
|
|
687
862
|
require 'sass/engine'
|
data/rails/init.rb
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
Kernel.load File.join(File.dirname(__FILE__), '..', 'init.rb')
|
data/test/benchmark.rb
CHANGED
|
@@ -1,95 +1,82 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
1
|
+
#!/usr/bin/env ruby
|
|
2
|
+
|
|
3
|
+
times = (ARGV.first || 1000).to_i
|
|
4
|
+
|
|
5
|
+
if times == 0 # Invalid parameter
|
|
6
|
+
puts <<END
|
|
7
|
+
ruby #$0 [times=1000]
|
|
8
|
+
Benchmark Haml against various other templating languages and Sass
|
|
9
|
+
on its own.
|
|
10
|
+
END
|
|
11
|
+
exit 1
|
|
12
|
+
end
|
|
13
|
+
|
|
14
|
+
require File.dirname(__FILE__) + '/../lib/haml'
|
|
15
|
+
%w[sass rubygems erb erubis markaby active_support action_controller
|
|
16
|
+
action_view haml/template].each(&method(:require))
|
|
17
|
+
|
|
18
|
+
begin
|
|
19
|
+
require 'benchwarmer'
|
|
20
|
+
rescue LoadError
|
|
21
|
+
# Since it's not as simple as gem install at the time of writing,
|
|
22
|
+
# we need to direct folks to the benchwarmer gem.
|
|
23
|
+
raise "The Haml benchmarks require the benchwarmer gem, available from http://github.com/wycats/benchwarmer"
|
|
8
24
|
end
|
|
9
25
|
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
require 'markaby'
|
|
14
|
-
require 'benchmark'
|
|
15
|
-
require 'stringio'
|
|
16
|
-
require 'open-uri'
|
|
17
|
-
|
|
18
|
-
module Haml
|
|
19
|
-
# Benchmarks Haml against ERB, Erubis, and Markaby and Sass on its own.
|
|
20
|
-
def self.benchmark(runs = 100)
|
|
21
|
-
template_name = 'standard'
|
|
22
|
-
directory = File.dirname(__FILE__) + '/haml'
|
|
23
|
-
haml_template = File.read("#{directory}/templates/#{template_name}.haml")
|
|
24
|
-
erb_template = File.read("#{directory}/rhtml/#{template_name}.rhtml")
|
|
25
|
-
markaby_template = File.read("#{directory}/markaby/#{template_name}.mab")
|
|
26
|
-
|
|
27
|
-
puts '-'*51, "Haml and Friends: No Caching", '-'*51
|
|
28
|
-
|
|
29
|
-
times = Benchmark.bmbm do |b|
|
|
30
|
-
b.report("haml:") { runs.times { Haml::Engine.new(haml_template).render } }
|
|
31
|
-
b.report("erb:") { runs.times { ERB.new(erb_template, nil, '-').render } }
|
|
32
|
-
b.report("erubis:") { runs.times { Erubis::Eruby.new(erb_template).result } }
|
|
33
|
-
b.report("mab:") { runs.times { Markaby::Template.new(markaby_template).render } }
|
|
34
|
-
end
|
|
35
|
-
|
|
36
|
-
print_result = proc do |s, n|
|
|
37
|
-
printf "%1$*2$s %3$*4$g",
|
|
38
|
-
"Haml/#{s}:", -13, times[0].to_a[5] / times[n].to_a[5], -17
|
|
39
|
-
printf "%1$*2$s %3$g\n",
|
|
40
|
-
"#{s}/Haml:", -13, times[n].to_a[5] / times[0].to_a[5]
|
|
41
|
-
end
|
|
42
|
-
|
|
43
|
-
print_result["ERB", 1]
|
|
44
|
-
print_result["Erubis", 2]
|
|
45
|
-
print_result["Markaby", 3]
|
|
46
|
-
|
|
47
|
-
puts '', '-' * 50, 'Haml and Friends: Cached', '-' * 50
|
|
26
|
+
Benchmark.warmer(times) do
|
|
27
|
+
columns :haml, :erb, :erubis, :mab
|
|
28
|
+
titles :haml => "Haml", :erb => "ERB", :erubis => "Erubis", :mab => "Markaby"
|
|
48
29
|
|
|
30
|
+
template_name = 'standard'
|
|
31
|
+
directory = File.dirname(__FILE__) + '/haml'
|
|
32
|
+
haml_template = File.read("#{directory}/templates/#{template_name}.haml")
|
|
33
|
+
erb_template = File.read("#{directory}/rhtml/#{template_name}.rhtml")
|
|
34
|
+
markaby_template = File.read("#{directory}/markaby/#{template_name}.mab")
|
|
35
|
+
|
|
36
|
+
report "Uncached" do
|
|
37
|
+
haml { Haml::Engine.new(haml_template).render }
|
|
38
|
+
erb { ERB.new(erb_template, nil, '-').result }
|
|
39
|
+
erubis { Erubis::Eruby.new(erb_template).result }
|
|
40
|
+
mab { Markaby::Template.new(markaby_template).render }
|
|
41
|
+
end
|
|
42
|
+
|
|
43
|
+
report "Cached" do
|
|
49
44
|
obj = Object.new
|
|
45
|
+
|
|
50
46
|
Haml::Engine.new(haml_template).def_method(obj, :haml)
|
|
51
|
-
erb = ERB.new(erb_template, nil, '-')
|
|
52
|
-
obj.instance_eval("def erb; #{erb.src}; end")
|
|
53
47
|
Erubis::Eruby.new(erb_template).def_method(obj, :erubis)
|
|
54
|
-
|
|
55
|
-
b.report("haml:") { runs.times { obj.haml } }
|
|
56
|
-
b.report("erb:") { runs.times { obj.erb } }
|
|
57
|
-
b.report("erubis:") { runs.times { obj.erubis } }
|
|
58
|
-
end
|
|
48
|
+
obj.instance_eval("def erb; #{ERB.new(erb_template, nil, '-').src}; end")
|
|
59
49
|
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
require 'active_support'
|
|
66
|
-
require 'action_controller'
|
|
67
|
-
require 'action_view'
|
|
68
|
-
require 'haml/template'
|
|
50
|
+
haml { obj.haml }
|
|
51
|
+
erb { obj.erb }
|
|
52
|
+
erubis { obj.erubis }
|
|
53
|
+
end
|
|
69
54
|
|
|
55
|
+
report "ActionView" do
|
|
70
56
|
@base = ActionView::Base.new(File.dirname(__FILE__))
|
|
71
|
-
times = Benchmark.bmbm do |b|
|
|
72
|
-
b.report("haml:") { runs.times { @base.render 'haml/templates/standard' } }
|
|
73
|
-
b.report("erb:") { runs.times { @base.render 'haml/rhtml/standard' } }
|
|
74
|
-
end
|
|
75
57
|
|
|
76
|
-
|
|
58
|
+
# To cache the template
|
|
59
|
+
@base.render 'haml/templates/standard'
|
|
60
|
+
@base.render 'haml/rhtml/standard'
|
|
77
61
|
|
|
78
|
-
|
|
62
|
+
haml { @base.render 'haml/templates/standard' }
|
|
63
|
+
erb { @base.render 'haml/rhtml/standard' }
|
|
64
|
+
end
|
|
79
65
|
|
|
66
|
+
report "ActionView with deep partials" do
|
|
80
67
|
@base = ActionView::Base.new(File.dirname(__FILE__))
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
puts '', '-' * 50, 'Sass', '-' * 50
|
|
89
|
-
sass_template = File.read("#{File.dirname(__FILE__)}/sass/templates/complex.sass")
|
|
90
|
-
|
|
91
|
-
Benchmark.bmbm do |b|
|
|
92
|
-
b.report("sass:") { runs.times { Sass::Engine.new(sass_template).render } }
|
|
93
|
-
end
|
|
68
|
+
|
|
69
|
+
# To cache the template
|
|
70
|
+
@base.render 'haml/templates/action_view'
|
|
71
|
+
@base.render 'haml/rhtml/action_view'
|
|
72
|
+
|
|
73
|
+
haml { @base.render 'haml/templates/action_view' }
|
|
74
|
+
erb { @base.render 'haml/rhtml/action_view' }
|
|
94
75
|
end
|
|
95
76
|
end
|
|
77
|
+
|
|
78
|
+
Benchmark.warmer(times) do
|
|
79
|
+
sass_template = File.read("#{File.dirname(__FILE__)}/sass/templates/complex.sass")
|
|
80
|
+
|
|
81
|
+
report("Sass") { Sass::Engine.new(sass_template).render }
|
|
82
|
+
end
|