erubis 2.0.1 → 2.1.0
Sign up to get free protection for your applications and to get access to all the features.
- data/ChangeLog +150 -2
- data/LGPL +504 -0
- data/README.txt +14 -8
- data/benchmark/erubybench.rb +1 -1
- data/benchmark/erubybench.rhtml +3 -3
- data/bin/erubis +1 -1
- data/bin/notext +154 -0
- data/contrib/erubis +1036 -374
- data/contrib/inline-require +5 -3
- data/doc-api/classes/Erubis.html +43 -1
- data/doc-api/classes/Erubis/ArrayBufferEnhancer.html +14 -14
- data/doc-api/classes/Erubis/ArrayEnhancer.html +14 -14
- data/doc-api/classes/Erubis/Basic.html +112 -0
- data/doc-api/classes/Erubis/Basic/Converter.html +318 -0
- data/doc-api/classes/Erubis/Basic/Engine.html +130 -0
- data/doc-api/classes/Erubis/BiPatternEnhancer.html +14 -14
- data/doc-api/classes/Erubis/CGenerator.html +386 -0
- data/doc-api/classes/Erubis/Context.html +31 -32
- data/doc-api/classes/Erubis/Converter.html +231 -0
- data/doc-api/classes/Erubis/Ec.html +9 -283
- data/doc-api/classes/Erubis/Ejava.html +9 -274
- data/doc-api/classes/Erubis/Ejavascript.html +9 -298
- data/doc-api/classes/Erubis/Engine.html +68 -508
- data/doc-api/classes/Erubis/Eperl.html +9 -259
- data/doc-api/classes/Erubis/Ephp.html +9 -239
- data/doc-api/classes/Erubis/ErubisError.html +2 -2
- data/doc-api/classes/Erubis/Eruby.html +4 -187
- data/doc-api/classes/Erubis/EscapeEnhancer.html +9 -11
- data/doc-api/classes/Erubis/Escheme.html +9 -272
- data/doc-api/classes/Erubis/Evaluator.html +212 -0
- data/doc-api/classes/Erubis/Generator.html +410 -0
- data/doc-api/classes/Erubis/HeaderFooterEnhancer.html +16 -16
- data/doc-api/classes/Erubis/Helper.html +112 -0
- data/doc-api/classes/Erubis/Helper/CachedRailsTemplate.html +198 -0
- data/doc-api/classes/Erubis/Helper/RailsTemplate.html +366 -0
- data/doc-api/classes/Erubis/JavaGenerator.html +359 -0
- data/doc-api/classes/Erubis/JavascriptGenerator.html +381 -0
- data/doc-api/classes/Erubis/Main.html +27 -25
- data/doc-api/classes/Erubis/NoCodeEnhancer.html +249 -0
- data/doc-api/classes/Erubis/NoCodeEruby.html +120 -0
- data/doc-api/classes/Erubis/NoTextEnhancer.html +8 -8
- data/doc-api/classes/Erubis/NotSupportedError.html +119 -0
- data/doc-api/classes/Erubis/OptimizedEruby.html +22 -304
- data/doc-api/classes/Erubis/OptimizedGenerator.html +439 -0
- data/doc-api/classes/Erubis/OptimizedXmlEruby.html +7 -7
- data/doc-api/classes/Erubis/PI.html +124 -0
- data/doc-api/classes/Erubis/PI/Converter.html +318 -0
- data/doc-api/classes/Erubis/PI/Ec.html +166 -0
- data/doc-api/classes/Erubis/PI/Ejava.html +166 -0
- data/doc-api/classes/Erubis/PI/Ejavascript.html +166 -0
- data/doc-api/classes/Erubis/PI/Engine.html +122 -0
- data/doc-api/classes/Erubis/PI/Eperl.html +166 -0
- data/doc-api/classes/Erubis/PI/Ephp.html +166 -0
- data/doc-api/classes/Erubis/PI/Eruby.html +155 -0
- data/doc-api/classes/Erubis/PI/Escheme.html +166 -0
- data/doc-api/classes/Erubis/PI/TinyEruby.html +305 -0
- data/doc-api/classes/Erubis/PercentLineEnhancer.html +7 -7
- data/doc-api/classes/Erubis/PerlGenerator.html +344 -0
- data/doc-api/classes/Erubis/PhpGenerator.html +350 -0
- data/doc-api/classes/Erubis/PrintEnabledEnhancer.html +24 -24
- data/doc-api/classes/Erubis/PrintOutEnhancer.html +35 -35
- data/doc-api/classes/Erubis/RubyEvaluator.html +190 -0
- data/doc-api/classes/Erubis/RubyGenerator.html +327 -0
- data/doc-api/classes/Erubis/SchemeGenerator.html +382 -0
- data/doc-api/classes/Erubis/SimplifyEnhancer.html +17 -13
- data/doc-api/classes/Erubis/StdoutEnhancer.html +14 -14
- data/doc-api/classes/Erubis/StringBufferEnhancer.html +14 -14
- data/doc-api/classes/Erubis/TinyEruby.html +45 -40
- data/doc-api/classes/Erubis/XmlHelper.html +14 -14
- data/doc-api/created.rid +1 -1
- data/doc-api/files/__/README_txt.html +27 -9
- data/doc-api/files/erubis/context_rb.html +107 -0
- data/doc-api/files/erubis/converter_rb.html +114 -0
- data/doc-api/files/erubis/engine/ec_rb.html +2 -2
- data/doc-api/files/erubis/engine/ejava_rb.html +2 -2
- data/doc-api/files/erubis/engine/ejavascript_rb.html +2 -2
- data/doc-api/files/erubis/engine/enhanced_rb.html +2 -2
- data/doc-api/files/erubis/engine/eperl_rb.html +2 -2
- data/doc-api/files/erubis/engine/ephp_rb.html +2 -2
- data/doc-api/files/erubis/engine/eruby_rb.html +3 -2
- data/doc-api/files/erubis/engine/escheme_rb.html +2 -2
- data/doc-api/files/erubis/engine/optimized_rb.html +2 -2
- data/doc-api/files/erubis/engine_rb.html +6 -3
- data/doc-api/files/erubis/enhancer_rb.html +2 -9
- data/doc-api/files/erubis/error_rb.html +107 -0
- data/doc-api/files/erubis/evaluator_rb.html +115 -0
- data/doc-api/files/erubis/generator_rb.html +114 -0
- data/doc-api/files/erubis/helper/rails_rb.html +140 -0
- data/doc-api/files/erubis/helper_rb.html +1 -1
- data/doc-api/files/erubis/local-setting_rb.html +1 -1
- data/doc-api/files/erubis/main_rb.html +2 -2
- data/doc-api/files/erubis/tiny_rb.html +2 -2
- data/doc-api/files/erubis_rb.html +2 -2
- data/doc-api/fr_class_index.html +32 -0
- data/doc-api/fr_file_index.html +6 -0
- data/doc-api/fr_method_index.html +178 -136
- data/doc/users-guide.html +538 -199
- data/examples/{Makefile → basic/Makefile} +11 -11
- data/examples/basic/example.ec +42 -0
- data/examples/{example.ejava → basic/example.ejava} +5 -1
- data/examples/{example.ejavascript → basic/example.ejs} +0 -0
- data/examples/{example.eperl → basic/example.eperl} +2 -2
- data/examples/{example.ephp → basic/example.ephp} +0 -0
- data/examples/{example.eruby → basic/example.eruby} +0 -0
- data/examples/{example.escheme → basic/example.escheme} +0 -0
- data/examples/pi/Makefile +54 -0
- data/examples/pi/example.ec +42 -0
- data/examples/pi/example.ejava +45 -0
- data/examples/pi/example.ejs +16 -0
- data/examples/pi/example.eperl +16 -0
- data/examples/pi/example.ephp +17 -0
- data/examples/pi/example.eruby +15 -0
- data/examples/pi/example.escheme +26 -0
- data/lib/erubis.rb +15 -8
- data/lib/erubis/context.rb +54 -0
- data/lib/erubis/converter.rb +307 -0
- data/lib/erubis/engine.rb +57 -227
- data/lib/erubis/engine/ec.rb +31 -20
- data/lib/erubis/engine/ejava.rb +33 -21
- data/lib/erubis/engine/ejavascript.rb +30 -18
- data/lib/erubis/engine/enhanced.rb +7 -2
- data/lib/erubis/engine/eperl.rb +33 -19
- data/lib/erubis/engine/ephp.rb +32 -14
- data/lib/erubis/engine/eruby.rb +34 -7
- data/lib/erubis/engine/escheme.rb +34 -15
- data/lib/erubis/engine/optimized.rb +25 -11
- data/lib/erubis/enhancer.rb +53 -19
- data/lib/erubis/error.rb +24 -0
- data/lib/erubis/evaluator.rb +71 -0
- data/lib/erubis/generator.rb +83 -0
- data/lib/erubis/helper.rb +1 -1
- data/lib/erubis/helper/rails.rb +159 -0
- data/lib/erubis/local-setting.rb +1 -1
- data/lib/erubis/main.rb +87 -46
- data/lib/erubis/tiny.rb +81 -7
- data/test/assert-text-equal.rb +1 -1
- data/test/test-engines.rb +8 -9
- data/test/test-erubis.rb +196 -18
- data/test/{test-bin.rb → test-main.rb} +123 -21
- data/test/test-notext.rb +27 -0
- data/test/test.rb +5 -3
- data/test/testutil.rb +25 -36
- metadata +75 -13
- data/COPYING +0 -340
- data/examples/example.ec +0 -24
@@ -10,10 +10,10 @@ example.php: example.ephp
|
|
10
10
|
erubis -l php example.ephp > example.php
|
11
11
|
|
12
12
|
example.c: example.ec
|
13
|
-
erubis -
|
13
|
+
erubis -bl c example.ec > example.c
|
14
14
|
|
15
15
|
example.java: example.ejava
|
16
|
-
erubis -
|
16
|
+
erubis -bl java example.ejava > example.java
|
17
17
|
|
18
18
|
example.scm: example.escheme
|
19
19
|
erubis -l scheme --func=display example.escheme > example.scm
|
@@ -22,31 +22,31 @@ example.scm: example.escheme
|
|
22
22
|
example.pl: example.eperl
|
23
23
|
erubis -l perl example.eperl > example.pl
|
24
24
|
|
25
|
-
example.js: example.
|
26
|
-
erubis -l javascript example.
|
25
|
+
example.js: example.ejs
|
26
|
+
erubis -l javascript example.ejs > example.js
|
27
27
|
|
28
28
|
|
29
29
|
###----------
|
30
30
|
|
31
|
-
src = example.eruby example.ephp example.ec example.ejava example.escheme example.eperl example.
|
31
|
+
src = example.eruby example.ephp example.ec example.ejava example.escheme example.eperl example.ejs Makefile
|
32
32
|
|
33
33
|
clean:
|
34
34
|
rm -f `ruby -e 'puts(Dir.glob("*.*") - %w[$(src)])'`
|
35
35
|
# rm -f $(all)
|
36
36
|
|
37
|
-
compile:
|
37
|
+
compile: example.bin example.class
|
38
38
|
|
39
|
-
|
40
|
-
cc example.c
|
39
|
+
example.bin: example.c
|
40
|
+
cc -o example.bin example.c
|
41
41
|
|
42
42
|
example.class: example.java
|
43
43
|
jikes example.java
|
44
44
|
|
45
|
-
output: $(all)
|
45
|
+
output: $(all) example.bin example.class
|
46
46
|
erubis example.eruby > example.ruby.out
|
47
47
|
php example.php > example.php.out
|
48
|
-
./
|
49
|
-
java example > example.
|
48
|
+
./example.bin '<aaa>' 'b&b' '"ccc"' > example.c.out
|
49
|
+
java example > example.javexample.bin
|
50
50
|
gosh example.scm > example.scm.out
|
51
51
|
# guile example.scm > example.scm.out
|
52
52
|
perl example.pl > example.pl.out
|
@@ -0,0 +1,42 @@
|
|
1
|
+
<%
|
2
|
+
#include <stdio.h>
|
3
|
+
|
4
|
+
void escape(char *str, FILE *out);
|
5
|
+
|
6
|
+
int main(int argc, char *argv[])
|
7
|
+
{
|
8
|
+
int i;
|
9
|
+
|
10
|
+
%>
|
11
|
+
<p>Hello <%== argv[0] %>!</p>
|
12
|
+
<table>
|
13
|
+
<tbody>
|
14
|
+
<% for (i = 1; i < argc; i++) { %>
|
15
|
+
<tr bgcolor="<%= i % 2 == 0 ? "#FFCCCC" : "#CCCCFF" %>">
|
16
|
+
<td><%= "%d", i %></td>
|
17
|
+
<td><%== argv[i] %></td>
|
18
|
+
</tr>
|
19
|
+
<% } %>
|
20
|
+
</tbody>
|
21
|
+
</table>
|
22
|
+
<%
|
23
|
+
|
24
|
+
return 0;
|
25
|
+
}
|
26
|
+
|
27
|
+
void escape(char *str, FILE *out)
|
28
|
+
{
|
29
|
+
char *pch;
|
30
|
+
for (pch = str; *pch != '\0'; pch++) {
|
31
|
+
switch (*pch) {
|
32
|
+
case '&': fputs("&", out); break;
|
33
|
+
case '>': fputs(">", out); break;
|
34
|
+
case '<': fputs("<", out); break;
|
35
|
+
case '"': fputs(""", out); break;
|
36
|
+
case '\'': fputs("'", out); break;
|
37
|
+
default: fputc(*pch, out);
|
38
|
+
}
|
39
|
+
}
|
40
|
+
}
|
41
|
+
|
42
|
+
%>
|
@@ -8,7 +8,7 @@ public class example {
|
|
8
8
|
String[] list = { "<aaa>", "b&b", "\"ccc\"" };
|
9
9
|
StringBuffer _buf = new StringBuffer();
|
10
10
|
%>
|
11
|
-
<p>Hello
|
11
|
+
<p>Hello <%== user %>!</p>
|
12
12
|
<table>
|
13
13
|
<tbody>
|
14
14
|
<% for (int i = 0; i < list.length; i++) { %>
|
@@ -37,5 +37,9 @@ public class example {
|
|
37
37
|
}
|
38
38
|
return sb.toString();
|
39
39
|
}
|
40
|
+
|
41
|
+
public static String escape(int i) {
|
42
|
+
return Integer.toString(i);
|
43
|
+
}
|
40
44
|
}
|
41
45
|
%>
|
File without changes
|
@@ -2,14 +2,14 @@
|
|
2
2
|
my $user = 'Erubis';
|
3
3
|
my @list = ('<aaa>', 'b&b', '"ccc"');
|
4
4
|
%>
|
5
|
-
<p>Hello
|
5
|
+
<p>Hello <%== $user %>!</p>
|
6
6
|
<table>
|
7
7
|
<tbody>
|
8
8
|
<% $i = 0; %>
|
9
9
|
<% for $item (@list) { %>
|
10
10
|
<tr bgcolor=<%= ++$i % 2 == 0 ? '#FFCCCC' : '#CCCCFF' %>">
|
11
11
|
<td><%= $i %></td>
|
12
|
-
<td
|
12
|
+
<td><%== $item %></td>
|
13
13
|
</tr>
|
14
14
|
<% } %>
|
15
15
|
</tbody>
|
File without changes
|
File without changes
|
File without changes
|
@@ -0,0 +1,54 @@
|
|
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 --pi -l ruby example.eruby > example.rb
|
7
|
+
|
8
|
+
|
9
|
+
example.php: example.ephp
|
10
|
+
erubis --pi -l php example.ephp > example.php
|
11
|
+
|
12
|
+
example.c: example.ec
|
13
|
+
erubis --pi -bl c example.ec > example.c
|
14
|
+
|
15
|
+
example.java: example.ejava
|
16
|
+
erubis --pi -bl java example.ejava > example.java
|
17
|
+
|
18
|
+
example.scm: example.escheme
|
19
|
+
erubis --pi -l scheme --func=display example.escheme > example.scm
|
20
|
+
# erubis --pi -l scheme example.escheme > example.scm
|
21
|
+
|
22
|
+
example.pl: example.eperl
|
23
|
+
erubis --pi -l perl example.eperl > example.pl
|
24
|
+
|
25
|
+
example.js: example.ejs
|
26
|
+
erubis --pi -l javascript example.ejs > example.js
|
27
|
+
|
28
|
+
|
29
|
+
###----------
|
30
|
+
|
31
|
+
src = example.eruby example.ephp example.ec example.ejava example.escheme example.eperl example.ejs Makefile
|
32
|
+
|
33
|
+
clean:
|
34
|
+
rm -f `ruby -e 'puts(Dir.glob("*.*") - %w[$(src)])'`
|
35
|
+
# rm -f $(all)
|
36
|
+
|
37
|
+
compile: example.bin example.class
|
38
|
+
|
39
|
+
example.bin: example.c
|
40
|
+
cc -o example.bin example.c
|
41
|
+
|
42
|
+
example.class: example.java
|
43
|
+
jikes example.java
|
44
|
+
|
45
|
+
output: $(all) example.bin example.class
|
46
|
+
erubis --pi example.eruby > example.ruby.result
|
47
|
+
#ruby example.rb > example.ruby.result
|
48
|
+
php example.php > example.php.result
|
49
|
+
./example.bin '<aaa>' 'b&b' '"ccc"' > example.c.result
|
50
|
+
java example > example.java.result
|
51
|
+
gosh example.scm > example.scm.result
|
52
|
+
#guile example.scm > example.scm.result
|
53
|
+
perl example.pl > example.pl.result
|
54
|
+
|
@@ -0,0 +1,42 @@
|
|
1
|
+
<?c
|
2
|
+
#include <stdio.h>
|
3
|
+
|
4
|
+
void escape(char *str, FILE *out);
|
5
|
+
|
6
|
+
int main(int argc, char *argv[])
|
7
|
+
{
|
8
|
+
int i;
|
9
|
+
|
10
|
+
?>
|
11
|
+
<p>Hello @!{argv[0]}@!</p>
|
12
|
+
<table>
|
13
|
+
<tbody>
|
14
|
+
<?c for (i = 1; i < argc; i++) { ?>
|
15
|
+
<tr bgcolor="@{i % 2 == 0 ? "#FFCCCC" : "#CCCCFF"}@">
|
16
|
+
<td>@!{"%d", i}@</td>
|
17
|
+
<td>@{argv[i]}@</td>
|
18
|
+
</tr>
|
19
|
+
<?c } ?>
|
20
|
+
</tbody>
|
21
|
+
</table>
|
22
|
+
<?c
|
23
|
+
|
24
|
+
return 0;
|
25
|
+
}
|
26
|
+
|
27
|
+
void escape(char *str, FILE *out)
|
28
|
+
{
|
29
|
+
char *pch;
|
30
|
+
for (pch = str; *pch != '\0'; pch++) {
|
31
|
+
switch (*pch) {
|
32
|
+
case '&': fputs("&", out); break;
|
33
|
+
case '>': fputs(">", out); break;
|
34
|
+
case '<': fputs("<", out); break;
|
35
|
+
case '"': fputs(""", out); break;
|
36
|
+
case '\'': fputs("'", out); break;
|
37
|
+
default: fputc(*pch, out);
|
38
|
+
}
|
39
|
+
}
|
40
|
+
}
|
41
|
+
|
42
|
+
?>
|
@@ -0,0 +1,45 @@
|
|
1
|
+
<?java
|
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
|
+
<?java 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
|
+
<?java } ?>
|
20
|
+
</tbody>
|
21
|
+
</table>
|
22
|
+
<?java
|
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
|
+
public static String escape(int i) {
|
42
|
+
return Integer.toString(i);
|
43
|
+
}
|
44
|
+
}
|
45
|
+
?>
|
@@ -0,0 +1,16 @@
|
|
1
|
+
<?js
|
2
|
+
var user = 'Erubis';
|
3
|
+
var list = ['<aaa>', 'b&b', '"ccc"'];
|
4
|
+
?>
|
5
|
+
<p>Hello @{user}@!</p>
|
6
|
+
<table>
|
7
|
+
<tbody>
|
8
|
+
<?js var i; ?>
|
9
|
+
<?js 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
|
+
<?js } ?>
|
15
|
+
</tbody>
|
16
|
+
</table>
|
@@ -0,0 +1,16 @@
|
|
1
|
+
<?perl
|
2
|
+
my $user = 'Erubis';
|
3
|
+
my @list = ('<aaa>', 'b&b', '"ccc"');
|
4
|
+
?>
|
5
|
+
<p>Hello @{$user}@!</p>
|
6
|
+
<table>
|
7
|
+
<tbody>
|
8
|
+
<?perl $i = 0; ?>
|
9
|
+
<?perl for $item (@list) { ?>
|
10
|
+
<tr bgcolor=@!{++$i % 2 == 0 ? '#FFCCCC' : '#CCCCFF'}@">
|
11
|
+
<td>@!{$i}@</td>
|
12
|
+
<td>@{$item}@</td>
|
13
|
+
</tr>
|
14
|
+
<?perl } ?>
|
15
|
+
</tbody>
|
16
|
+
</table>
|
@@ -0,0 +1,17 @@
|
|
1
|
+
<?php
|
2
|
+
$user = "World";
|
3
|
+
$list = array('<aaa>', 'b&b', '"ccc"');
|
4
|
+
?>
|
5
|
+
<p>Hello @{$user}@!</p>
|
6
|
+
<table>
|
7
|
+
<tbody>
|
8
|
+
<?php $i = 0 ?>
|
9
|
+
<?php foreach ($list as $item) { ?>
|
10
|
+
<?php $i++; ?>
|
11
|
+
<tr bgcolor="@!{$i % 2 == 0 ? '#FFCCCC' : '#CCCCFF'}@">
|
12
|
+
<td>@!{$i}@</td>
|
13
|
+
<td>@{$item}@</td>
|
14
|
+
</tr>
|
15
|
+
<?php } ?>
|
16
|
+
</tbody>
|
17
|
+
</table>
|
@@ -0,0 +1,15 @@
|
|
1
|
+
<?rb
|
2
|
+
user = 'Erubis'
|
3
|
+
list = ['<aaa>', 'b&b', '"ccc"']
|
4
|
+
?>
|
5
|
+
<p>Hello @{user}@!</p>
|
6
|
+
<table>
|
7
|
+
<tbody>
|
8
|
+
<?rb 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
|
+
<?rb end ?>
|
14
|
+
</tbody>
|
15
|
+
</table>
|
@@ -0,0 +1,26 @@
|
|
1
|
+
<?scheme
|
2
|
+
(let ((user "Erubis")
|
3
|
+
(items '("<aaa>" "b&b" "\"ccc\""))
|
4
|
+
(i 0))
|
5
|
+
?>
|
6
|
+
<p>Hello @!{user}@!</p>
|
7
|
+
<table>
|
8
|
+
<tbody>
|
9
|
+
<?scheme
|
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
|
+
<?scheme
|
19
|
+
) ; lambda end
|
20
|
+
items) ; for-each end
|
21
|
+
?>
|
22
|
+
</tbody>
|
23
|
+
</table>
|
24
|
+
<?scheme
|
25
|
+
) ; let end
|
26
|
+
?>
|
data/lib/erubis.rb
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
##
|
2
|
-
## $Rev:
|
3
|
-
## $Release: 2.0
|
2
|
+
## $Rev: 36 $
|
3
|
+
## $Release: 2.1.0 $
|
4
4
|
## copyright(c) 2006 kuwata-lab all rights reserved.
|
5
5
|
##
|
6
6
|
|
@@ -24,12 +24,15 @@
|
|
24
24
|
## </ul>
|
25
25
|
## END
|
26
26
|
## list = ['<aaa>', 'b&b', '"ccc"']
|
27
|
-
## eruby = Erubis::Eruby.new(
|
28
|
-
##
|
29
|
-
## puts
|
27
|
+
## eruby = Erubis::Eruby.new()
|
28
|
+
## code = eruby.convert(input)
|
29
|
+
## puts "--- code ---"
|
30
|
+
## puts code
|
30
31
|
## puts "--- result ---"
|
31
|
-
##
|
32
|
-
##
|
32
|
+
## context = Object.new
|
33
|
+
## context.instance_variable_set("@list", list)
|
34
|
+
## puts context.instance_eval(code)
|
35
|
+
## # or @list = list; puts eval(code, binding())
|
33
36
|
##
|
34
37
|
## result:
|
35
38
|
## --- source ---
|
@@ -53,6 +56,11 @@
|
|
53
56
|
|
54
57
|
|
55
58
|
require 'erubis/engine'
|
59
|
+
#require 'erubis/generator'
|
60
|
+
#require 'erubis/converter'
|
61
|
+
#require 'erubis/evaluator'
|
62
|
+
#require 'erubis/error'
|
63
|
+
#require 'erubis/context'
|
56
64
|
require 'erubis/helper'
|
57
65
|
require 'erubis/enhancer'
|
58
66
|
#require 'erubis/tiny'
|
@@ -66,5 +74,4 @@ require 'erubis/engine/eruby'
|
|
66
74
|
#require 'erubis/engine/eperl'
|
67
75
|
#require 'erubis/engine/ejavascript'
|
68
76
|
|
69
|
-
|
70
77
|
require 'erubis/local-setting'
|
@@ -0,0 +1,54 @@
|
|
1
|
+
##
|
2
|
+
## $Rev: 32 $
|
3
|
+
## $Release: 2.1.0 $
|
4
|
+
## copyright(c) 2006 kuwata-lab all rights reserved.
|
5
|
+
##
|
6
|
+
|
7
|
+
|
8
|
+
module Erubis
|
9
|
+
|
10
|
+
|
11
|
+
##
|
12
|
+
## context object for Engine#evaluate
|
13
|
+
##
|
14
|
+
## ex.
|
15
|
+
## template = <<'END'
|
16
|
+
## Hello <%= @user %>!
|
17
|
+
## <% for item in @list %>
|
18
|
+
## - <%= item %>
|
19
|
+
## <% end %>
|
20
|
+
## END
|
21
|
+
##
|
22
|
+
## context = Erubis::Context.new(:user=>'World', :list=>['a','b','c'])
|
23
|
+
## # or
|
24
|
+
## # context = Erubis::Context.new
|
25
|
+
## # context[:user] = 'World'
|
26
|
+
## # context[:list] = ['a', 'b', 'c']
|
27
|
+
##
|
28
|
+
## eruby = Erubis::Eruby.new(template)
|
29
|
+
## print eruby.evaluate(context)
|
30
|
+
##
|
31
|
+
class Context
|
32
|
+
|
33
|
+
def initialize(hash=nil)
|
34
|
+
hash.each do |name, value|
|
35
|
+
self[name] = value
|
36
|
+
end if hash
|
37
|
+
end
|
38
|
+
|
39
|
+
def [](key)
|
40
|
+
return instance_variable_get("@#{key}")
|
41
|
+
end
|
42
|
+
|
43
|
+
def []=(key, value)
|
44
|
+
return instance_variable_set("@#{key}", value)
|
45
|
+
end
|
46
|
+
|
47
|
+
def keys
|
48
|
+
return instance_variables.collect { |name| name[1,name.length-1] }
|
49
|
+
end
|
50
|
+
|
51
|
+
end
|
52
|
+
|
53
|
+
|
54
|
+
end
|