erbse 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/CHANGES.txt +828 -0
- data/MIT-LICENSE +20 -0
- data/README.md +51 -0
- data/benchmark/Makefile +6 -0
- data/benchmark/bench.rb +313 -0
- data/benchmark/bench_context.yaml +141 -0
- data/benchmark/templates/_footer.html +4 -0
- data/benchmark/templates/_header.html +52 -0
- data/benchmark/templates/bench_erb.rhtml +29 -0
- data/benchmark/templates/bench_erubis.rhtml +29 -0
- data/benchmark/templates/bench_eruby.rhtml +29 -0
- data/bin/erubis +10 -0
- data/erbse.gemspec +24 -0
- data/lib/erbse.rb +52 -0
- data/lib/erbse/context.rb +83 -0
- data/lib/erbse/converter.rb +357 -0
- data/lib/erbse/engine.rb +114 -0
- data/lib/erbse/engine/ec.rb +117 -0
- data/lib/erbse/engine/ecpp.rb +113 -0
- data/lib/erbse/engine/ejava.rb +110 -0
- data/lib/erbse/engine/ejavascript.rb +119 -0
- data/lib/erbse/engine/enhanced.rb +126 -0
- data/lib/erbse/engine/eperl.rb +95 -0
- data/lib/erbse/engine/ephp.rb +99 -0
- data/lib/erbse/engine/eruby.rb +119 -0
- data/lib/erbse/engine/escheme.rb +114 -0
- data/lib/erbse/engine/optimized.rb +127 -0
- data/lib/erbse/enhancer.rb +723 -0
- data/lib/erbse/error.rb +23 -0
- data/lib/erbse/evaluator.rb +88 -0
- data/lib/erbse/generator.rb +85 -0
- data/lib/erbse/helper.rb +47 -0
- data/lib/erbse/helpers/rails_form_helper.rb +197 -0
- data/lib/erbse/helpers/rails_helper.rb +353 -0
- data/lib/erbse/main.rb +516 -0
- data/lib/erbse/preprocessing.rb +58 -0
- data/lib/erbse/tiny.rb +144 -0
- data/lib/erbse/util.rb +22 -0
- data/lib/erbse/version.rb +3 -0
- data/test/assert-text-equal.rb +44 -0
- data/test/data/users-guide/Example.ejava +55 -0
- data/test/data/users-guide/array_example.result +9 -0
- data/test/data/users-guide/arraybuffer_example.result +9 -0
- data/test/data/users-guide/bipattern-example.rhtml +4 -0
- data/test/data/users-guide/bipattern_example.result +6 -0
- data/test/data/users-guide/bufvar-example.rb +10 -0
- data/test/data/users-guide/bufvar-example.result +17 -0
- data/test/data/users-guide/context.rb +6 -0
- data/test/data/users-guide/context.yaml +8 -0
- data/test/data/users-guide/def_method.rb +14 -0
- data/test/data/users-guide/def_method.result +3 -0
- data/test/data/users-guide/escape_example.result +9 -0
- data/test/data/users-guide/example.ec +27 -0
- data/test/data/users-guide/example.ecpp +30 -0
- data/test/data/users-guide/example.ejs +20 -0
- data/test/data/users-guide/example.eperl +18 -0
- data/test/data/users-guide/example.ephp +18 -0
- data/test/data/users-guide/example.eruby +6 -0
- data/test/data/users-guide/example.escheme +28 -0
- data/test/data/users-guide/example1.eruby +6 -0
- data/test/data/users-guide/example1.rb +17 -0
- data/test/data/users-guide/example1.result +16 -0
- data/test/data/users-guide/example10.rb +4 -0
- data/test/data/users-guide/example10.result +17 -0
- data/test/data/users-guide/example10.xhtml +14 -0
- data/test/data/users-guide/example10_x.result +17 -0
- data/test/data/users-guide/example11.php +20 -0
- data/test/data/users-guide/example11.result +23 -0
- data/test/data/users-guide/example11.rhtml +21 -0
- data/test/data/users-guide/example11_C.result +10 -0
- data/test/data/users-guide/example11_N.result +16 -0
- data/test/data/users-guide/example11_U.result +16 -0
- data/test/data/users-guide/example11_php.result +15 -0
- data/test/data/users-guide/example1_x.result +9 -0
- data/test/data/users-guide/example2.eruby +7 -0
- data/test/data/users-guide/example2.rb +10 -0
- data/test/data/users-guide/example2.result +27 -0
- data/test/data/users-guide/example2_trim.result +10 -0
- data/test/data/users-guide/example2_x.result +10 -0
- data/test/data/users-guide/example3.eruby +6 -0
- data/test/data/users-guide/example3.rb +10 -0
- data/test/data/users-guide/example31.result +22 -0
- data/test/data/users-guide/example32.result +4 -0
- data/test/data/users-guide/example3_e.result +8 -0
- data/test/data/users-guide/example4.eruby +3 -0
- data/test/data/users-guide/example4.rb +11 -0
- data/test/data/users-guide/example4.result +10 -0
- data/test/data/users-guide/example4_x.result +5 -0
- data/test/data/users-guide/example5.eruby +6 -0
- data/test/data/users-guide/example5.rb +16 -0
- data/test/data/users-guide/example5.result +7 -0
- data/test/data/users-guide/example6.rb +12 -0
- data/test/data/users-guide/example6.result +7 -0
- data/test/data/users-guide/example7.eruby +8 -0
- data/test/data/users-guide/example71.result +13 -0
- data/test/data/users-guide/example72.result +13 -0
- data/test/data/users-guide/example8.eruby +6 -0
- data/test/data/users-guide/example8_ruby.result +7 -0
- data/test/data/users-guide/example8_yaml.result +7 -0
- data/test/data/users-guide/example9.eruby +3 -0
- data/test/data/users-guide/example9.rb +8 -0
- data/test/data/users-guide/example9.result +9 -0
- data/test/data/users-guide/example91.result +5 -0
- data/test/data/users-guide/example92.result +4 -0
- data/test/data/users-guide/example_c.result +32 -0
- data/test/data/users-guide/example_java.result +56 -0
- data/test/data/users-guide/example_js.result +22 -0
- data/test/data/users-guide/example_perl.result +20 -0
- data/test/data/users-guide/example_php.result +19 -0
- data/test/data/users-guide/example_scheme.result +30 -0
- data/test/data/users-guide/example_scheme_display.result +29 -0
- data/test/data/users-guide/fasteruby-example.rb +8 -0
- data/test/data/users-guide/fasteruby-example.result +18 -0
- data/test/data/users-guide/fasteruby.rb +11 -0
- data/test/data/users-guide/fasteruby.result +38 -0
- data/test/data/users-guide/fasteruby.rhtml +15 -0
- data/test/data/users-guide/headerfooter-example.eruby +9 -0
- data/test/data/users-guide/headerfooter-example2.rb +8 -0
- data/test/data/users-guide/headerfooter-example2.rhtml +10 -0
- data/test/data/users-guide/headerfooter_example.result +11 -0
- data/test/data/users-guide/headerfooter_example2.result +13 -0
- data/test/data/users-guide/interpolation_example.result +9 -0
- data/test/data/users-guide/main_program1.rb +8 -0
- data/test/data/users-guide/main_program1.result +6 -0
- data/test/data/users-guide/main_program2.rb +8 -0
- data/test/data/users-guide/main_program2.result +6 -0
- data/test/data/users-guide/nocode-example.eruby +14 -0
- data/test/data/users-guide/nocode-php.result +20 -0
- data/test/data/users-guide/nocode_example.result +15 -0
- data/test/data/users-guide/normal-eruby-test.eruby +9 -0
- data/test/data/users-guide/normal_eruby_test.result +11 -0
- data/test/data/users-guide/notext-example.eruby +14 -0
- data/test/data/users-guide/notext-example.php +19 -0
- data/test/data/users-guide/notext-php.result +20 -0
- data/test/data/users-guide/notext_example.result +16 -0
- data/test/data/users-guide/percentline-example.rhtml +6 -0
- data/test/data/users-guide/percentline_example.result +9 -0
- data/test/data/users-guide/prefixedline-example.rb +9 -0
- data/test/data/users-guide/prefixedline-example.rhtml +6 -0
- data/test/data/users-guide/prefixedline_example.result +9 -0
- data/test/data/users-guide/printenable_example.result +4 -0
- data/test/data/users-guide/printenabled-example.eruby +3 -0
- data/test/data/users-guide/printenabled-example.rb +8 -0
- data/test/data/users-guide/printstatement_example.result +8 -0
- data/test/data/users-guide/simplify_example.result +9 -0
- data/test/data/users-guide/stderr.log +3 -0
- data/test/data/users-guide/stdout_exmple.result +9 -0
- data/test/data/users-guide/stringbuffer_example.result +9 -0
- data/test/data/users-guide/tail_260.result +4 -0
- data/test/data/users-guide/tailnewline.rhtml +3 -0
- data/test/data/users-guide/template1.rhtml +4 -0
- data/test/data/users-guide/template2.rhtml +4 -0
- data/test/test-engines.rb +425 -0
- data/test/test-enhancers.rb +646 -0
- data/test/test-erubis.rb +887 -0
- data/test/test-index-cgi.rb +191 -0
- data/test/test-main.rb +752 -0
- data/test/test-users-guide.rb +73 -0
- data/test/test.rb +45 -0
- data/test/testutil.rb +111 -0
- metadata +233 -0
@@ -0,0 +1,27 @@
|
|
1
|
+
<%
|
2
|
+
#include <stdio.h>
|
3
|
+
|
4
|
+
int main(int argc, char *argv[])
|
5
|
+
{
|
6
|
+
int i;
|
7
|
+
|
8
|
+
%>
|
9
|
+
<html>
|
10
|
+
<body>
|
11
|
+
<p>Hello <%= "%s", 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><%= "%s", argv[i] %></td>
|
18
|
+
</tr>
|
19
|
+
<% } %>
|
20
|
+
</tbody>
|
21
|
+
</table>
|
22
|
+
</body>
|
23
|
+
</html>
|
24
|
+
<%
|
25
|
+
return 0;
|
26
|
+
}
|
27
|
+
%>
|
@@ -0,0 +1,30 @@
|
|
1
|
+
<%
|
2
|
+
#include <string>
|
3
|
+
#include <iostream>
|
4
|
+
#include <sstream>
|
5
|
+
|
6
|
+
int main(int argc, char *argv[])
|
7
|
+
{
|
8
|
+
std::stringstream _buf;
|
9
|
+
%>
|
10
|
+
<html>
|
11
|
+
<body>
|
12
|
+
<p>Hello <%= argv[0] %>!</p>
|
13
|
+
<table>
|
14
|
+
<tbody>
|
15
|
+
<% for (int i = 1; i < argc; i++) { %>
|
16
|
+
<tr bgcolor="<%= i % 2 == 0 ? "#FFCCCC" : "#CCCCFF" %>">
|
17
|
+
<td><%= i %></td>
|
18
|
+
<td><%= argv[i] %></td>
|
19
|
+
</tr>
|
20
|
+
<% } %>
|
21
|
+
</tbody>
|
22
|
+
</table>
|
23
|
+
</body>
|
24
|
+
</html>
|
25
|
+
<%
|
26
|
+
std::string output = _buf.str();
|
27
|
+
std::cout << output;
|
28
|
+
return 0;
|
29
|
+
}
|
30
|
+
%>
|
@@ -0,0 +1,20 @@
|
|
1
|
+
<%
|
2
|
+
var user = 'Erubis';
|
3
|
+
var list = ['<aaa>', 'b&b', '"ccc"'];
|
4
|
+
%>
|
5
|
+
<html>
|
6
|
+
<body>
|
7
|
+
<p>Hello <%= user %>!</p>
|
8
|
+
<table>
|
9
|
+
<tbody>
|
10
|
+
<% var i; %>
|
11
|
+
<% for (i = 0; i < list.length; i++) { %>
|
12
|
+
<tr bgcolor="<%= i % 2 == 0 ? '#FFCCCC' : '#CCCCFF' %>">
|
13
|
+
<td><%= i + 1 %></td>
|
14
|
+
<td><%= list[i] %></td>
|
15
|
+
</tr>
|
16
|
+
<% } %>
|
17
|
+
</tbody>
|
18
|
+
</table>
|
19
|
+
</body>
|
20
|
+
</html>
|
@@ -0,0 +1,18 @@
|
|
1
|
+
<%
|
2
|
+
my $user = 'Erubis';
|
3
|
+
my @list = ('<aaa>', 'b&b', '"ccc"');
|
4
|
+
%>
|
5
|
+
<html>
|
6
|
+
<body>
|
7
|
+
<p>Hello <%= $user %>!</p>
|
8
|
+
<table>
|
9
|
+
<% $i = 0; %>
|
10
|
+
<% for $item (@list) { %>
|
11
|
+
<tr bgcolor=<%= ++$i % 2 == 0 ? '#FFCCCC' : '#CCCCFF' %>">
|
12
|
+
<td><%= $i %></td>
|
13
|
+
<td><%= $item %></td>
|
14
|
+
</tr>
|
15
|
+
<% } %>
|
16
|
+
</table>
|
17
|
+
</body>
|
18
|
+
</html>
|
@@ -0,0 +1,18 @@
|
|
1
|
+
<?xml version="1.0"?>
|
2
|
+
<html>
|
3
|
+
<body>
|
4
|
+
<p>Hello <%= $user %>!</p>
|
5
|
+
<table>
|
6
|
+
<tbody>
|
7
|
+
<% $i = 0; %>
|
8
|
+
<% foreach ($list as $item) { %>
|
9
|
+
<% $i++; %>
|
10
|
+
<tr bgcolor="<%= $i % 2 == 0 ? '#FFCCCC' : '#CCCCFF' %>">
|
11
|
+
<td><%= $i %></td>
|
12
|
+
<td><%== $item %></td>
|
13
|
+
</tr>
|
14
|
+
<% } %>
|
15
|
+
</tbody>
|
16
|
+
</table>
|
17
|
+
</body>
|
18
|
+
</html>
|
@@ -0,0 +1,28 @@
|
|
1
|
+
<html>
|
2
|
+
<body>
|
3
|
+
<%
|
4
|
+
(let ((user "Erubis")
|
5
|
+
(items '("<aaa>" "b&b" "\"ccc\""))
|
6
|
+
(i 0))
|
7
|
+
%>
|
8
|
+
<p>Hello <%= user %>!</p>
|
9
|
+
<table>
|
10
|
+
<%
|
11
|
+
(for-each
|
12
|
+
(lambda (item)
|
13
|
+
(set! i (+ i 1))
|
14
|
+
%>
|
15
|
+
<tr bgcolor="<%= (if (= (modulo i 2) 0) "#FFCCCC" "#CCCCFF") %>">
|
16
|
+
<td><%= i %></td>
|
17
|
+
<td><%= item %></td>
|
18
|
+
</tr>
|
19
|
+
<%
|
20
|
+
) ; lambda end
|
21
|
+
items) ; for-each end
|
22
|
+
%>
|
23
|
+
</table>
|
24
|
+
<%
|
25
|
+
) ; let end
|
26
|
+
%>
|
27
|
+
</body>
|
28
|
+
</html>
|
@@ -0,0 +1,17 @@
|
|
1
|
+
require 'erubis'
|
2
|
+
input = File.read('example1.eruby')
|
3
|
+
eruby = Erubis::Eruby.new(input) # create Eruby object
|
4
|
+
|
5
|
+
puts "---------- script source ---"
|
6
|
+
puts eruby.src # print script source
|
7
|
+
|
8
|
+
puts "---------- result ----------"
|
9
|
+
list = ['aaa', 'bbb', 'ccc']
|
10
|
+
puts eruby.result(binding()) # get result
|
11
|
+
## or puts eruby.result(:list=>list) # or pass Hash instead of Binding
|
12
|
+
|
13
|
+
## # or
|
14
|
+
## eruby = Erubis::Eruby.new
|
15
|
+
## input = File.read('example1.eruby')
|
16
|
+
## src = eruby.convert(input)
|
17
|
+
## eval src
|
@@ -0,0 +1,16 @@
|
|
1
|
+
$ ruby example1.rb
|
2
|
+
---------- script source ---
|
3
|
+
_buf = ''; _buf << '<ul>
|
4
|
+
'; for item in list
|
5
|
+
_buf << ' <li>'; _buf << ( item ).to_s; _buf << '</li>
|
6
|
+
'; end
|
7
|
+
|
8
|
+
_buf << '</ul>
|
9
|
+
';
|
10
|
+
_buf.to_s
|
11
|
+
---------- result ----------
|
12
|
+
<ul>
|
13
|
+
<li>aaa</li>
|
14
|
+
<li>bbb</li>
|
15
|
+
<li>ccc</li>
|
16
|
+
</ul>
|
@@ -0,0 +1,17 @@
|
|
1
|
+
$ ruby example10.rb
|
2
|
+
_buf = ''; _buf << '<?xml version="1.0" ?>
|
3
|
+
';
|
4
|
+
lang = 'en'
|
5
|
+
list = ['<aaa>', 'b&b', '"ccc"']
|
6
|
+
|
7
|
+
_buf << '<html lang="'; _buf << (lang).to_s; _buf << '">
|
8
|
+
<body>
|
9
|
+
<ul>
|
10
|
+
'; for item in list
|
11
|
+
_buf << ' <li>'; _buf << Erubis::XmlHelper.escape_xml(item); _buf << '</li>
|
12
|
+
'; end
|
13
|
+
_buf << ' </ul>
|
14
|
+
</body>
|
15
|
+
</html>
|
16
|
+
';
|
17
|
+
_buf.to_s
|
@@ -0,0 +1,17 @@
|
|
1
|
+
$ erubis -x --pi example10.xhtml
|
2
|
+
_buf = ''; _buf << '<?xml version="1.0" ?>
|
3
|
+
';
|
4
|
+
lang = 'en'
|
5
|
+
list = ['<aaa>', 'b&b', '"ccc"']
|
6
|
+
|
7
|
+
_buf << '<html lang="'; _buf << (lang).to_s; _buf << '">
|
8
|
+
<body>
|
9
|
+
<ul>
|
10
|
+
'; for item in list
|
11
|
+
_buf << ' <li>'; _buf << Erubis::XmlHelper.escape_xml(item); _buf << '</li>
|
12
|
+
'; end
|
13
|
+
_buf << ' </ul>
|
14
|
+
</body>
|
15
|
+
</html>
|
16
|
+
';
|
17
|
+
_buf.to_s
|
@@ -0,0 +1,20 @@
|
|
1
|
+
<?xml version="1.0"?>
|
2
|
+
<html>
|
3
|
+
<body>
|
4
|
+
<h3>List</h3>
|
5
|
+
<?php if (!$list) { ?>
|
6
|
+
<p>not found.</p>
|
7
|
+
<?php } else { ?>
|
8
|
+
<table>
|
9
|
+
<tbody>
|
10
|
+
<?php $i = 0; ?>
|
11
|
+
<?php foreach ($list as $item) { ?>
|
12
|
+
<tr bgcolor="<?php echo ++$i % 2 == 1 ? '#FCC' : '#CCF'; ?>">
|
13
|
+
<td><?php echo $item; ?></td>
|
14
|
+
</tr>
|
15
|
+
<?php } ?>
|
16
|
+
</tbody>
|
17
|
+
</table>
|
18
|
+
<?php } ?>
|
19
|
+
</body>
|
20
|
+
</html>
|
@@ -0,0 +1,23 @@
|
|
1
|
+
$ erubis -X example11.rhtml
|
2
|
+
_buf = '';
|
3
|
+
|
4
|
+
|
5
|
+
|
6
|
+
|
7
|
+
|
8
|
+
if @list.nil? || @list.empty?
|
9
|
+
|
10
|
+
else
|
11
|
+
|
12
|
+
|
13
|
+
@list.each_with_index do |item, i|
|
14
|
+
_buf << ( i % 2 == 0 ? '#FCC' : '#CCF' ).to_s;
|
15
|
+
_buf << ( item ).to_s;
|
16
|
+
|
17
|
+
end
|
18
|
+
|
19
|
+
|
20
|
+
end
|
21
|
+
|
22
|
+
|
23
|
+
_buf.to_s
|
@@ -0,0 +1,21 @@
|
|
1
|
+
<?xml version="1.0" encoding="UTF-8"?>
|
2
|
+
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
|
3
|
+
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
|
4
|
+
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
|
5
|
+
<body>
|
6
|
+
<h3>List</h3>
|
7
|
+
<% if @list.nil? || @list.empty? %>
|
8
|
+
<p>not found.</p>
|
9
|
+
<% else %>
|
10
|
+
<table>
|
11
|
+
<tbody>
|
12
|
+
<% @list.each_with_index do |item, i| %>
|
13
|
+
<tr bgcolor="<%= i % 2 == 0 ? '#FCC' : '#CCF' %>">
|
14
|
+
<td><%= item %></td>
|
15
|
+
</tr>
|
16
|
+
<% end %>
|
17
|
+
</tbody>
|
18
|
+
</table>
|
19
|
+
<% end %>
|
20
|
+
</body>
|
21
|
+
</html>
|
@@ -0,0 +1,16 @@
|
|
1
|
+
$ erubis -XNU example11.rhtml
|
2
|
+
1: _buf = '';
|
3
|
+
|
4
|
+
7: if @list.nil? || @list.empty?
|
5
|
+
|
6
|
+
9: else
|
7
|
+
|
8
|
+
12: @list.each_with_index do |item, i|
|
9
|
+
13: _buf << ( i % 2 == 0 ? '#FCC' : '#CCF' ).to_s;
|
10
|
+
14: _buf << ( item ).to_s;
|
11
|
+
|
12
|
+
16: end
|
13
|
+
|
14
|
+
19: end
|
15
|
+
|
16
|
+
22: _buf.to_s
|
@@ -0,0 +1,15 @@
|
|
1
|
+
$ erubis -XNU -l php --pi=php --trim=false example11.php
|
2
|
+
|
3
|
+
5: <?php if (!$list) { ?>
|
4
|
+
|
5
|
+
7: <?php } else { ?>
|
6
|
+
|
7
|
+
10: <?php $i = 0; ?>
|
8
|
+
11: <?php foreach ($list as $item) { ?>
|
9
|
+
12: <?php echo ++$i % 2 == 1 ? '#FCC' : '#CCF'; ?>
|
10
|
+
13: <?php echo $item; ?>
|
11
|
+
|
12
|
+
15: <?php } ?>
|
13
|
+
|
14
|
+
18: <?php } ?>
|
15
|
+
|
@@ -0,0 +1,10 @@
|
|
1
|
+
require 'erubis'
|
2
|
+
input = File.read('example2.eruby')
|
3
|
+
eruby = Erubis::Eruby.new(input, :trim=>false)
|
4
|
+
|
5
|
+
puts "----- script source ---"
|
6
|
+
puts eruby.src # print script source
|
7
|
+
|
8
|
+
puts "----- result ----------"
|
9
|
+
list = ['aaa', 'bbb', 'ccc']
|
10
|
+
puts eruby.result(binding()) # get result
|
@@ -0,0 +1,27 @@
|
|
1
|
+
$ ruby example2.rb
|
2
|
+
----- script source ---
|
3
|
+
_buf = ''; _buf << '<ul>
|
4
|
+
'; _buf << ' '; for item in list ; _buf << '
|
5
|
+
'; _buf << ' <li>
|
6
|
+
'; _buf << ( item ).to_s; _buf << '
|
7
|
+
'; _buf << ' </li>
|
8
|
+
'; _buf << ' '; end ; _buf << '
|
9
|
+
'; _buf << '</ul>
|
10
|
+
';
|
11
|
+
_buf.to_s
|
12
|
+
----- result ----------
|
13
|
+
<ul>
|
14
|
+
|
15
|
+
<li>
|
16
|
+
aaa
|
17
|
+
</li>
|
18
|
+
|
19
|
+
<li>
|
20
|
+
bbb
|
21
|
+
</li>
|
22
|
+
|
23
|
+
<li>
|
24
|
+
ccc
|
25
|
+
</li>
|
26
|
+
|
27
|
+
</ul>
|