erubis 2.0.1 → 2.1.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.
Files changed (145) hide show
  1. data/ChangeLog +150 -2
  2. data/LGPL +504 -0
  3. data/README.txt +14 -8
  4. data/benchmark/erubybench.rb +1 -1
  5. data/benchmark/erubybench.rhtml +3 -3
  6. data/bin/erubis +1 -1
  7. data/bin/notext +154 -0
  8. data/contrib/erubis +1036 -374
  9. data/contrib/inline-require +5 -3
  10. data/doc-api/classes/Erubis.html +43 -1
  11. data/doc-api/classes/Erubis/ArrayBufferEnhancer.html +14 -14
  12. data/doc-api/classes/Erubis/ArrayEnhancer.html +14 -14
  13. data/doc-api/classes/Erubis/Basic.html +112 -0
  14. data/doc-api/classes/Erubis/Basic/Converter.html +318 -0
  15. data/doc-api/classes/Erubis/Basic/Engine.html +130 -0
  16. data/doc-api/classes/Erubis/BiPatternEnhancer.html +14 -14
  17. data/doc-api/classes/Erubis/CGenerator.html +386 -0
  18. data/doc-api/classes/Erubis/Context.html +31 -32
  19. data/doc-api/classes/Erubis/Converter.html +231 -0
  20. data/doc-api/classes/Erubis/Ec.html +9 -283
  21. data/doc-api/classes/Erubis/Ejava.html +9 -274
  22. data/doc-api/classes/Erubis/Ejavascript.html +9 -298
  23. data/doc-api/classes/Erubis/Engine.html +68 -508
  24. data/doc-api/classes/Erubis/Eperl.html +9 -259
  25. data/doc-api/classes/Erubis/Ephp.html +9 -239
  26. data/doc-api/classes/Erubis/ErubisError.html +2 -2
  27. data/doc-api/classes/Erubis/Eruby.html +4 -187
  28. data/doc-api/classes/Erubis/EscapeEnhancer.html +9 -11
  29. data/doc-api/classes/Erubis/Escheme.html +9 -272
  30. data/doc-api/classes/Erubis/Evaluator.html +212 -0
  31. data/doc-api/classes/Erubis/Generator.html +410 -0
  32. data/doc-api/classes/Erubis/HeaderFooterEnhancer.html +16 -16
  33. data/doc-api/classes/Erubis/Helper.html +112 -0
  34. data/doc-api/classes/Erubis/Helper/CachedRailsTemplate.html +198 -0
  35. data/doc-api/classes/Erubis/Helper/RailsTemplate.html +366 -0
  36. data/doc-api/classes/Erubis/JavaGenerator.html +359 -0
  37. data/doc-api/classes/Erubis/JavascriptGenerator.html +381 -0
  38. data/doc-api/classes/Erubis/Main.html +27 -25
  39. data/doc-api/classes/Erubis/NoCodeEnhancer.html +249 -0
  40. data/doc-api/classes/Erubis/NoCodeEruby.html +120 -0
  41. data/doc-api/classes/Erubis/NoTextEnhancer.html +8 -8
  42. data/doc-api/classes/Erubis/NotSupportedError.html +119 -0
  43. data/doc-api/classes/Erubis/OptimizedEruby.html +22 -304
  44. data/doc-api/classes/Erubis/OptimizedGenerator.html +439 -0
  45. data/doc-api/classes/Erubis/OptimizedXmlEruby.html +7 -7
  46. data/doc-api/classes/Erubis/PI.html +124 -0
  47. data/doc-api/classes/Erubis/PI/Converter.html +318 -0
  48. data/doc-api/classes/Erubis/PI/Ec.html +166 -0
  49. data/doc-api/classes/Erubis/PI/Ejava.html +166 -0
  50. data/doc-api/classes/Erubis/PI/Ejavascript.html +166 -0
  51. data/doc-api/classes/Erubis/PI/Engine.html +122 -0
  52. data/doc-api/classes/Erubis/PI/Eperl.html +166 -0
  53. data/doc-api/classes/Erubis/PI/Ephp.html +166 -0
  54. data/doc-api/classes/Erubis/PI/Eruby.html +155 -0
  55. data/doc-api/classes/Erubis/PI/Escheme.html +166 -0
  56. data/doc-api/classes/Erubis/PI/TinyEruby.html +305 -0
  57. data/doc-api/classes/Erubis/PercentLineEnhancer.html +7 -7
  58. data/doc-api/classes/Erubis/PerlGenerator.html +344 -0
  59. data/doc-api/classes/Erubis/PhpGenerator.html +350 -0
  60. data/doc-api/classes/Erubis/PrintEnabledEnhancer.html +24 -24
  61. data/doc-api/classes/Erubis/PrintOutEnhancer.html +35 -35
  62. data/doc-api/classes/Erubis/RubyEvaluator.html +190 -0
  63. data/doc-api/classes/Erubis/RubyGenerator.html +327 -0
  64. data/doc-api/classes/Erubis/SchemeGenerator.html +382 -0
  65. data/doc-api/classes/Erubis/SimplifyEnhancer.html +17 -13
  66. data/doc-api/classes/Erubis/StdoutEnhancer.html +14 -14
  67. data/doc-api/classes/Erubis/StringBufferEnhancer.html +14 -14
  68. data/doc-api/classes/Erubis/TinyEruby.html +45 -40
  69. data/doc-api/classes/Erubis/XmlHelper.html +14 -14
  70. data/doc-api/created.rid +1 -1
  71. data/doc-api/files/__/README_txt.html +27 -9
  72. data/doc-api/files/erubis/context_rb.html +107 -0
  73. data/doc-api/files/erubis/converter_rb.html +114 -0
  74. data/doc-api/files/erubis/engine/ec_rb.html +2 -2
  75. data/doc-api/files/erubis/engine/ejava_rb.html +2 -2
  76. data/doc-api/files/erubis/engine/ejavascript_rb.html +2 -2
  77. data/doc-api/files/erubis/engine/enhanced_rb.html +2 -2
  78. data/doc-api/files/erubis/engine/eperl_rb.html +2 -2
  79. data/doc-api/files/erubis/engine/ephp_rb.html +2 -2
  80. data/doc-api/files/erubis/engine/eruby_rb.html +3 -2
  81. data/doc-api/files/erubis/engine/escheme_rb.html +2 -2
  82. data/doc-api/files/erubis/engine/optimized_rb.html +2 -2
  83. data/doc-api/files/erubis/engine_rb.html +6 -3
  84. data/doc-api/files/erubis/enhancer_rb.html +2 -9
  85. data/doc-api/files/erubis/error_rb.html +107 -0
  86. data/doc-api/files/erubis/evaluator_rb.html +115 -0
  87. data/doc-api/files/erubis/generator_rb.html +114 -0
  88. data/doc-api/files/erubis/helper/rails_rb.html +140 -0
  89. data/doc-api/files/erubis/helper_rb.html +1 -1
  90. data/doc-api/files/erubis/local-setting_rb.html +1 -1
  91. data/doc-api/files/erubis/main_rb.html +2 -2
  92. data/doc-api/files/erubis/tiny_rb.html +2 -2
  93. data/doc-api/files/erubis_rb.html +2 -2
  94. data/doc-api/fr_class_index.html +32 -0
  95. data/doc-api/fr_file_index.html +6 -0
  96. data/doc-api/fr_method_index.html +178 -136
  97. data/doc/users-guide.html +538 -199
  98. data/examples/{Makefile → basic/Makefile} +11 -11
  99. data/examples/basic/example.ec +42 -0
  100. data/examples/{example.ejava → basic/example.ejava} +5 -1
  101. data/examples/{example.ejavascript → basic/example.ejs} +0 -0
  102. data/examples/{example.eperl → basic/example.eperl} +2 -2
  103. data/examples/{example.ephp → basic/example.ephp} +0 -0
  104. data/examples/{example.eruby → basic/example.eruby} +0 -0
  105. data/examples/{example.escheme → basic/example.escheme} +0 -0
  106. data/examples/pi/Makefile +54 -0
  107. data/examples/pi/example.ec +42 -0
  108. data/examples/pi/example.ejava +45 -0
  109. data/examples/pi/example.ejs +16 -0
  110. data/examples/pi/example.eperl +16 -0
  111. data/examples/pi/example.ephp +17 -0
  112. data/examples/pi/example.eruby +15 -0
  113. data/examples/pi/example.escheme +26 -0
  114. data/lib/erubis.rb +15 -8
  115. data/lib/erubis/context.rb +54 -0
  116. data/lib/erubis/converter.rb +307 -0
  117. data/lib/erubis/engine.rb +57 -227
  118. data/lib/erubis/engine/ec.rb +31 -20
  119. data/lib/erubis/engine/ejava.rb +33 -21
  120. data/lib/erubis/engine/ejavascript.rb +30 -18
  121. data/lib/erubis/engine/enhanced.rb +7 -2
  122. data/lib/erubis/engine/eperl.rb +33 -19
  123. data/lib/erubis/engine/ephp.rb +32 -14
  124. data/lib/erubis/engine/eruby.rb +34 -7
  125. data/lib/erubis/engine/escheme.rb +34 -15
  126. data/lib/erubis/engine/optimized.rb +25 -11
  127. data/lib/erubis/enhancer.rb +53 -19
  128. data/lib/erubis/error.rb +24 -0
  129. data/lib/erubis/evaluator.rb +71 -0
  130. data/lib/erubis/generator.rb +83 -0
  131. data/lib/erubis/helper.rb +1 -1
  132. data/lib/erubis/helper/rails.rb +159 -0
  133. data/lib/erubis/local-setting.rb +1 -1
  134. data/lib/erubis/main.rb +87 -46
  135. data/lib/erubis/tiny.rb +81 -7
  136. data/test/assert-text-equal.rb +1 -1
  137. data/test/test-engines.rb +8 -9
  138. data/test/test-erubis.rb +196 -18
  139. data/test/{test-bin.rb → test-main.rb} +123 -21
  140. data/test/test-notext.rb +27 -0
  141. data/test/test.rb +5 -3
  142. data/test/testutil.rb +25 -36
  143. metadata +75 -13
  144. data/COPYING +0 -340
  145. 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 -l c example.ec > example.c
13
+ erubis -bl c example.ec > example.c
14
14
 
15
15
  example.java: example.ejava
16
- erubis -l java example.ejava > example.java
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.ejavascript
26
- erubis -l javascript example.ejavascript > example.js
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.ejavascript Makefile
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: a.out example.class
37
+ compile: example.bin example.class
38
38
 
39
- a.out: example.c
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) a.out example.class
45
+ output: $(all) example.bin example.class
46
46
  erubis example.eruby > example.ruby.out
47
47
  php example.php > example.php.out
48
- ./a.out foo bar baz > example.c.out
49
- java example > example.java.out
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("&amp;", out); break;
33
+ case '>': fputs("&gt;", out); break;
34
+ case '<': fputs("&lt;", out); break;
35
+ case '"': fputs("&quot;", out); break;
36
+ case '\'': fputs("&#039;", 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 <%= user %>!</p>
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
  %>
@@ -2,14 +2,14 @@
2
2
  my $user = 'Erubis';
3
3
  my @list = ('<aaa>', 'b&b', '"ccc"');
4
4
  %>
5
- <p>Hello <%= $user %>!</p>
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><%= $item %></td>
12
+ <td><%== $item %></td>
13
13
  </tr>
14
14
  <% } %>
15
15
  </tbody>
@@ -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("&amp;", out); break;
33
+ case '>': fputs("&gt;", out); break;
34
+ case '<': fputs("&lt;", out); break;
35
+ case '"': fputs("&quot;", out); break;
36
+ case '\'': fputs("&#039;", 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("&lt;"); break;
32
+ case '>': sb.append("&gt;"); break;
33
+ case '&': sb.append("&amp;"); break;
34
+ case '"': sb.append("&quot;"); 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
+ ?>
@@ -1,6 +1,6 @@
1
1
  ##
2
- ## $Rev: 21 $
3
- ## $Release: 2.0.1 $
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(input)
28
- ## puts "--- source ---"
29
- ## puts eruby.src
27
+ ## eruby = Erubis::Eruby.new()
28
+ ## code = eruby.convert(input)
29
+ ## puts "--- code ---"
30
+ ## puts code
30
31
  ## puts "--- result ---"
31
- ## puts eruby.evaluate(:list=>list)
32
- ## # or puts eruby.result(binding())
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