erubis 1.1.0 → 2.0.0
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/ChangeLog +45 -18
- data/README.txt +80 -0
- data/benchmark/erubybench-lib.rb +189 -0
- data/benchmark/erubybench.rb +364 -0
- data/benchmark/erubybench.rhtml +61 -0
- data/benchmark/erubybench.yaml +61 -0
- data/bin/erubis +4 -180
- data/contrib/erubis +2297 -0
- data/contrib/inline-require +151 -0
- data/doc-api/classes/Erubis.html +236 -0
- data/doc-api/classes/Erubis/ArrayBufferEnhancer.html +175 -0
- data/doc-api/classes/Erubis/ArrayBufferEruby.html +120 -0
- data/doc-api/classes/Erubis/ArrayEnhancer.html +174 -0
- data/doc-api/classes/Erubis/ArrayEruby.html +120 -0
- data/doc-api/classes/Erubis/BiPatternEnhancer.html +212 -0
- data/doc-api/classes/Erubis/BiPatternEruby.html +120 -0
- data/doc-api/classes/Erubis/CommandOptionError.html +113 -0
- data/doc-api/classes/Erubis/Context.html +249 -0
- data/doc-api/classes/Erubis/Ec.html +399 -0
- data/doc-api/classes/Erubis/Ejava.html +366 -0
- data/doc-api/classes/Erubis/Ejavascript.html +390 -0
- data/doc-api/classes/Erubis/Engine.html +711 -0
- data/doc-api/classes/Erubis/Eperl.html +350 -0
- data/doc-api/classes/Erubis/Ephp.html +308 -0
- data/doc-api/classes/Erubis/ErubisError.html +117 -0
- data/doc-api/classes/Erubis/Eruby.html +310 -0
- data/doc-api/classes/Erubis/EscapeEnhancer.html +167 -0
- data/doc-api/classes/Erubis/EscapedEc.html +120 -0
- data/doc-api/classes/Erubis/EscapedEjava.html +120 -0
- data/doc-api/classes/Erubis/EscapedEjavascript.html +120 -0
- data/doc-api/classes/Erubis/EscapedEperl.html +120 -0
- data/doc-api/classes/Erubis/EscapedEphp.html +120 -0
- data/doc-api/classes/Erubis/EscapedEruby.html +127 -0
- data/doc-api/classes/Erubis/EscapedEscheme.html +120 -0
- data/doc-api/classes/Erubis/Escheme.html +389 -0
- data/doc-api/classes/Erubis/HeaderFooterEnhancer.html +264 -0
- data/doc-api/classes/Erubis/HeaderFooterEruby.html +120 -0
- data/doc-api/classes/Erubis/Main.html +318 -0
- data/doc-api/classes/Erubis/NoTextEnhancer.html +159 -0
- data/doc-api/classes/Erubis/NoTextEruby.html +120 -0
- data/doc-api/classes/Erubis/OptimizedEruby.html +445 -0
- data/doc-api/classes/Erubis/OptimizedXmlEruby.html +163 -0
- data/doc-api/classes/Erubis/PercentLineEnhancer.html +174 -0
- data/doc-api/classes/Erubis/PercentLineEruby.html +120 -0
- data/doc-api/classes/Erubis/PrintEnabledEnhancer.html +212 -0
- data/doc-api/classes/Erubis/PrintEnabledEruby.html +120 -0
- data/doc-api/classes/Erubis/PrintOutEnhancer.html +244 -0
- data/doc-api/classes/Erubis/PrintOutEruby.html +120 -0
- data/doc-api/classes/Erubis/PrintOutSimplifiedEruby.html +121 -0
- data/doc-api/classes/Erubis/SimplifiedEruby.html +120 -0
- data/doc-api/classes/Erubis/SimplifyEnhancer.html +185 -0
- data/doc-api/classes/Erubis/StdoutEnhancer.html +173 -0
- data/doc-api/classes/Erubis/StdoutEruby.html +120 -0
- data/doc-api/classes/Erubis/StdoutSimplifiedEruby.html +121 -0
- data/doc-api/classes/Erubis/StringBufferEnhancer.html +174 -0
- data/doc-api/classes/Erubis/StringBufferEruby.html +120 -0
- data/doc-api/classes/Erubis/StringIOEruby.html +120 -0
- data/doc-api/classes/Erubis/TinyEruby.html +305 -0
- data/doc-api/classes/Erubis/XmlEruby.html +130 -0
- data/doc-api/classes/Erubis/XmlHelper.html +193 -0
- data/doc-api/created.rid +1 -0
- data/doc-api/files/__/README_txt.html +214 -0
- data/doc-api/files/erubis/engine/ec_rb.html +115 -0
- data/doc-api/files/erubis/engine/ejava_rb.html +115 -0
- data/doc-api/files/erubis/engine/ejavascript_rb.html +115 -0
- data/doc-api/files/erubis/engine/enhanced_rb.html +115 -0
- data/doc-api/files/erubis/engine/eperl_rb.html +115 -0
- data/doc-api/files/erubis/engine/ephp_rb.html +115 -0
- data/doc-api/files/erubis/engine/eruby_rb.html +115 -0
- data/doc-api/files/erubis/engine/escheme_rb.html +115 -0
- data/doc-api/files/erubis/engine/optimized_rb.html +114 -0
- data/doc-api/files/erubis/engine_rb.html +114 -0
- data/doc-api/files/erubis/enhancer_rb.html +114 -0
- data/doc-api/files/erubis/helper_rb.html +107 -0
- data/doc-api/files/erubis/local-setting_rb.html +107 -0
- data/doc-api/files/erubis/main_rb.html +125 -0
- data/doc-api/files/erubis/tiny_rb.html +107 -0
- data/doc-api/files/erubis_rb.html +118 -0
- data/doc-api/fr_class_index.html +77 -0
- data/doc-api/fr_file_index.html +43 -0
- data/doc-api/fr_method_index.html +157 -0
- data/doc-api/index.html +24 -0
- data/doc-api/rdoc-style.css +208 -0
- data/doc/users-guide.html +1507 -375
- data/examples/Makefile +53 -0
- data/examples/example.ec +24 -0
- data/examples/example.ejava +41 -0
- data/examples/example.ejavascript +16 -0
- data/examples/example.eperl +16 -0
- data/examples/example.ephp +17 -0
- data/examples/example.eruby +15 -0
- data/examples/example.escheme +26 -0
- data/lib/erubis.rb +37 -269
- data/lib/erubis/engine.rb +260 -0
- data/lib/erubis/engine/ec.rb +106 -0
- data/lib/erubis/engine/ejava.rb +101 -0
- data/lib/erubis/engine/ejavascript.rb +104 -0
- data/lib/erubis/engine/enhanced.rb +102 -0
- data/lib/erubis/engine/eperl.rb +83 -0
- data/lib/erubis/engine/ephp.rb +84 -0
- data/lib/erubis/engine/eruby.rb +91 -0
- data/lib/erubis/engine/escheme.rb +96 -0
- data/lib/erubis/engine/optimized.rb +114 -0
- data/lib/erubis/enhancer.rb +487 -0
- data/lib/erubis/helper.rb +53 -0
- data/lib/erubis/local-setting.rb +10 -0
- data/lib/erubis/main.rb +368 -0
- data/lib/erubis/tiny.rb +65 -0
- data/test/assert-text-equal.rb +45 -0
- data/test/test-bin.rb +222 -45
- data/test/test-engines.rb +343 -0
- data/test/test-erubis.rb +836 -501
- data/test/test.rb +27 -0
- data/test/testutil.rb +86 -0
- metadata +131 -8
- data/README +0 -50
data/examples/Makefile
ADDED
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
all = example.rb example.php example.c example.java example.scm example.pl example.js
|
|
2
|
+
|
|
3
|
+
all: $(all)
|
|
4
|
+
|
|
5
|
+
example.rb: example.eruby
|
|
6
|
+
erubis -l ruby example.eruby > example.rb
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
example.php: example.ephp
|
|
10
|
+
erubis -l php example.ephp > example.php
|
|
11
|
+
|
|
12
|
+
example.c: example.ec
|
|
13
|
+
erubis -l c example.ec > example.c
|
|
14
|
+
|
|
15
|
+
example.java: example.ejava
|
|
16
|
+
erubis -l java example.ejava > example.java
|
|
17
|
+
|
|
18
|
+
example.scm: example.escheme
|
|
19
|
+
erubis -l scheme --func=display example.escheme > example.scm
|
|
20
|
+
# erubis -l scheme example.escheme > example.scm
|
|
21
|
+
|
|
22
|
+
example.pl: example.eperl
|
|
23
|
+
erubis -l perl example.eperl > example.pl
|
|
24
|
+
|
|
25
|
+
example.js: example.ejavascript
|
|
26
|
+
erubis -l javascript example.ejavascript > example.js
|
|
27
|
+
|
|
28
|
+
|
|
29
|
+
###----------
|
|
30
|
+
|
|
31
|
+
src = example.eruby example.ephp example.ec example.ejava example.escheme example.eperl example.ejavascript Makefile
|
|
32
|
+
|
|
33
|
+
clean:
|
|
34
|
+
rm -f `ruby -e 'puts(Dir.glob("*.*") - %w[$(src)])'`
|
|
35
|
+
# rm -f $(all)
|
|
36
|
+
|
|
37
|
+
compile: a.out example.class
|
|
38
|
+
|
|
39
|
+
a.out: example.c
|
|
40
|
+
cc example.c
|
|
41
|
+
|
|
42
|
+
example.class: example.java
|
|
43
|
+
jikes example.java
|
|
44
|
+
|
|
45
|
+
output: $(all) a.out example.class
|
|
46
|
+
erubis example.eruby > example.ruby.out
|
|
47
|
+
php example.php > example.php.out
|
|
48
|
+
./a.out foo bar baz > example.c.out
|
|
49
|
+
java example > example.java.out
|
|
50
|
+
gosh example.scm > example.scm.out
|
|
51
|
+
# guile example.scm > example.scm.out
|
|
52
|
+
perl example.pl > example.pl.out
|
|
53
|
+
|
data/examples/example.ec
ADDED
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
<%
|
|
2
|
+
#include <stdio.h>
|
|
3
|
+
|
|
4
|
+
int main(int argc, char *argv[])
|
|
5
|
+
{
|
|
6
|
+
int i;
|
|
7
|
+
|
|
8
|
+
%>
|
|
9
|
+
<p>Hello <%= "%s", argv[0] %>!</p>
|
|
10
|
+
<table>
|
|
11
|
+
<tbody>
|
|
12
|
+
<% for (i = 1; i < argc; i++) { %>
|
|
13
|
+
<tr bgcolor="<%= i % 2 == 0 ? "#FFCCCC" : "#CCCCFF" %>">
|
|
14
|
+
<td><%= "%d", i %></td>
|
|
15
|
+
<td><%= "%s", argv[i] %></td>
|
|
16
|
+
</tr>
|
|
17
|
+
<% } %>
|
|
18
|
+
</tbody>
|
|
19
|
+
</table>
|
|
20
|
+
<%
|
|
21
|
+
|
|
22
|
+
return 0;
|
|
23
|
+
}
|
|
24
|
+
%>
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
<%
|
|
2
|
+
import java.util.*;
|
|
3
|
+
|
|
4
|
+
public class example {
|
|
5
|
+
|
|
6
|
+
public static void main(String[] args) {
|
|
7
|
+
String user = "Erubis";
|
|
8
|
+
String[] list = { "<aaa>", "b&b", "\"ccc\"" };
|
|
9
|
+
StringBuffer _buf = new StringBuffer();
|
|
10
|
+
%>
|
|
11
|
+
<p>Hello <%= user %>!</p>
|
|
12
|
+
<table>
|
|
13
|
+
<tbody>
|
|
14
|
+
<% for (int i = 0; i < list.length; i++) { %>
|
|
15
|
+
<tr bgcolor="<%= i % 2 == 0 ? "#FFCCCC" : "#CCCCFF" %>">
|
|
16
|
+
<td><%= i + 1 %></td>
|
|
17
|
+
<td><%== list[i] %></td>
|
|
18
|
+
</tr>
|
|
19
|
+
<% } %>
|
|
20
|
+
</tbody>
|
|
21
|
+
</table>
|
|
22
|
+
<%
|
|
23
|
+
System.out.print(_buf.toString());
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
public static String escape(String s) {
|
|
27
|
+
StringBuffer sb = new StringBuffer();
|
|
28
|
+
for (int i = 0; i < s.length(); i++) {
|
|
29
|
+
char ch = s.charAt(i);
|
|
30
|
+
switch (ch) {
|
|
31
|
+
case '<': sb.append("<"); break;
|
|
32
|
+
case '>': sb.append(">"); break;
|
|
33
|
+
case '&': sb.append("&"); break;
|
|
34
|
+
case '"': sb.append("""); break;
|
|
35
|
+
default: sb.append(ch);
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
return sb.toString();
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
%>
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
<%
|
|
2
|
+
var user = 'Erubis';
|
|
3
|
+
var list = ['<aaa>', 'b&b', '"ccc"'];
|
|
4
|
+
%>
|
|
5
|
+
<p>Hello <%= user %>!</p>
|
|
6
|
+
<table>
|
|
7
|
+
<tbody>
|
|
8
|
+
<% var i; %>
|
|
9
|
+
<% for (i = 0; i < list.length; i++) { %>
|
|
10
|
+
<tr bgcolor="<%= i % 2 == 0 ? '#FFCCCC' : '#CCCCFF' %>">
|
|
11
|
+
<td><%= i + 1 %></td>
|
|
12
|
+
<td><%= list[i] %></td>
|
|
13
|
+
</tr>
|
|
14
|
+
<% } %>
|
|
15
|
+
</tbody>
|
|
16
|
+
</table>
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
<%
|
|
2
|
+
my $user = 'Erubis';
|
|
3
|
+
my @list = ('<aaa>', 'b&b', '"ccc"');
|
|
4
|
+
%>
|
|
5
|
+
<p>Hello <%= $user %>!</p>
|
|
6
|
+
<table>
|
|
7
|
+
<tbody>
|
|
8
|
+
<% $i = 0; %>
|
|
9
|
+
<% for $item (@list) { %>
|
|
10
|
+
<tr bgcolor=<%= ++$i % 2 == 0 ? '#FFCCCC' : '#CCCCFF' %>">
|
|
11
|
+
<td><%= $i %></td>
|
|
12
|
+
<td><%= $item %></td>
|
|
13
|
+
</tr>
|
|
14
|
+
<% } %>
|
|
15
|
+
</tbody>
|
|
16
|
+
</table>
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
<%
|
|
2
|
+
$user = "World";
|
|
3
|
+
$list = array('<aaa>', 'b&b', '"ccc"');
|
|
4
|
+
%>
|
|
5
|
+
<p>Hello <%= $user %>!</p>
|
|
6
|
+
<table>
|
|
7
|
+
<tbody>
|
|
8
|
+
<% $i = 0 %>
|
|
9
|
+
<% foreach ($list as $item) { %>
|
|
10
|
+
<% $i++; %>
|
|
11
|
+
<tr bgcolor="<%= $i % 2 == 0 ? '#FFCCCC' : '#CCCCFF' %>">
|
|
12
|
+
<td><%= $i %></td>
|
|
13
|
+
<td><%== $item %></td>
|
|
14
|
+
</tr>
|
|
15
|
+
<% } %>
|
|
16
|
+
</tbody>
|
|
17
|
+
</table>
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
<%
|
|
2
|
+
user = 'Erubis'
|
|
3
|
+
list = ['<aaa>', 'b&b', '"ccc"']
|
|
4
|
+
%>
|
|
5
|
+
<p>Hello <%= user %>!</p>
|
|
6
|
+
<table>
|
|
7
|
+
<tbody>
|
|
8
|
+
<% list.each_with_index do |item, i| %>
|
|
9
|
+
<tr bgcolor="<%= i % 2 == 0 ? '#FFCCCC' : '#CCCCFF' %>">
|
|
10
|
+
<td><%= i + 1 %></td>
|
|
11
|
+
<td><%== item %></td>
|
|
12
|
+
</tr>
|
|
13
|
+
<% end %>
|
|
14
|
+
</tbody>
|
|
15
|
+
</table>
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
<%
|
|
2
|
+
(let ((user "Erubis")
|
|
3
|
+
(items '("<aaa>" "b&b" "\"ccc\""))
|
|
4
|
+
(i 0))
|
|
5
|
+
%>
|
|
6
|
+
<p>Hello <%= user %>!</p>
|
|
7
|
+
<table>
|
|
8
|
+
<tbody>
|
|
9
|
+
<%
|
|
10
|
+
(for-each
|
|
11
|
+
(lambda (item)
|
|
12
|
+
(set! i (+ i 1))
|
|
13
|
+
%>
|
|
14
|
+
<tr bgcolor="<%= (if (= (modulo i 2) 0) "#FFCCCC" "#CCCCFF") %>">
|
|
15
|
+
<td><%= i %></td>
|
|
16
|
+
<td><%= item %></td>
|
|
17
|
+
</tr>
|
|
18
|
+
<%
|
|
19
|
+
) ; lambda end
|
|
20
|
+
items) ; for-each end
|
|
21
|
+
%>
|
|
22
|
+
</tbody>
|
|
23
|
+
</table>
|
|
24
|
+
<%
|
|
25
|
+
) ; let end
|
|
26
|
+
%>
|
data/lib/erubis.rb
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
##
|
|
2
|
-
## $Rev:
|
|
3
|
-
## $Release:
|
|
2
|
+
## $Rev: 21 $
|
|
3
|
+
## $Release: 2.0.0 $
|
|
4
4
|
## copyright(c) 2006 kuwata-lab all rights reserved.
|
|
5
5
|
##
|
|
6
6
|
|
|
@@ -9,294 +9,62 @@
|
|
|
9
9
|
##
|
|
10
10
|
## * class Eruby - normal eRuby class
|
|
11
11
|
## * class XmlEruby - eRuby class which escape '&<>"' into '&<>"'
|
|
12
|
-
## * module
|
|
13
|
-
## * module
|
|
14
|
-
## *
|
|
12
|
+
## * module StdoutEnhancer - use $stdout instead of String as output
|
|
13
|
+
## * module PrintEnhancer - enable to write print statement in <% ... %>
|
|
14
|
+
## * class OptimizedEruby - optimized Eruby class faster than FastEruby
|
|
15
|
+
## * class OptimizedXmlEruby - optimized XmlEruby class faster than FastXmlEruby
|
|
15
16
|
##
|
|
16
17
|
## example:
|
|
17
|
-
##
|
|
18
|
-
## input = <<-END
|
|
18
|
+
## input = <<'END'
|
|
19
19
|
## <ul>
|
|
20
|
-
## <% for item in list %>
|
|
20
|
+
## <% for item in @list %>
|
|
21
21
|
## <li><%= item %>
|
|
22
22
|
## <%== item %></li>
|
|
23
23
|
## <% end %>
|
|
24
24
|
## </ul>
|
|
25
25
|
## END
|
|
26
|
-
##
|
|
26
|
+
## list = ['<aaa>', 'b&b', '"ccc"']
|
|
27
|
+
## eruby = Erubis::Eruby.new(input)
|
|
27
28
|
## puts "--- source ---"
|
|
28
29
|
## puts eruby.src
|
|
29
30
|
## puts "--- result ---"
|
|
30
|
-
## puts eruby.
|
|
31
|
-
## # or puts eruby.
|
|
31
|
+
## puts eruby.evaluate(:list=>list)
|
|
32
|
+
## # or puts eruby.result(binding())
|
|
32
33
|
##
|
|
33
34
|
## result:
|
|
34
35
|
## --- source ---
|
|
35
|
-
##
|
|
36
|
+
## _buf = ""; _buf << " <ul>\n"
|
|
36
37
|
## for item in list
|
|
37
|
-
##
|
|
38
|
-
##
|
|
38
|
+
## _buf << " <li>"; _buf << ( item ).to_s; _buf << "\n"
|
|
39
|
+
## _buf << " "; _buf << Erubis::XmlEruby.escape( item ); _buf << "</li>\n"
|
|
39
40
|
## end
|
|
40
|
-
##
|
|
41
|
-
##
|
|
41
|
+
## _buf << " </ul>\n"
|
|
42
|
+
## _buf
|
|
42
43
|
## --- result ---
|
|
43
44
|
## <ul>
|
|
44
|
-
## <li
|
|
45
|
-
##
|
|
46
|
-
## <li>b&
|
|
47
|
-
## b&b</li>
|
|
48
|
-
## <li
|
|
49
|
-
##
|
|
45
|
+
## <li><aaa>
|
|
46
|
+
## <aaa></li>
|
|
47
|
+
## <li>b&b
|
|
48
|
+
## b&b</li>
|
|
49
|
+
## <li>"ccc"
|
|
50
|
+
## "ccc"</li>
|
|
50
51
|
## </ul>
|
|
51
52
|
##
|
|
52
53
|
|
|
53
|
-
module Erubis
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
##
|
|
57
|
-
## base class
|
|
58
|
-
##
|
|
59
|
-
class Eruby
|
|
60
|
-
|
|
61
|
-
def initialize(input, options={})
|
|
62
|
-
#@input = input
|
|
63
|
-
@pattern = options[:pattern] || '<% %>'
|
|
64
|
-
@filename = options[:filename]
|
|
65
|
-
@trim = options[:trim] != false
|
|
66
|
-
@src = compile(input)
|
|
67
|
-
end
|
|
68
|
-
attr_reader :src
|
|
69
|
-
attr_accessor :filename
|
|
70
|
-
|
|
71
|
-
def self.load_file(filename, options={})
|
|
72
|
-
input = File.open(filename, 'rb') { |f| f.read }
|
|
73
|
-
options[:filename] = filename
|
|
74
|
-
eruby = self.new(input, options)
|
|
75
|
-
return eruby
|
|
76
|
-
end
|
|
77
|
-
|
|
78
|
-
def result(binding=TOPLEVEL_BINDING)
|
|
79
|
-
filename = @filename || '(erubis)'
|
|
80
|
-
eval @src, binding, filename
|
|
81
|
-
end
|
|
82
|
-
|
|
83
|
-
def evaluate(_context={})
|
|
84
|
-
_evalstr = ''
|
|
85
|
-
_context.keys.each do |key|
|
|
86
|
-
_evalstr << "#{key.to_s} = _context[#{key.inspect}]\n"
|
|
87
|
-
end
|
|
88
|
-
eval _evalstr
|
|
89
|
-
return result(binding())
|
|
90
|
-
end
|
|
91
|
-
|
|
92
|
-
#private
|
|
93
|
-
|
|
94
|
-
def compile(input)
|
|
95
|
-
src = ""
|
|
96
|
-
initialize_src(src)
|
|
97
|
-
prefix, postfix = @pattern.split()
|
|
98
|
-
regexp = /(.*?)(^[ \t]*)?#{prefix}(=+|\#)?(.*?)#{postfix}([ \t]*\r?\n)?/m
|
|
99
|
-
input.scan(regexp) do |text, head_space, indicator, code, tail_space|
|
|
100
|
-
## * when '<%= %>', do nothing
|
|
101
|
-
## * when '<% %>' or '<%# %>', delete spaces iff only spaces are around '<% %>'
|
|
102
|
-
if indicator && indicator[0] == ?=
|
|
103
|
-
flag_trim = false
|
|
104
|
-
else
|
|
105
|
-
flag_trim = @trim && head_space && tail_space
|
|
106
|
-
end
|
|
107
|
-
#flag_trim = @trim && !(indicator && indicator[0]==?=) && head_space && tail_space
|
|
108
|
-
add_src_text(src, text)
|
|
109
|
-
add_src_text(src, head_space) if !flag_trim && head_space
|
|
110
|
-
if !indicator # <% %>
|
|
111
|
-
code = "#{head_space}#{code}#{tail_space}" if flag_trim
|
|
112
|
-
add_src_code(src, code)
|
|
113
|
-
elsif indicator[0] == ?= # <%= %>
|
|
114
|
-
add_src_expr(src, code, indicator)
|
|
115
|
-
else # <%# %>
|
|
116
|
-
n = code.count("\n")
|
|
117
|
-
n += tail_space.count("\n") if tail_space
|
|
118
|
-
add_src_code(src, "\n" * n)
|
|
119
|
-
end
|
|
120
|
-
add_src_text(src, tail_space) if !flag_trim && tail_space
|
|
121
|
-
end
|
|
122
|
-
rest = $' || input
|
|
123
|
-
add_src_text(src, rest)
|
|
124
|
-
finalize_src(src)
|
|
125
|
-
return src
|
|
126
|
-
end
|
|
127
|
-
|
|
128
|
-
protected
|
|
129
|
-
|
|
130
|
-
def initialize_src(src)
|
|
131
|
-
src << "_out = ''; "
|
|
132
|
-
end
|
|
133
|
-
|
|
134
|
-
def add_src_text(src, text)
|
|
135
|
-
#return if text.empty?
|
|
136
|
-
text.each_line do |line|
|
|
137
|
-
src << "_out << #{line.dump}" << (line[-1] == ?\n ? "\n" : "; ")
|
|
138
|
-
end
|
|
139
|
-
end
|
|
140
|
-
|
|
141
|
-
def add_src_expr(src, code, indicator)
|
|
142
|
-
src << "_out << (#{code}).to_s; "
|
|
143
|
-
end
|
|
144
|
-
|
|
145
|
-
def add_src_code(src, code)
|
|
146
|
-
code.each_line { |line| src << line }
|
|
147
|
-
src << "; " unless code[-1] == ?\n
|
|
148
|
-
end
|
|
149
|
-
|
|
150
|
-
def finalize_src(src)
|
|
151
|
-
src << "_out\n"
|
|
152
|
-
end
|
|
153
|
-
|
|
154
|
-
end # end of class Eruby
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
##
|
|
158
|
-
## do sanitizing of <%= %>
|
|
159
|
-
##
|
|
160
|
-
class XmlEruby < Eruby
|
|
161
|
-
|
|
162
|
-
def self.escape(obj)
|
|
163
|
-
str = obj.to_s.dup
|
|
164
|
-
#str = obj.to_s
|
|
165
|
-
#str = str.dup if obj.__id__ == str.__id__
|
|
166
|
-
str.gsub!(/&/, '&')
|
|
167
|
-
str.gsub!(/</, '<')
|
|
168
|
-
str.gsub!(/>/, '>')
|
|
169
|
-
str.gsub!(/"/, '"') #"
|
|
170
|
-
return str
|
|
171
|
-
end
|
|
172
|
-
|
|
173
|
-
def add_src_expr(src, code, indicator)
|
|
174
|
-
case indicator
|
|
175
|
-
when '=' # <%= %>
|
|
176
|
-
src << "_out << Erubis::XmlEruby.escape(#{code}); "
|
|
177
|
-
when '==' # <%== %>
|
|
178
|
-
super
|
|
179
|
-
when '===' # <%=== %>
|
|
180
|
-
code.strip!
|
|
181
|
-
s = code.dump
|
|
182
|
-
s.sub!(/\A"/, '')
|
|
183
|
-
s.sub!(/"\z/, '')
|
|
184
|
-
src << "$stderr.puts(\"** erubis: #{s} = \#{(#{code}).inspect}\"); "
|
|
185
|
-
else
|
|
186
|
-
# nothing
|
|
187
|
-
end
|
|
188
|
-
end
|
|
189
|
-
|
|
190
|
-
end # end of class XmlEruby
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
##
|
|
194
|
-
## make Eruby faster
|
|
195
|
-
##
|
|
196
|
-
module FastEnhancer
|
|
197
|
-
|
|
198
|
-
def add_src_text(src, text)
|
|
199
|
-
return if text.empty?
|
|
200
|
-
#src << "_out << #{text.dump}" << (text[-1] == ?\n ? "\n" : "; ")
|
|
201
|
-
src << "_out << #{text.dump}"
|
|
202
|
-
n = text.count("\n")
|
|
203
|
-
src << ("\n" * n)
|
|
204
|
-
src << "; " if n == 0
|
|
205
|
-
end
|
|
206
|
-
|
|
207
|
-
end
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
##
|
|
211
|
-
## use $stdout instead of string
|
|
212
|
-
##
|
|
213
|
-
module StdoutEnhancer
|
|
214
|
-
|
|
215
|
-
def initialize_src(src)
|
|
216
|
-
src << "_out = $stdout; "
|
|
217
|
-
end
|
|
218
|
-
|
|
219
|
-
def finalize_src(src)
|
|
220
|
-
src << "nil\n"
|
|
221
|
-
end
|
|
222
|
-
|
|
223
|
-
end
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
##
|
|
227
|
-
## print function is available.
|
|
228
|
-
##
|
|
229
|
-
## Notice: use Eruby#evaluate() and don't use Eruby#result()
|
|
230
|
-
## to be enable print function.
|
|
231
|
-
##
|
|
232
|
-
module PrintEnhancer
|
|
233
|
-
|
|
234
|
-
def initialize_src(src)
|
|
235
|
-
src << "@_out = _out = ''; "
|
|
236
|
-
end
|
|
237
|
-
|
|
238
|
-
def print(arg)
|
|
239
|
-
@_out << arg.to_s
|
|
240
|
-
end
|
|
241
|
-
|
|
242
|
-
def result(binding=TOPLEVEL_BINDING)
|
|
243
|
-
filename = @filename || '(erubis)'
|
|
244
|
-
eval @src, binding, filename
|
|
245
|
-
end
|
|
246
|
-
|
|
247
|
-
end
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
class FastEruby < Eruby
|
|
251
|
-
include FastEnhancer
|
|
252
|
-
end
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
class StdoutEruby < Eruby
|
|
256
|
-
include StdoutEnhancer
|
|
257
|
-
end
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
class PrintEruby < Eruby
|
|
261
|
-
include PrintEnhancer
|
|
262
|
-
end
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
class FastXmlEruby < XmlEruby
|
|
266
|
-
include FastEnhancer
|
|
267
|
-
end
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
class StdoutXmlEruby < XmlEruby
|
|
271
|
-
include StdoutEnhancer
|
|
272
|
-
end
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
class PrintXmlEruby < XmlEruby
|
|
276
|
-
include PrintEnhancer
|
|
277
|
-
end
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
end
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
if __FILE__ == $0
|
|
284
54
|
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
55
|
+
require 'erubis/engine'
|
|
56
|
+
require 'erubis/helper'
|
|
57
|
+
require 'erubis/enhancer'
|
|
58
|
+
#require 'erubis/tiny'
|
|
59
|
+
require 'erubis/engine/eruby'
|
|
60
|
+
#require 'erubis/engine/enhanced' # enhanced eruby engines
|
|
61
|
+
#require 'erubis/engine/optimized' # generates optimized ruby code
|
|
62
|
+
#require 'erubis/engine/ephp'
|
|
63
|
+
#require 'erubis/engine/ec'
|
|
64
|
+
#require 'erubis/engine/ejava'
|
|
65
|
+
#require 'erubis/engine/escheme'
|
|
66
|
+
#require 'erubis/engine/eperl'
|
|
67
|
+
#require 'erubis/engine/ejavascript'
|
|
294
68
|
|
|
295
|
-
eruby = Erubis::XmlEruby.new(input)
|
|
296
|
-
puts "--- source ---"
|
|
297
|
-
puts eruby.src
|
|
298
|
-
puts "--- result ---"
|
|
299
|
-
#puts eruby.result(binding())
|
|
300
|
-
puts eruby.evaluate(:list=>list)
|
|
301
69
|
|
|
302
|
-
|
|
70
|
+
require 'erubis/local-setting'
|