erbse 0.0.1 → 0.0.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGES.md +3 -0
- data/Gemfile +3 -0
- data/README.md +40 -22
- data/Rakefile +13 -0
- data/lib/erbse.rb +3 -6
- data/lib/erbse/converter.rb +41 -241
- data/lib/erbse/eruby.rb +114 -0
- data/lib/erbse/template.rb +14 -0
- data/lib/erbse/version.rb +1 -1
- data/test/erbse_test.rb +14 -0
- data/test/test_helper.rb +2 -0
- metadata +9 -149
- data/CHANGES.txt +0 -828
- data/bin/erubis +0 -10
- data/lib/erbse/context.rb +0 -83
- data/lib/erbse/engine.rb +0 -114
- data/lib/erbse/engine/ec.rb +0 -117
- data/lib/erbse/engine/ecpp.rb +0 -113
- data/lib/erbse/engine/ejava.rb +0 -110
- data/lib/erbse/engine/ejavascript.rb +0 -119
- data/lib/erbse/engine/enhanced.rb +0 -126
- data/lib/erbse/engine/eperl.rb +0 -95
- data/lib/erbse/engine/ephp.rb +0 -99
- data/lib/erbse/engine/eruby.rb +0 -119
- data/lib/erbse/engine/escheme.rb +0 -114
- data/lib/erbse/engine/optimized.rb +0 -127
- data/lib/erbse/enhancer.rb +0 -723
- data/lib/erbse/error.rb +0 -23
- data/lib/erbse/evaluator.rb +0 -88
- data/lib/erbse/generator.rb +0 -85
- data/lib/erbse/helper.rb +0 -47
- data/lib/erbse/helpers/rails_form_helper.rb +0 -197
- data/lib/erbse/helpers/rails_helper.rb +0 -353
- data/lib/erbse/main.rb +0 -516
- data/lib/erbse/preprocessing.rb +0 -58
- data/lib/erbse/tiny.rb +0 -144
- data/lib/erbse/util.rb +0 -22
- data/test/assert-text-equal.rb +0 -44
- data/test/data/users-guide/Example.ejava +0 -55
- data/test/data/users-guide/array_example.result +0 -9
- data/test/data/users-guide/arraybuffer_example.result +0 -9
- data/test/data/users-guide/bipattern-example.rhtml +0 -4
- data/test/data/users-guide/bipattern_example.result +0 -6
- data/test/data/users-guide/bufvar-example.rb +0 -10
- data/test/data/users-guide/bufvar-example.result +0 -17
- data/test/data/users-guide/context.rb +0 -6
- data/test/data/users-guide/context.yaml +0 -8
- data/test/data/users-guide/def_method.rb +0 -14
- data/test/data/users-guide/def_method.result +0 -3
- data/test/data/users-guide/escape_example.result +0 -9
- data/test/data/users-guide/example.ec +0 -27
- data/test/data/users-guide/example.ecpp +0 -30
- data/test/data/users-guide/example.ejs +0 -20
- data/test/data/users-guide/example.eperl +0 -18
- data/test/data/users-guide/example.ephp +0 -18
- data/test/data/users-guide/example.eruby +0 -6
- data/test/data/users-guide/example.escheme +0 -28
- data/test/data/users-guide/example1.eruby +0 -6
- data/test/data/users-guide/example1.rb +0 -17
- data/test/data/users-guide/example1.result +0 -16
- data/test/data/users-guide/example10.rb +0 -4
- data/test/data/users-guide/example10.result +0 -17
- data/test/data/users-guide/example10.xhtml +0 -14
- data/test/data/users-guide/example10_x.result +0 -17
- data/test/data/users-guide/example11.php +0 -20
- data/test/data/users-guide/example11.result +0 -23
- data/test/data/users-guide/example11.rhtml +0 -21
- data/test/data/users-guide/example11_C.result +0 -10
- data/test/data/users-guide/example11_N.result +0 -16
- data/test/data/users-guide/example11_U.result +0 -16
- data/test/data/users-guide/example11_php.result +0 -15
- data/test/data/users-guide/example1_x.result +0 -9
- data/test/data/users-guide/example2.eruby +0 -7
- data/test/data/users-guide/example2.rb +0 -10
- data/test/data/users-guide/example2.result +0 -27
- data/test/data/users-guide/example2_trim.result +0 -10
- data/test/data/users-guide/example2_x.result +0 -10
- data/test/data/users-guide/example3.eruby +0 -6
- data/test/data/users-guide/example3.rb +0 -10
- data/test/data/users-guide/example31.result +0 -22
- data/test/data/users-guide/example32.result +0 -4
- data/test/data/users-guide/example3_e.result +0 -8
- data/test/data/users-guide/example4.eruby +0 -3
- data/test/data/users-guide/example4.rb +0 -11
- data/test/data/users-guide/example4.result +0 -10
- data/test/data/users-guide/example4_x.result +0 -5
- data/test/data/users-guide/example5.eruby +0 -6
- data/test/data/users-guide/example5.rb +0 -16
- data/test/data/users-guide/example5.result +0 -7
- data/test/data/users-guide/example6.rb +0 -12
- data/test/data/users-guide/example6.result +0 -7
- data/test/data/users-guide/example7.eruby +0 -8
- data/test/data/users-guide/example71.result +0 -13
- data/test/data/users-guide/example72.result +0 -13
- data/test/data/users-guide/example8.eruby +0 -6
- data/test/data/users-guide/example8_ruby.result +0 -7
- data/test/data/users-guide/example8_yaml.result +0 -7
- data/test/data/users-guide/example9.eruby +0 -3
- data/test/data/users-guide/example9.rb +0 -8
- data/test/data/users-guide/example9.result +0 -9
- data/test/data/users-guide/example91.result +0 -5
- data/test/data/users-guide/example92.result +0 -4
- data/test/data/users-guide/example_c.result +0 -32
- data/test/data/users-guide/example_java.result +0 -56
- data/test/data/users-guide/example_js.result +0 -22
- data/test/data/users-guide/example_perl.result +0 -20
- data/test/data/users-guide/example_php.result +0 -19
- data/test/data/users-guide/example_scheme.result +0 -30
- data/test/data/users-guide/example_scheme_display.result +0 -29
- data/test/data/users-guide/fasteruby-example.rb +0 -8
- data/test/data/users-guide/fasteruby-example.result +0 -18
- data/test/data/users-guide/fasteruby.rb +0 -11
- data/test/data/users-guide/fasteruby.result +0 -38
- data/test/data/users-guide/fasteruby.rhtml +0 -15
- data/test/data/users-guide/headerfooter-example.eruby +0 -9
- data/test/data/users-guide/headerfooter-example2.rb +0 -8
- data/test/data/users-guide/headerfooter-example2.rhtml +0 -10
- data/test/data/users-guide/headerfooter_example.result +0 -11
- data/test/data/users-guide/headerfooter_example2.result +0 -13
- data/test/data/users-guide/interpolation_example.result +0 -9
- data/test/data/users-guide/main_program1.rb +0 -8
- data/test/data/users-guide/main_program1.result +0 -6
- data/test/data/users-guide/main_program2.rb +0 -8
- data/test/data/users-guide/main_program2.result +0 -6
- data/test/data/users-guide/nocode-example.eruby +0 -14
- data/test/data/users-guide/nocode-php.result +0 -20
- data/test/data/users-guide/nocode_example.result +0 -15
- data/test/data/users-guide/normal-eruby-test.eruby +0 -9
- data/test/data/users-guide/normal_eruby_test.result +0 -11
- data/test/data/users-guide/notext-example.eruby +0 -14
- data/test/data/users-guide/notext-example.php +0 -19
- data/test/data/users-guide/notext-php.result +0 -20
- data/test/data/users-guide/notext_example.result +0 -16
- data/test/data/users-guide/percentline-example.rhtml +0 -6
- data/test/data/users-guide/percentline_example.result +0 -9
- data/test/data/users-guide/prefixedline-example.rb +0 -9
- data/test/data/users-guide/prefixedline-example.rhtml +0 -6
- data/test/data/users-guide/prefixedline_example.result +0 -9
- data/test/data/users-guide/printenable_example.result +0 -4
- data/test/data/users-guide/printenabled-example.eruby +0 -3
- data/test/data/users-guide/printenabled-example.rb +0 -8
- data/test/data/users-guide/printstatement_example.result +0 -8
- data/test/data/users-guide/simplify_example.result +0 -9
- data/test/data/users-guide/stderr.log +0 -3
- data/test/data/users-guide/stdout_exmple.result +0 -9
- data/test/data/users-guide/stringbuffer_example.result +0 -9
- data/test/data/users-guide/tail_260.result +0 -4
- data/test/data/users-guide/tailnewline.rhtml +0 -3
- data/test/data/users-guide/template1.rhtml +0 -4
- data/test/data/users-guide/template2.rhtml +0 -4
- data/test/test-engines.rb +0 -425
- data/test/test-enhancers.rb +0 -646
- data/test/test-erubis.rb +0 -887
- data/test/test-index-cgi.rb +0 -191
- data/test/test-main.rb +0 -752
- data/test/test-users-guide.rb +0 -73
- data/test/test.rb +0 -45
- data/test/testutil.rb +0 -111
data/lib/erbse/eruby.rb
ADDED
@@ -0,0 +1,114 @@
|
|
1
|
+
module Erbse
|
2
|
+
class RubyGenerator
|
3
|
+
def init_generator(properties={})
|
4
|
+
@escapefunc ||= "Erubis::XmlHelper.escape_xml"
|
5
|
+
end
|
6
|
+
|
7
|
+
def escape_text(text)
|
8
|
+
text.gsub(/['\\]/, '\\\\\&') # "'" => "\\'", '\\' => '\\\\'
|
9
|
+
end
|
10
|
+
|
11
|
+
def escaped_expr(code)
|
12
|
+
return "#{@escapefunc}(#{code})"
|
13
|
+
end
|
14
|
+
|
15
|
+
#--
|
16
|
+
#def add_preamble(src)
|
17
|
+
# src << "#{@bufvar} = [];"
|
18
|
+
#end
|
19
|
+
#++
|
20
|
+
def add_preamble(src)
|
21
|
+
@newline_pending = 0
|
22
|
+
src << "@output_buffer = output_buffer;" # DISCUSS: i removed the output_buffer || ActionView::OB.new rubbish here.
|
23
|
+
end
|
24
|
+
|
25
|
+
# def add_text(src, text)
|
26
|
+
# src << " #{@bufvar} << '" << escape_text(text) << "';" unless text.empty?
|
27
|
+
# end
|
28
|
+
def add_text(src, text)
|
29
|
+
return if text.empty?
|
30
|
+
|
31
|
+
if text == "\n"
|
32
|
+
@newline_pending += 1
|
33
|
+
else
|
34
|
+
src << "@output_buffer.safe_append='"
|
35
|
+
src << "\n" * @newline_pending if @newline_pending > 0
|
36
|
+
src << escape_text(text)
|
37
|
+
src << "'.freeze;"
|
38
|
+
|
39
|
+
@newline_pending = 0
|
40
|
+
end
|
41
|
+
end
|
42
|
+
|
43
|
+
# Erubis toggles <%= and <%== behavior when escaping is enabled.
|
44
|
+
# We override to always treat <%== as escaped.
|
45
|
+
# def add_expr(src, code, indicator)
|
46
|
+
# case indicator
|
47
|
+
# when '=='
|
48
|
+
# add_expr_escaped(src, code)
|
49
|
+
# else
|
50
|
+
# super
|
51
|
+
# end
|
52
|
+
# end
|
53
|
+
|
54
|
+
def ____add_stmt(src, code)
|
55
|
+
src << code
|
56
|
+
src << ';' unless code[-1] == ?\n
|
57
|
+
end
|
58
|
+
|
59
|
+
def add_stmt(src, code)
|
60
|
+
flush_newline_if_pending(src)
|
61
|
+
____add_stmt(src, code)
|
62
|
+
end
|
63
|
+
|
64
|
+
# def add_expr_literal(src, code)
|
65
|
+
# src << " #{@bufvar} << (" << code << ').to_s;'
|
66
|
+
# end
|
67
|
+
BLOCK_EXPR = /\s*((\s+|\))do|\{)(\s*\|[^|]*\|)?\s*\Z/
|
68
|
+
|
69
|
+
def add_expr_literal(src, code)
|
70
|
+
flush_newline_if_pending(src)
|
71
|
+
if code =~ BLOCK_EXPR
|
72
|
+
src << '@output_buffer.append= ' << code
|
73
|
+
else
|
74
|
+
src << '@output_buffer.append=(' << code << ');'
|
75
|
+
end
|
76
|
+
end
|
77
|
+
|
78
|
+
def add_expr_escaped(src, code)
|
79
|
+
flush_newline_if_pending(src)
|
80
|
+
if code =~ BLOCK_EXPR
|
81
|
+
src << "@output_buffer.safe_expr_append= " << code
|
82
|
+
else
|
83
|
+
src << "@output_buffer.safe_expr_append=(" << code << ");"
|
84
|
+
end
|
85
|
+
end
|
86
|
+
|
87
|
+
# def add_expr_escaped(src, code)
|
88
|
+
# src << " #{@bufvar} << " << escaped_expr(code) << ';'
|
89
|
+
# end
|
90
|
+
|
91
|
+
def add_expr_debug(src, code)
|
92
|
+
code.strip!
|
93
|
+
s = (code.dump =~ /\A"(.*)"\z/) && $1
|
94
|
+
src << ' $stderr.puts("*** debug: ' << s << '=#{(' << code << ').inspect}");'
|
95
|
+
end
|
96
|
+
|
97
|
+
#--
|
98
|
+
#def add_postamble(src)
|
99
|
+
# src << "\n#{@bufvar}.join\n"
|
100
|
+
#end
|
101
|
+
#++
|
102
|
+
def add_postamble(src)
|
103
|
+
flush_newline_if_pending(src)
|
104
|
+
src << '@output_buffer.to_s'
|
105
|
+
end
|
106
|
+
|
107
|
+
def flush_newline_if_pending(src)
|
108
|
+
if @newline_pending > 0
|
109
|
+
src << "@output_buffer.safe_append='#{"\n" * @newline_pending}'.freeze;"
|
110
|
+
@newline_pending = 0
|
111
|
+
end
|
112
|
+
end
|
113
|
+
end
|
114
|
+
end
|
@@ -0,0 +1,14 @@
|
|
1
|
+
module Erbse
|
2
|
+
# Compiles the runtime method for an ERB input string.
|
3
|
+
class Template
|
4
|
+
def initialize(input, properties={})
|
5
|
+
generator = RubyGenerator.new
|
6
|
+
converter = Basic::Converter.new(properties, generator)
|
7
|
+
@src = converter.convert(input)
|
8
|
+
end
|
9
|
+
|
10
|
+
def call
|
11
|
+
@src
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
data/lib/erbse/version.rb
CHANGED
data/test/erbse_test.rb
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
require "test_helper"
|
2
|
+
|
3
|
+
# most tests are via cells-erb.
|
4
|
+
|
5
|
+
class ErbseTest < MiniTest::Spec
|
6
|
+
it do
|
7
|
+
Erbse::Template.new(%{<%- text = "Hello" %> <%= text %>}).call.must_equal "@output_buffer = output_buffer; text = \"Hello\" ;@output_buffer.safe_append=' '.freeze;@output_buffer.append=( text );@output_buffer.to_s"
|
8
|
+
end
|
9
|
+
|
10
|
+
# nested <%= block do %> syntax.
|
11
|
+
it do
|
12
|
+
Erbse::Template.new(%{<%= form_for do %><%= content_tag :div do %>DIV<% end %><% end %>}).call.must_equal "@output_buffer = output_buffer;@output_buffer.append= form_for do @output_buffer.append= content_tag :div do @output_buffer.safe_append='DIV'.freeze; end ; end ;@output_buffer.to_s"
|
13
|
+
end
|
14
|
+
end
|
data/test/test_helper.rb
ADDED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: erbse
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Nick Sutterer
|
@@ -41,14 +41,15 @@ dependencies:
|
|
41
41
|
description: An updated Erubis with block support. Block inheritance soon to come.
|
42
42
|
email:
|
43
43
|
- apotonick@gmail.com
|
44
|
-
executables:
|
45
|
-
- erubis
|
44
|
+
executables: []
|
46
45
|
extensions: []
|
47
46
|
extra_rdoc_files: []
|
48
47
|
files:
|
49
|
-
- CHANGES.
|
48
|
+
- CHANGES.md
|
49
|
+
- Gemfile
|
50
50
|
- MIT-LICENSE
|
51
51
|
- README.md
|
52
|
+
- Rakefile
|
52
53
|
- benchmark/Makefile
|
53
54
|
- benchmark/bench.rb
|
54
55
|
- benchmark/bench_context.yaml
|
@@ -57,155 +58,14 @@ files:
|
|
57
58
|
- benchmark/templates/bench_erb.rhtml
|
58
59
|
- benchmark/templates/bench_erubis.rhtml
|
59
60
|
- benchmark/templates/bench_eruby.rhtml
|
60
|
-
- bin/erubis
|
61
61
|
- erbse.gemspec
|
62
62
|
- lib/erbse.rb
|
63
|
-
- lib/erbse/context.rb
|
64
63
|
- lib/erbse/converter.rb
|
65
|
-
- lib/erbse/
|
66
|
-
- lib/erbse/
|
67
|
-
- lib/erbse/engine/ecpp.rb
|
68
|
-
- lib/erbse/engine/ejava.rb
|
69
|
-
- lib/erbse/engine/ejavascript.rb
|
70
|
-
- lib/erbse/engine/enhanced.rb
|
71
|
-
- lib/erbse/engine/eperl.rb
|
72
|
-
- lib/erbse/engine/ephp.rb
|
73
|
-
- lib/erbse/engine/eruby.rb
|
74
|
-
- lib/erbse/engine/escheme.rb
|
75
|
-
- lib/erbse/engine/optimized.rb
|
76
|
-
- lib/erbse/enhancer.rb
|
77
|
-
- lib/erbse/error.rb
|
78
|
-
- lib/erbse/evaluator.rb
|
79
|
-
- lib/erbse/generator.rb
|
80
|
-
- lib/erbse/helper.rb
|
81
|
-
- lib/erbse/helpers/rails_form_helper.rb
|
82
|
-
- lib/erbse/helpers/rails_helper.rb
|
83
|
-
- lib/erbse/main.rb
|
84
|
-
- lib/erbse/preprocessing.rb
|
85
|
-
- lib/erbse/tiny.rb
|
86
|
-
- lib/erbse/util.rb
|
64
|
+
- lib/erbse/eruby.rb
|
65
|
+
- lib/erbse/template.rb
|
87
66
|
- lib/erbse/version.rb
|
88
|
-
- test/
|
89
|
-
- test/
|
90
|
-
- test/data/users-guide/array_example.result
|
91
|
-
- test/data/users-guide/arraybuffer_example.result
|
92
|
-
- test/data/users-guide/bipattern-example.rhtml
|
93
|
-
- test/data/users-guide/bipattern_example.result
|
94
|
-
- test/data/users-guide/bufvar-example.rb
|
95
|
-
- test/data/users-guide/bufvar-example.result
|
96
|
-
- test/data/users-guide/context.rb
|
97
|
-
- test/data/users-guide/context.yaml
|
98
|
-
- test/data/users-guide/def_method.rb
|
99
|
-
- test/data/users-guide/def_method.result
|
100
|
-
- test/data/users-guide/escape_example.result
|
101
|
-
- test/data/users-guide/example.ec
|
102
|
-
- test/data/users-guide/example.ecpp
|
103
|
-
- test/data/users-guide/example.ejs
|
104
|
-
- test/data/users-guide/example.eperl
|
105
|
-
- test/data/users-guide/example.ephp
|
106
|
-
- test/data/users-guide/example.eruby
|
107
|
-
- test/data/users-guide/example.escheme
|
108
|
-
- test/data/users-guide/example1.eruby
|
109
|
-
- test/data/users-guide/example1.rb
|
110
|
-
- test/data/users-guide/example1.result
|
111
|
-
- test/data/users-guide/example10.rb
|
112
|
-
- test/data/users-guide/example10.result
|
113
|
-
- test/data/users-guide/example10.xhtml
|
114
|
-
- test/data/users-guide/example10_x.result
|
115
|
-
- test/data/users-guide/example11.php
|
116
|
-
- test/data/users-guide/example11.result
|
117
|
-
- test/data/users-guide/example11.rhtml
|
118
|
-
- test/data/users-guide/example11_C.result
|
119
|
-
- test/data/users-guide/example11_N.result
|
120
|
-
- test/data/users-guide/example11_U.result
|
121
|
-
- test/data/users-guide/example11_php.result
|
122
|
-
- test/data/users-guide/example1_x.result
|
123
|
-
- test/data/users-guide/example2.eruby
|
124
|
-
- test/data/users-guide/example2.rb
|
125
|
-
- test/data/users-guide/example2.result
|
126
|
-
- test/data/users-guide/example2_trim.result
|
127
|
-
- test/data/users-guide/example2_x.result
|
128
|
-
- test/data/users-guide/example3.eruby
|
129
|
-
- test/data/users-guide/example3.rb
|
130
|
-
- test/data/users-guide/example31.result
|
131
|
-
- test/data/users-guide/example32.result
|
132
|
-
- test/data/users-guide/example3_e.result
|
133
|
-
- test/data/users-guide/example4.eruby
|
134
|
-
- test/data/users-guide/example4.rb
|
135
|
-
- test/data/users-guide/example4.result
|
136
|
-
- test/data/users-guide/example4_x.result
|
137
|
-
- test/data/users-guide/example5.eruby
|
138
|
-
- test/data/users-guide/example5.rb
|
139
|
-
- test/data/users-guide/example5.result
|
140
|
-
- test/data/users-guide/example6.rb
|
141
|
-
- test/data/users-guide/example6.result
|
142
|
-
- test/data/users-guide/example7.eruby
|
143
|
-
- test/data/users-guide/example71.result
|
144
|
-
- test/data/users-guide/example72.result
|
145
|
-
- test/data/users-guide/example8.eruby
|
146
|
-
- test/data/users-guide/example8_ruby.result
|
147
|
-
- test/data/users-guide/example8_yaml.result
|
148
|
-
- test/data/users-guide/example9.eruby
|
149
|
-
- test/data/users-guide/example9.rb
|
150
|
-
- test/data/users-guide/example9.result
|
151
|
-
- test/data/users-guide/example91.result
|
152
|
-
- test/data/users-guide/example92.result
|
153
|
-
- test/data/users-guide/example_c.result
|
154
|
-
- test/data/users-guide/example_java.result
|
155
|
-
- test/data/users-guide/example_js.result
|
156
|
-
- test/data/users-guide/example_perl.result
|
157
|
-
- test/data/users-guide/example_php.result
|
158
|
-
- test/data/users-guide/example_scheme.result
|
159
|
-
- test/data/users-guide/example_scheme_display.result
|
160
|
-
- test/data/users-guide/fasteruby-example.rb
|
161
|
-
- test/data/users-guide/fasteruby-example.result
|
162
|
-
- test/data/users-guide/fasteruby.rb
|
163
|
-
- test/data/users-guide/fasteruby.result
|
164
|
-
- test/data/users-guide/fasteruby.rhtml
|
165
|
-
- test/data/users-guide/headerfooter-example.eruby
|
166
|
-
- test/data/users-guide/headerfooter-example2.rb
|
167
|
-
- test/data/users-guide/headerfooter-example2.rhtml
|
168
|
-
- test/data/users-guide/headerfooter_example.result
|
169
|
-
- test/data/users-guide/headerfooter_example2.result
|
170
|
-
- test/data/users-guide/interpolation_example.result
|
171
|
-
- test/data/users-guide/main_program1.rb
|
172
|
-
- test/data/users-guide/main_program1.result
|
173
|
-
- test/data/users-guide/main_program2.rb
|
174
|
-
- test/data/users-guide/main_program2.result
|
175
|
-
- test/data/users-guide/nocode-example.eruby
|
176
|
-
- test/data/users-guide/nocode-php.result
|
177
|
-
- test/data/users-guide/nocode_example.result
|
178
|
-
- test/data/users-guide/normal-eruby-test.eruby
|
179
|
-
- test/data/users-guide/normal_eruby_test.result
|
180
|
-
- test/data/users-guide/notext-example.eruby
|
181
|
-
- test/data/users-guide/notext-example.php
|
182
|
-
- test/data/users-guide/notext-php.result
|
183
|
-
- test/data/users-guide/notext_example.result
|
184
|
-
- test/data/users-guide/percentline-example.rhtml
|
185
|
-
- test/data/users-guide/percentline_example.result
|
186
|
-
- test/data/users-guide/prefixedline-example.rb
|
187
|
-
- test/data/users-guide/prefixedline-example.rhtml
|
188
|
-
- test/data/users-guide/prefixedline_example.result
|
189
|
-
- test/data/users-guide/printenable_example.result
|
190
|
-
- test/data/users-guide/printenabled-example.eruby
|
191
|
-
- test/data/users-guide/printenabled-example.rb
|
192
|
-
- test/data/users-guide/printstatement_example.result
|
193
|
-
- test/data/users-guide/simplify_example.result
|
194
|
-
- test/data/users-guide/stderr.log
|
195
|
-
- test/data/users-guide/stdout_exmple.result
|
196
|
-
- test/data/users-guide/stringbuffer_example.result
|
197
|
-
- test/data/users-guide/tail_260.result
|
198
|
-
- test/data/users-guide/tailnewline.rhtml
|
199
|
-
- test/data/users-guide/template1.rhtml
|
200
|
-
- test/data/users-guide/template2.rhtml
|
201
|
-
- test/test-engines.rb
|
202
|
-
- test/test-enhancers.rb
|
203
|
-
- test/test-erubis.rb
|
204
|
-
- test/test-index-cgi.rb
|
205
|
-
- test/test-main.rb
|
206
|
-
- test/test-users-guide.rb
|
207
|
-
- test/test.rb
|
208
|
-
- test/testutil.rb
|
67
|
+
- test/erbse_test.rb
|
68
|
+
- test/test_helper.rb
|
209
69
|
homepage: https://github.com/apotonick/erbse
|
210
70
|
licenses:
|
211
71
|
- MIT
|
data/CHANGES.txt
DELETED
@@ -1,828 +0,0 @@
|
|
1
|
-
# -*- coding: utf-8 -*-
|
2
|
-
# $Release: 2.7.0 $
|
3
|
-
# copyright(c) 2006-2011 kuwata-lab.com all rights reserved.
|
4
|
-
|
5
|
-
- release: 2.7.0
|
6
|
-
date: 2011-04-01
|
7
|
-
enhancements:
|
8
|
-
|
9
|
-
- |
|
10
|
-
New option ':bufvar' supported to specify buffer variable name.
|
11
|
-
|
12
|
-
ex:
|
13
|
-
input = "Hello <%= name %>!"
|
14
|
-
eruby = Erubis::Eruby.new(input)
|
15
|
-
puts eruby.src
|
16
|
-
#=> _buf = ''; _buf << "Hello "; _buf << ( name ).to_s; _buf << '!';
|
17
|
-
|
18
|
-
eruby = Erubis::Eruby.new(input, :bufvar=>'@_out')
|
19
|
-
puts eruby.src
|
20
|
-
#=> @_out = ''; @_out << 'Hello '; @_out << ( name ).to_s; @_out << '!';
|
21
|
-
|
22
|
-
- |
|
23
|
-
New enhancer 'PrefixedLineEnhancer' which is a customizable version
|
24
|
-
of PercentLineEnhancer.
|
25
|
-
The difference between PrefixedLineEnhancer and PercentLineEnhancer is:
|
26
|
-
* You can indent Ruby statetment lines starting with '%'
|
27
|
-
* You can specify prefix character by :prefixchar option.
|
28
|
-
|
29
|
-
ex:
|
30
|
-
class MyEruby < Erubis::Eruby
|
31
|
-
include Erubis::PrefixedLineEnhancer
|
32
|
-
end
|
33
|
-
input = <<END
|
34
|
-
<ul>
|
35
|
-
% for item in @items
|
36
|
-
<li><%= item %></li>
|
37
|
-
% end
|
38
|
-
%% you can indent '%' lines
|
39
|
-
</ul>
|
40
|
-
END
|
41
|
-
eruby = MyEruby.new(input, :prefixchar=>'%') # default '%'
|
42
|
-
puts eruby.src
|
43
|
-
|
44
|
-
output:
|
45
|
-
_buf = ''; _buf << '<ul>
|
46
|
-
'; for item in @items
|
47
|
-
_buf << ' <li>'; _buf << ( item ).to_s; _buf << '</li>
|
48
|
-
'; end
|
49
|
-
% you can indent '%' lines
|
50
|
-
_buf << '</ul>
|
51
|
-
';
|
52
|
-
_buf.to_s
|
53
|
-
|
54
|
-
- |
|
55
|
-
Add helper CGI script. See 'public_html/README.txt' for details.
|
56
|
-
|
57
|
-
- |
|
58
|
-
Rubinius is supported as first-class Ruby implementation.
|
59
|
-
|
60
|
-
- |
|
61
|
-
C++ support. Try '-l cpp' command-line option.
|
62
|
-
|
63
|
-
|
64
|
-
changes:
|
65
|
-
|
66
|
-
- |
|
67
|
-
Remove dependency to 'abstract' library.
|
68
|
-
You don't need to install 'abstract' gem.
|
69
|
-
|
70
|
-
- |
|
71
|
-
Erubis::Eruby#load_file() now sets cache file timestamp to the same
|
72
|
-
value as original eRuby file. For example, if you restore eRuby files
|
73
|
-
from backup, Erubis::Eruby#load_file() can detect it and generate
|
74
|
-
cache file again.
|
75
|
-
|
76
|
-
## generates cache file (A.rhtml.cache).
|
77
|
-
eruby = Erubis::Eruby.load_file('A.rhtml')
|
78
|
-
p File.mtime('A.rhtml') == File.mtime('A.rhtml.cache') #=> true
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
- release: 2.6.6
|
83
|
-
date: 2010-06-27
|
84
|
-
bugfixes:
|
85
|
-
|
86
|
-
- |
|
87
|
-
Fixed a bug around InterporationEnhancer and FastEruby to escape back-quote. (thanks to Andrew R Jackson)
|
88
|
-
|
89
|
-
|
90
|
-
- release: 2.6.5
|
91
|
-
date: 2009-07-20
|
92
|
-
bugfixes:
|
93
|
-
|
94
|
-
- |
|
95
|
-
Fixed bug around '-z' option.
|
96
|
-
|
97
|
-
|
98
|
-
- release: 2.6.4
|
99
|
-
date: 2009-02-18
|
100
|
-
enhancements:
|
101
|
-
|
102
|
-
- |
|
103
|
-
Rails 2.2 and 2.3 support.
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
- release: 2.6.3
|
108
|
-
date: 2009-02-07
|
109
|
-
bugfixes:
|
110
|
-
|
111
|
-
- Enhancer name was not displayed in Ruby 1.9.1 when it was missing.
|
112
|
-
|
113
|
-
- Command option argument name was not displayed correctly as a part of error message.
|
114
|
-
|
115
|
-
- MethoNotFound error was raised when invalid option was specified.
|
116
|
-
|
117
|
-
|
118
|
-
- release: 2.6.2
|
119
|
-
date: 2008-06-12
|
120
|
-
enhancements:
|
121
|
-
|
122
|
-
- |
|
123
|
-
Ruby 1.9 support.
|
124
|
-
|
125
|
-
bugfixes:
|
126
|
-
|
127
|
-
- |
|
128
|
-
Fixed installation problem on Windows (Thanks to Tim Morgan and Allen).
|
129
|
-
|
130
|
-
|
131
|
-
- release: 2.6.1
|
132
|
-
date: 2008-06-06
|
133
|
-
enhancements:
|
134
|
-
|
135
|
-
- |
|
136
|
-
Rails 2.1 support. (special thanks José Valim)
|
137
|
-
|
138
|
-
|
139
|
-
|
140
|
-
- release: 2.6.0
|
141
|
-
date: 2008-05-05
|
142
|
-
enhancements:
|
143
|
-
|
144
|
-
- |
|
145
|
-
Improved support of Ruby on Rails 2.0.2.
|
146
|
-
New class ActionView::TemplateHandlers::Erubis is defined and
|
147
|
-
registered as default handler of *.html.erb and *.rhtml.
|
148
|
-
|
149
|
-
- |
|
150
|
-
'<%% %>' and '<%%= %>' are converted into '<% %>' and '<%= %>' respectively.
|
151
|
-
This is for compatibility with ERB.
|
152
|
-
|
153
|
-
ex1.rhtml:
|
154
|
-
<ul>
|
155
|
-
<%% for item in @list %>
|
156
|
-
<li><%%= item %></li>
|
157
|
-
<%% end %>
|
158
|
-
</ul>
|
159
|
-
|
160
|
-
result:
|
161
|
-
$ erubis ex1.rhtml
|
162
|
-
<ul>
|
163
|
-
<% for item in @list %>
|
164
|
-
<li><%= item %></li>
|
165
|
-
<% end %>
|
166
|
-
</ul>
|
167
|
-
|
168
|
-
- |
|
169
|
-
'<%= -%>' removes tail spaces and newlines.
|
170
|
-
This is for compatibiliy with ERB when trim mode is '-'.
|
171
|
-
'<%= =%>' also removes tail spaces and newlines, and this is
|
172
|
-
Erubis-original enhancement (cooler than '<%= -%>', isn't it?).
|
173
|
-
|
174
|
-
ex2.rhtml:
|
175
|
-
<div>
|
176
|
-
<%= @var -%> # or <%= @var =%>
|
177
|
-
</div>
|
178
|
-
|
179
|
-
result (version 2.6.0):
|
180
|
-
$ erubis -c '{var: "AAA\n"}' ex2.rhtml
|
181
|
-
<div>
|
182
|
-
AAA
|
183
|
-
</div>
|
184
|
-
|
185
|
-
result (version 2.5.0):
|
186
|
-
$ erubis -c '{var: "AAA\n"}' ex2.rhtml
|
187
|
-
<div>
|
188
|
-
AAA
|
189
|
-
|
190
|
-
</div>
|
191
|
-
|
192
|
-
- |
|
193
|
-
Erubis::Eruby.load_file() now allows you to change cache filename.
|
194
|
-
|
195
|
-
ex.
|
196
|
-
eruby = Erubis::Eruby.load_file("ex3.rhtml",
|
197
|
-
:cachename=>'ex3.rhtml.cache')
|
198
|
-
|
199
|
-
|
200
|
-
- release: 2.5.0
|
201
|
-
date: 2008-01-30
|
202
|
-
enhancements:
|
203
|
-
|
204
|
-
- |
|
205
|
-
Ruby on Rails 2.0 support.
|
206
|
-
If you are using preprocessing, notice that _?('foo.id') will be NG
|
207
|
-
because it contains period ('.') character.
|
208
|
-
|
209
|
-
--------------------
|
210
|
-
<!-- NG in Rails 2.0 -->
|
211
|
-
[%= link_to 'Edit', edit_user_path(_?('@user.id')) %]
|
212
|
-
[%= link_to 'Show', @user %]
|
213
|
-
[%= link_to 'Delete', @user, :confirm=>'OK?', :method=>:delete %]
|
214
|
-
|
215
|
-
<!-- OK in Rails 2.0 -->
|
216
|
-
<%= user_id = @user.id %>
|
217
|
-
[%= link_to 'Edit', edit_user_path(_?('user_id')) %]
|
218
|
-
[%= link_to 'Show', :action=>'show', :id=>_?('user_id') %]
|
219
|
-
[%= link_to 'Delete', {:action=>'destroy', :id=>_?('user_id')},
|
220
|
-
{:confirm=>'OK?', :method=>:delete} %]
|
221
|
-
--------------------
|
222
|
-
|
223
|
-
- |
|
224
|
-
(experimental)
|
225
|
-
Rails form helper methods for preprocessing are added.
|
226
|
-
These helper methos are available with preprocessing.
|
227
|
-
|
228
|
-
ex. _form.rhtml
|
229
|
-
--------------------
|
230
|
-
Name: <%= text_field :user, :name %>
|
231
|
-
Name: [%= pp_text_field :user, :name %]
|
232
|
-
--------------------
|
233
|
-
|
234
|
-
preprocessed:
|
235
|
-
--------------------
|
236
|
-
Name: <%= text_field :user, :name %>
|
237
|
-
Name: <input id="stock_name" name="stock[name]" size="30" type="text" value="<%=h @stock.name%>" />
|
238
|
-
--------------------
|
239
|
-
|
240
|
-
Ruby code:
|
241
|
-
--------------------
|
242
|
-
_buf << '
|
243
|
-
Name: '; _buf << ( text_field :stock, :name ).to_s; _buf << '
|
244
|
-
Name: <input id="stock_name" name="stock[name]" size="30" type="text" value="'; _buf << (h @stock.name).to_s; _buf << '" />
|
245
|
-
';
|
246
|
-
--------------------
|
247
|
-
|
248
|
-
This shows that text_filed() is called every time when rendering,
|
249
|
-
but pp_text_filed() is called only once when loading template,
|
250
|
-
so pp_text_field() with prepocessing is much faster than text_field().
|
251
|
-
|
252
|
-
See User's guide for details.
|
253
|
-
http://www.kuwata-lab.com/erubis/users-guide.05.html#rails-formhelpers
|
254
|
-
|
255
|
-
#
|
256
|
-
- release: 2.4.1
|
257
|
-
date: 2007-09-25
|
258
|
-
enhancements:
|
259
|
-
|
260
|
-
- |
|
261
|
-
Add new section 'evaluate(context) v.s. result(binding)' to user's guide.
|
262
|
-
This section describes why Erubis::Eruby#evaluate(context) is recommended
|
263
|
-
rather than Erubis::Eruby#result(binding).
|
264
|
-
User's Guide > Other Topics > evaluate(context) v.s. result(binding)
|
265
|
-
http://www.kuwata-lab.com/erubis/users-guide.06.html#topics-context-vs-binding
|
266
|
-
|
267
|
-
- |
|
268
|
-
Add new command-line property '--docwrite={true|false}' to
|
269
|
-
Erubis::Ejavascript.
|
270
|
-
If this property is true then 'document.write(_buf.join(""));' is used
|
271
|
-
as postamble and if it is false then '_buf.join("")' is used.
|
272
|
-
Default is true for compatibility reason but it will be false in the
|
273
|
-
future release.
|
274
|
-
(This feature was proposed by D.Dribin. Thank you.)
|
275
|
-
|
276
|
-
bugfix:
|
277
|
-
|
278
|
-
- |
|
279
|
-
When using Erubis::Eruby#evaluate(), changing local variables in
|
280
|
-
templates have affected to variables accessible with TOPLEVEL_BINDING.
|
281
|
-
It means that if you change variables in templates, it is possible to
|
282
|
-
change variables in main program.
|
283
|
-
This was a bug and is now fixed not to affect to variables in main
|
284
|
-
program.
|
285
|
-
|
286
|
-
ex. template.rhtml
|
287
|
-
--------------------
|
288
|
-
<% for x in @items %>
|
289
|
-
item = <%= x %>
|
290
|
-
<% end %>
|
291
|
-
--------------------
|
292
|
-
|
293
|
-
ex. main-program.rb
|
294
|
-
--------------------
|
295
|
-
require 'erubis'
|
296
|
-
x = 10
|
297
|
-
items = ['foo', 'bar', 'baz']
|
298
|
-
eruby = Erubis::Eruby.new(File.read('template.rhtml'))
|
299
|
-
s = eruby.evaluate(:items=>items)
|
300
|
-
print s
|
301
|
-
$stderr.puts "*** debug: x=#{x.inspect}" #=> x="baz" (2.4.0)
|
302
|
-
#=> x=10 (2.4.1)
|
303
|
-
--------------------
|
304
|
-
|
305
|
-
- |
|
306
|
-
PercentLineEnhancer was very slow. Now performance problem is solved.
|
307
|
-
|
308
|
-
|
309
|
-
#
|
310
|
-
- release: 2.4.0
|
311
|
-
date: 2007-07-19
|
312
|
-
enhancements:
|
313
|
-
|
314
|
-
- |
|
315
|
-
Preprocessing is supported by Ruby on Rails helper.
|
316
|
-
Preprocessing makes Ruby on Rails application about 20-40 percent faster.
|
317
|
-
|
318
|
-
For example,
|
319
|
-
|
320
|
-
[%= link_to 'Show', :action=>'show', :id=>_?('@user.id') %]
|
321
|
-
|
322
|
-
is evaluate by preprocessor and expanded into the following
|
323
|
-
when template file is loaded.
|
324
|
-
|
325
|
-
<a href="/users/show/<%=@user.id%>">Show</a>
|
326
|
-
|
327
|
-
It means that link_to() is not called when template is rendered
|
328
|
-
and rendering speed will be much faster in the result.
|
329
|
-
|
330
|
-
See User's Guide for details.
|
331
|
-
|
332
|
-
- |
|
333
|
-
Erubis::Eruby#evaluate() (or Erubis::RubyEvaluator#evaluate()) now
|
334
|
-
creates Proc object from @src and eval it.
|
335
|
-
|
336
|
-
def evaluate(context=Context.new)
|
337
|
-
context = Context.new(context) if context.is_a?(Hash)
|
338
|
-
@_proc ||= eval("proc { #{@src} }", TOPLEVEL_BINDING, @filename || '(erubis)')
|
339
|
-
return context.instance_eval(&@_proc)
|
340
|
-
end
|
341
|
-
|
342
|
-
This makes evaluate() much faster when eruby object is reused.
|
343
|
-
|
344
|
-
- |
|
345
|
-
Erubis::Eruby#def_method() is supported.
|
346
|
-
This method defines ruby code as instance method or singleton metod.
|
347
|
-
|
348
|
-
require 'erubis'
|
349
|
-
s = "hello <%= name %>"
|
350
|
-
eruby = Erubis::Eruby.new(s)
|
351
|
-
filename = 'hello.rhtml'
|
352
|
-
|
353
|
-
## define instance method to Dummy class (or module)
|
354
|
-
class Dummy; end
|
355
|
-
eruby.def_method(Dummy, 'render(name)', filename) # filename is optional
|
356
|
-
p Dummy.new.render('world') #=> "hello world"
|
357
|
-
|
358
|
-
## define singleton method to an object
|
359
|
-
obj = Object.new
|
360
|
-
eruby.def_method(obj, 'render(name)', filename) # filename is optional
|
361
|
-
p obj.render('world') #=> "hello world"
|
362
|
-
|
363
|
-
This is equivarent to ERB#def_method().
|
364
|
-
|
365
|
-
- |
|
366
|
-
Erubis::XmlHelper.url_escape() and u() which is alias of url_escape()
|
367
|
-
are added.
|
368
|
-
This is equivarent to ERB#Util.url_escape().
|
369
|
-
|
370
|
-
|
371
|
-
bugfix:
|
372
|
-
- Help message was not shown when '-h' is specified. Fixed.
|
373
|
-
- 'def method()' was not availabe in template file. Fixed.
|
374
|
-
|
375
|
-
|
376
|
-
#
|
377
|
-
- release: 2.3.1
|
378
|
-
date: 2007-05-26
|
379
|
-
bugfix:
|
380
|
-
- A serious bug in 'helpers/rails_helper.rb' is fixed.
|
381
|
-
You must be update if you are using Erubis with Ruby on Rails.
|
382
|
-
|
383
|
-
|
384
|
-
#
|
385
|
-
- release: 2.3.0
|
386
|
-
date: 2007-05-23
|
387
|
-
enhancements:
|
388
|
-
- |
|
389
|
-
New class 'Erubis::FastEruby' is added.
|
390
|
-
It is a subclass of Erubis::Eruby and includes InterpolationEnhancer.
|
391
|
-
Erubis::FastEruby is compatible with and faster than Erubis::Eruby.
|
392
|
-
|
393
|
-
- |
|
394
|
-
New enhancer 'InterpolationEnhancer' is added.
|
395
|
-
This enhancer uses expression interpolation to eliminate method call
|
396
|
-
of String#<<. In the result, this enhancer makes Eruby a little faster.
|
397
|
-
|
398
|
-
--------------------
|
399
|
-
## Assume that input is '<a href="<%=url%>"><%=name%></a>'.
|
400
|
-
## Eruby convert input into the following code. String#<< is called 5 times.
|
401
|
-
_buf << '<a href="'; _buf << (url).to_s; _buf << '">'; _buf << (name).to_s; _buf << '</a>';
|
402
|
-
|
403
|
-
## When InterpolationEnhancer is used, String#<< is called only once.
|
404
|
-
_buf << %Q`<a href="#{url}">#{name}</a>`;
|
405
|
-
--------------------
|
406
|
-
|
407
|
-
- |
|
408
|
-
New enhancer 'ErboutEnhancer' is added.
|
409
|
-
ErboutEnhancer set '_erbout' as well as '_buf' to be compatible with ERB.
|
410
|
-
|
411
|
-
ex.
|
412
|
-
====================
|
413
|
-
$ cat ex.rhtml
|
414
|
-
<p>Hello</p>
|
415
|
-
$ erubis -x ex.rhtml
|
416
|
-
_buf = ''; _buf << '<p>Hello</p>
|
417
|
-
';
|
418
|
-
_buf.to_s
|
419
|
-
$ erubis -xE Erbout ex.rhtml
|
420
|
-
_erbout = _buf = ''; _buf << '<p>Hello</p>
|
421
|
-
';
|
422
|
-
_buf.to_s
|
423
|
-
====================
|
424
|
-
|
425
|
-
- |
|
426
|
-
[experimental]
|
427
|
-
New enhancer 'DeleteIndentEnhancer' is added.
|
428
|
-
This enhancer deletes indentation of HTML file.
|
429
|
-
|
430
|
-
ex.
|
431
|
-
====================
|
432
|
-
$ cat ex.rhtml
|
433
|
-
<div>
|
434
|
-
<ul>
|
435
|
-
<% for item in ['AAA', 'BBB', 'CCC'] %>
|
436
|
-
<li><%= item %></li>
|
437
|
-
<% end %>
|
438
|
-
</ul>
|
439
|
-
</div>
|
440
|
-
$ erubis ex.rhtml
|
441
|
-
<div>
|
442
|
-
<ul>
|
443
|
-
<li>AAA</li>
|
444
|
-
<li>BBB</li>
|
445
|
-
<li>CCC</li>
|
446
|
-
</ul>
|
447
|
-
</div>
|
448
|
-
$ erubis -E DeleteIndent ex.rhtml
|
449
|
-
<div>
|
450
|
-
<ul>
|
451
|
-
<li>AAA</li>
|
452
|
-
<li>BBB</li>
|
453
|
-
<li>CCC</li>
|
454
|
-
</ul>
|
455
|
-
</div>
|
456
|
-
====================
|
457
|
-
|
458
|
-
- |
|
459
|
-
Mod_ruby is supported (very thanks to Andrew R Jackson!).
|
460
|
-
See users-guide and 'contrib/erubis-run.rb' for details.
|
461
|
-
|
462
|
-
- |
|
463
|
-
New command-line option '-X', '-N', '-U', and '-C' are added.
|
464
|
-
These are intended to be a replacement of 'notext' command.
|
465
|
-
'-X' shows only ruby statements and expressions.
|
466
|
-
'-N' adds line numbers.
|
467
|
-
'-U' compress empty lines into a line.
|
468
|
-
'-C' removes empty lines.
|
469
|
-
|
470
|
-
|
471
|
-
changes:
|
472
|
-
|
473
|
-
- |
|
474
|
-
'helpers/rails_helper.rb' is changed to use ErboutEnhancer.
|
475
|
-
The following is an examle to use Erubis with Ruby on Rails.
|
476
|
-
|
477
|
-
File 'config/environment.rb':
|
478
|
-
----------------------------------------
|
479
|
-
require 'erubis/helpers/rails_helper'
|
480
|
-
#Erubis::Helpers::RailsHelper.engine_class = Erubis::Eruby # or Erubis::FastEruby
|
481
|
-
#Erubis::Helpers::RailsHelper.init_properties = {}
|
482
|
-
#Erubis::Helpers::RailsHelper.show_src = false # set true for debugging
|
483
|
-
----------------------------------------
|
484
|
-
|
485
|
-
- |
|
486
|
-
Command 'notext' has been removed. Use '-X', '-N', '-U', and '-C'
|
487
|
-
instead.
|
488
|
-
|
489
|
-
- |
|
490
|
-
Tab characters in YAML file are expaneded automatically.
|
491
|
-
If you want not to expand tab characters, add command-line optio '-T'.
|
492
|
-
|
493
|
-
- |
|
494
|
-
Benchmark scripts (benchmark/bench.*) are rewrited.
|
495
|
-
|
496
|
-
- |
|
497
|
-
Users-guide (doc/users-guide.html) is updated.
|
498
|
-
|
499
|
-
|
500
|
-
|
501
|
-
#
|
502
|
-
- release: 2.2.0
|
503
|
-
date: 2007-02-11
|
504
|
-
enhancements:
|
505
|
-
- |
|
506
|
-
Performance tuned up. Release 2.2.0 works about 8 percent faster
|
507
|
-
than 2.1.0.
|
508
|
-
As a result, Erubis works more than 10 percent faster than eruby.
|
509
|
-
(eruby is the extension module of eRuby written in C.)
|
510
|
-
|
511
|
-
- |
|
512
|
-
Support of Ruby on Rails improved.
|
513
|
-
If you want to use Erubis with Ruby on Rails, add the following code
|
514
|
-
into your 'config/environment.rb' and restart web server.
|
515
|
-
This will set Erubis as eRuby compiler in Ruby on Rails instead of ERB.
|
516
|
-
|
517
|
-
--------------------
|
518
|
-
require 'erubis/helpers/rails_helper'
|
519
|
-
#Erubis::Helpers::RailsHelper.engine_class = Erubis::Eruby
|
520
|
-
#Erubis::Helpers::RailsHelper.init_properties = {}
|
521
|
-
#Erubis::Helpers::RailsHelper.show_src = true
|
522
|
-
--------------------
|
523
|
-
|
524
|
-
Methods 'capture()' and 'content_for()' of ActionView::Helpers::CaptureHelper
|
525
|
-
are available. Methd ActionView::Helpers::TextHelper#concat() is also available.
|
526
|
-
|
527
|
-
If Erubis::Helpers::RailsHelper.show_src is ture, Erubis prints converted
|
528
|
-
Ruby code into log file (such as 'log/development.log').
|
529
|
-
|
530
|
-
- |
|
531
|
-
Erubis::Engine.load_file(filename) creates cache file (filename +
|
532
|
-
'.cache') automatically if cache file is old or not exist.
|
533
|
-
Caching makes Erubis about 40-50 percent faster.
|
534
|
-
|
535
|
-
ex.
|
536
|
-
--------------------
|
537
|
-
require 'erubis'
|
538
|
-
eruby = Erubis::Eruby.load_file('example.rhtml')
|
539
|
-
## cache file 'example.rhtml.cache' is created automatically
|
540
|
-
--------------------
|
541
|
-
|
542
|
-
- |
|
543
|
-
Command-line option '-f datafile' can take Ruby script ('*.rb')
|
544
|
-
as well as YAML file ('*.yaml' or '*.yml').
|
545
|
-
|
546
|
-
ex.
|
547
|
-
====================
|
548
|
-
$ cat context.rb
|
549
|
-
@title = 'Example'
|
550
|
-
@list = %w[AAA BBB CCC]
|
551
|
-
$ cat example.rhtml
|
552
|
-
<h1><%= @title %></h1>
|
553
|
-
<ul>
|
554
|
-
<% for item in @list %>
|
555
|
-
<li><%= item %></li>
|
556
|
-
<% end %>
|
557
|
-
</ul>
|
558
|
-
$ erubis -f context.rb example.rhtml
|
559
|
-
<h1>Example</h1>
|
560
|
-
<ul>
|
561
|
-
<li>AAA</li>
|
562
|
-
<li>BBB</li>
|
563
|
-
<li>CCC</li>
|
564
|
-
</ul>
|
565
|
-
====================
|
566
|
-
|
567
|
-
- |
|
568
|
-
New command-line option '-c context' support. It takes context string
|
569
|
-
in YAML inline style or Ruby code style.
|
570
|
-
|
571
|
-
ex. YAML inline style
|
572
|
-
====================
|
573
|
-
$ erubis -c '{title: Example, list: [AAA, BBB, CCC]}' example.rhtml
|
574
|
-
====================
|
575
|
-
|
576
|
-
ex. Ruby style
|
577
|
-
====================
|
578
|
-
$ erubis -c '@title="Example"; @list=%w[AAA BBB CCC]' example.rhtml
|
579
|
-
====================
|
580
|
-
|
581
|
-
- |
|
582
|
-
New command-line option '-z' (syntax checking) support. It is similar
|
583
|
-
to 'erubis -x file.rhtml | ruby -wc', but it can take several filenames.
|
584
|
-
|
585
|
-
ex.
|
586
|
-
====================
|
587
|
-
$ erubis -z app/views/*/*.rhtml
|
588
|
-
Syntax OK
|
589
|
-
====================
|
590
|
-
|
591
|
-
- |
|
592
|
-
New constant Erubis::VERSION added.
|
593
|
-
|
594
|
-
|
595
|
-
changes:
|
596
|
-
- |
|
597
|
-
Class Erubis::Eruby changed to include Erubis::StringBufferEnhancer
|
598
|
-
instead of Erubis::ArrayBufferEnhancer.
|
599
|
-
This is for Ruby on Rails support.
|
600
|
-
|
601
|
-
ex.
|
602
|
-
====================
|
603
|
-
$ cat example.rhtml
|
604
|
-
<ul>
|
605
|
-
<% for item in @list %>
|
606
|
-
<li><%= item %></li>
|
607
|
-
<% end %>
|
608
|
-
</ul>
|
609
|
-
$ erubis -x example.rhtml
|
610
|
-
_buf = ''; _buf << '<ul>
|
611
|
-
'; for item in @list
|
612
|
-
_buf << ' <li>'; _buf << ( item ).to_s; _buf << '</li>
|
613
|
-
'; end
|
614
|
-
_buf << '</ul>
|
615
|
-
';
|
616
|
-
_buf.to_s
|
617
|
-
====================
|
618
|
-
|
619
|
-
- |
|
620
|
-
Erubis::StringBufferEnhancer#add_postamble() prints "_buf.to_s"
|
621
|
-
instead of "_buf".
|
622
|
-
This is useful for 'erubis -x file.rhtml | ruby -wc'.
|
623
|
-
|
624
|
-
- |
|
625
|
-
Command-line option '-T' is removed. Use '--trim=false' instead.
|
626
|
-
|
627
|
-
- |
|
628
|
-
License is changed to MIT License.
|
629
|
-
|
630
|
-
- |
|
631
|
-
Embedded pattern '<%- -%>' can be handled.
|
632
|
-
|
633
|
-
|
634
|
-
#
|
635
|
-
- release: 2.1.0
|
636
|
-
date: 2006-09-23
|
637
|
-
enhancements:
|
638
|
-
- |
|
639
|
-
Ruby on Rails support. Add the following code to
|
640
|
-
your 'app/controllers/application.rb' and restart web server.
|
641
|
-
|
642
|
-
--------------------
|
643
|
-
require 'erubis/helper/rails'
|
644
|
-
suffix = 'erubis'
|
645
|
-
ActionView::Base.register_template_handler(suffix, Erubis::Helper::RailsTemplate)
|
646
|
-
#Erubis::Helper::RailsTemplate.engine_class = Erubis::EscapedEruby ## or Erubis::PI::Eruby
|
647
|
-
#Erubis::Helper::RailsTemplate.default_properties = { :escape=>true, :escapefunc=>'h' }
|
648
|
-
--------------------
|
649
|
-
|
650
|
-
And rename your view template as 'xxx.erubis'.
|
651
|
-
If you got the "(eval):10:in `render': no block given" error,
|
652
|
-
use '@content_for_layout' instead 'yield' in your layout template.
|
653
|
-
|
654
|
-
- |
|
655
|
-
Another eRuby engine (PIEngine) support. This engine doesn't
|
656
|
-
break HTML design because it uses Processing Instructions (PI)
|
657
|
-
'<?rb .. ?>' as embedded pattern instead of '<% .. %>'.
|
658
|
-
|
659
|
-
example.rhtml
|
660
|
-
--------------------
|
661
|
-
<table>
|
662
|
-
<?rb @list.each_with_index do |item, i| ?>
|
663
|
-
<?rb klass = i % 2 == 0 ? 'odd' : 'even' ?>
|
664
|
-
<tr class="@{klass}@">
|
665
|
-
<td>@!{item}@</td>
|
666
|
-
</tr>
|
667
|
-
<?rb end ?>
|
668
|
-
</table>
|
669
|
-
--------------------
|
670
|
-
|
671
|
-
compile:
|
672
|
-
====================
|
673
|
-
$ erubis -x --pi example.rhtml
|
674
|
-
_buf = []; _buf << '<table>
|
675
|
-
'; @list.each_with_index do |item, i|
|
676
|
-
klass = i % 2 == 0 ? 'odd' : 'even'
|
677
|
-
_buf << ' <tr class="'; _buf << Erubis::XmlHelper.escape_xml(klass); _buf << '">
|
678
|
-
<td>'; _buf << (item).to_s; _buf << '</td>
|
679
|
-
</tr>
|
680
|
-
'; end
|
681
|
-
_buf << '</table>
|
682
|
-
';
|
683
|
-
_buf.join
|
684
|
-
====================
|
685
|
-
|
686
|
-
- |
|
687
|
-
Add new command 'notext' which remove text part from eRuby
|
688
|
-
script and leaves only Ruby code.
|
689
|
-
This is very useful for debug of eRuby script.
|
690
|
-
|
691
|
-
example2.rhtml
|
692
|
-
--------------------
|
693
|
-
<html>
|
694
|
-
<body>
|
695
|
-
<table>
|
696
|
-
<% @list.each_with_index do |item, i| %>
|
697
|
-
<% klass = i % 2 == 0 ? 'odd' : 'even' %>
|
698
|
-
<tr class="<%= klass %>">
|
699
|
-
<td><%== item %></td>
|
700
|
-
</tr>
|
701
|
-
<% end %>
|
702
|
-
</table>
|
703
|
-
</body>
|
704
|
-
</html>
|
705
|
-
--------------------
|
706
|
-
|
707
|
-
command line example:
|
708
|
-
====================
|
709
|
-
$ notext example2.rhtml
|
710
|
-
_buf = [];
|
711
|
-
|
712
|
-
|
713
|
-
@list.each_with_index do |item, i| ;
|
714
|
-
klass = i % 2 == 0 ? 'odd' : 'even' ;
|
715
|
-
_buf << ( klass ).to_s;
|
716
|
-
_buf << Erubis::XmlHelper.escape_xml( item );
|
717
|
-
|
718
|
-
end ;
|
719
|
-
|
720
|
-
|
721
|
-
|
722
|
-
_buf.join
|
723
|
-
$ notext -nc example2.rhtml
|
724
|
-
1: _buf = [];
|
725
|
-
4: @list.each_with_index do |item, i| ;
|
726
|
-
5: klass = i % 2 == 0 ? 'odd' : 'even' ;
|
727
|
-
6: _buf << ( klass ).to_s;
|
728
|
-
7: _buf << Erubis::XmlHelper.escape_xml( item );
|
729
|
-
9: end ;
|
730
|
-
13: _buf.join
|
731
|
-
====================
|
732
|
-
|
733
|
-
- |
|
734
|
-
Add new enhance 'NoCode' which removes ruby code from
|
735
|
-
eRuby script and leaves only HTML text part.
|
736
|
-
It is very useful to validate HTML of eRuby script.
|
737
|
-
|
738
|
-
command-line example:
|
739
|
-
====================
|
740
|
-
$ erubis -x -E NoCode example2.rhtml
|
741
|
-
<html>
|
742
|
-
<body>
|
743
|
-
<table>
|
744
|
-
|
745
|
-
|
746
|
-
<tr class="">
|
747
|
-
<td></td>
|
748
|
-
</tr>
|
749
|
-
|
750
|
-
</table>
|
751
|
-
</body>
|
752
|
-
</html>
|
753
|
-
====================
|
754
|
-
|
755
|
-
changes:
|
756
|
-
- License is changed to LGPL.
|
757
|
-
- Command-line property '--escape=name' is renamed to
|
758
|
-
'--escapefunc=name'.
|
759
|
-
- When command-line option '-l perl' is specified, function
|
760
|
-
'encode_entities()' is used ad escaping function which is
|
761
|
-
available wth HTML::Entities module.
|
762
|
-
|
763
|
-
bugfix:
|
764
|
-
- There is a certain pattern which makes Engine#convert()
|
765
|
-
too slow. Now Engne#convert() is fixed not to be slown.
|
766
|
-
- Command name is now displayed when '-h' is specified.
|
767
|
-
|
768
|
-
|
769
|
-
#
|
770
|
-
- release: 2.0.1
|
771
|
-
date: 2006-06-21
|
772
|
-
bugfix:
|
773
|
-
- some minor bugs are fixed
|
774
|
-
|
775
|
-
|
776
|
-
#
|
777
|
-
- release: 2.0.0
|
778
|
-
date: 2006-05-20
|
779
|
-
changes:
|
780
|
-
- module 'PrintEnhancer' is renamed to 'PrintEnabledEnahncer'
|
781
|
-
- module 'FastEnhancer' and class 'FastEruby' is obsolete because they are integrated into Eruby class
|
782
|
-
- Eruby#evaluate() calls instance_eval() instead of eval()
|
783
|
-
- XmlEruby.escape_xml() is moved to XmlHelper.escape_xml()
|
784
|
-
enhancements:
|
785
|
-
- multi programming language support (Ruby/PHP/C/Java/Scheme/Perl/Javascript)
|
786
|
-
- class Eruby runs very fast because FastEnhancer module is integrated into Eruby by default
|
787
|
-
- TinyEruby class (tiny.rb) is added
|
788
|
-
- module ArrayBufferEnhancer added
|
789
|
-
- module ArrayEnhancer added
|
790
|
-
- module BiPatternEnhancer added
|
791
|
-
- module EscapeEnhancer added
|
792
|
-
- module HeaderFooterEnhancer added
|
793
|
-
- module NoTextEnhancer added
|
794
|
-
- module PercentLineEnhancer added
|
795
|
-
- module PrintEnabledEnhancer added
|
796
|
-
- module PrintOutEnhancer added
|
797
|
-
- module SimplifyEnhancer added
|
798
|
-
- module StringBufferEnhancer added
|
799
|
-
- module StringIOEnhancer added
|
800
|
-
- command-line option '-b' (body only) added
|
801
|
-
- command-line option '-e' (escape) added
|
802
|
-
- command-line option '-l' (lang) added
|
803
|
-
- command-line option '-E' (enhancer) added
|
804
|
-
- command-line option '-I' (require path) added
|
805
|
-
- command-line option '-K' (kanji code) added
|
806
|
-
- command-line option '-S' (string to symbol) added
|
807
|
-
- command-line option '-B' (call result(binding())) added
|
808
|
-
|
809
|
-
|
810
|
-
#
|
811
|
-
- release: 1.1.0
|
812
|
-
date: 2006-03-05
|
813
|
-
enhancements:
|
814
|
-
- '<%# ... %>' is supported
|
815
|
-
- PrintEnhancer, PrintEruby, and PrintXmlEruby added
|
816
|
-
|
817
|
-
- release: 1.0.1
|
818
|
-
date: 2006-02-01
|
819
|
-
bugfixes:
|
820
|
-
- bin/erubis is available with RubyGems
|
821
|
-
|
822
|
-
|
823
|
-
#
|
824
|
-
- release: 1.0.0
|
825
|
-
date: 2006-02-01
|
826
|
-
bugfixes:
|
827
|
-
- first release
|
828
|
-
|