tenjin 0.6.0
Sign up to get free protection for your applications and to get access to all the features.
- data/MIT-LICENSE +20 -0
- data/README.txt +54 -0
- data/benchmark/bench.rb +502 -0
- data/benchmark/bench_context.rb +17 -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_eruby.rhtml +29 -0
- data/benchmark/templates/bench_tenjin.rbhtml +29 -0
- data/bin/rbtenjin +449 -0
- data/doc-api/classes/Tenjin.html +141 -0
- data/doc-api/classes/Tenjin/ArrayBufferTemplate.html +270 -0
- data/doc-api/classes/Tenjin/BaseContext.html +312 -0
- data/doc-api/classes/Tenjin/Context.html +126 -0
- data/doc-api/classes/Tenjin/ContextHelper.html +433 -0
- data/doc-api/classes/Tenjin/Engine.html +616 -0
- data/doc-api/classes/Tenjin/ErubisTemplate.html +166 -0
- data/doc-api/classes/Tenjin/HtmlHelper.html +359 -0
- data/doc-api/classes/Tenjin/Preprocessor.html +242 -0
- data/doc-api/classes/Tenjin/Template.html +916 -0
- data/doc-api/created.rid +1 -0
- data/doc-api/files/README_txt.html +185 -0
- data/doc-api/files/lib/tenjin_rb.html +136 -0
- data/doc-api/fr_class_index.html +36 -0
- data/doc-api/fr_file_index.html +28 -0
- data/doc-api/fr_method_index.html +89 -0
- data/doc-api/index.html +24 -0
- data/doc-api/rdoc-style.css +208 -0
- data/doc/docstyle.css +188 -0
- data/doc/examples.html +312 -0
- data/doc/faq.html +909 -0
- data/doc/users-guide.html +1691 -0
- data/lib/tenjin.rb +959 -0
- data/setup.rb +1331 -0
- data/tenjin.gemspec +58 -0
- data/test/assert-text-equal.rb +45 -0
- data/test/data/examples/form/create.rbhtml +4 -0
- data/test/data/examples/form/form.rbhtml +14 -0
- data/test/data/examples/form/layout.rbhtml +8 -0
- data/test/data/examples/form/main.rb +9 -0
- data/test/data/examples/form/main.result +21 -0
- data/test/data/examples/form/update.rbhtml +4 -0
- data/test/data/examples/preprocessing/helper.rb +16 -0
- data/test/data/examples/preprocessing/main.rb +11 -0
- data/test/data/examples/preprocessing/main.result +17 -0
- data/test/data/examples/preprocessing/select.rbhtml +15 -0
- data/test/data/examples/preprocessing/select_P.result +18 -0
- data/test/data/examples/table/table.rb +9 -0
- data/test/data/examples/table/table.rbhtml +16 -0
- data/test/data/examples/table/table.result +20 -0
- data/test/data/examples/table/table_s.result +18 -0
- data/test/data/faq/ex1.rbhtml +5 -0
- data/test/data/faq/ex10-baselayout.rbhtml +27 -0
- data/test/data/faq/ex10-content.rbhtml +12 -0
- data/test/data/faq/ex10-customlayout.rbhtml +11 -0
- data/test/data/faq/ex10_inherit.result +25 -0
- data/test/data/faq/ex11-bench.rb +28 -0
- data/test/data/faq/ex11-content.rbhtml +9 -0
- data/test/data/faq/ex11-layout1.rbhtml +5 -0
- data/test/data/faq/ex11-layout2.rbhtml +6 -0
- data/test/data/faq/ex11.rb +5 -0
- data/test/data/faq/ex11.rbhtml +8 -0
- data/test/data/faq/ex11.source +11 -0
- data/test/data/faq/ex11_arraybuffer.result +15 -0
- data/test/data/faq/ex1_chksyntax.result +3 -0
- data/test/data/faq/ex2-content.rbhtml +3 -0
- data/test/data/faq/ex2-layout.rbhtml +11 -0
- data/test/data/faq/ex2_removenl.result +19 -0
- data/test/data/faq/ex3.rb +4 -0
- data/test/data/faq/ex3.rbhtml +1 -0
- data/test/data/faq/ex3_escapefunc1.result +2 -0
- data/test/data/faq/ex3_escapefunc2.result +2 -0
- data/test/data/faq/ex5.rbhtml +7 -0
- data/test/data/faq/ex5_template_args.source +9 -0
- data/test/data/faq/ex6-content.rhtml +6 -0
- data/test/data/faq/ex6-layout.rhtml +6 -0
- data/test/data/faq/ex6.rb +10 -0
- data/test/data/faq/ex6_eruby.result +12 -0
- data/test/data/faq/ex7-expr-pattern.rb +34 -0
- data/test/data/faq/ex7-expr-pattern.rbhtml +3 -0
- data/test/data/faq/ex7_expr_pattern.result +4 -0
- data/test/data/faq/ex8-m18n.rb +77 -0
- data/test/data/faq/ex8-m18n.rbhtml +4 -0
- data/test/data/faq/ex8_m18n.result +10 -0
- data/test/data/faq/ex9-baselayout.rbhtml +8 -0
- data/test/data/faq/ex9-content.rbhtml +6 -0
- data/test/data/faq/ex9-mylayout.rbhtml +5 -0
- data/test/data/faq/ex9_changelayout.result +11 -0
- data/test/data/users_guide/content6.rbhtml +3 -0
- data/test/data/users_guide/content7.rbhtml +5 -0
- data/test/data/users_guide/content8.rbhtml +2 -0
- data/test/data/users_guide/contextdata.rb +7 -0
- data/test/data/users_guide/datafile.rb +5 -0
- data/test/data/users_guide/datafile.yaml +10 -0
- data/test/data/users_guide/ex.rbhtml +6 -0
- data/test/data/users_guide/ex.result +7 -0
- data/test/data/users_guide/ex.script +5 -0
- data/test/data/users_guide/ex_script.result +7 -0
- data/test/data/users_guide/ex_source.result +8 -0
- data/test/data/users_guide/example1.rbhtml +12 -0
- data/test/data/users_guide/example1.result +17 -0
- data/test/data/users_guide/example10.rbhtml +4 -0
- data/test/data/users_guide/example10_template_args.result +6 -0
- data/test/data/users_guide/example11.rbhtml +5 -0
- data/test/data/users_guide/example11_template_args_result +2 -0
- data/test/data/users_guide/example12.rbhtml +12 -0
- data/test/data/users_guide/example12_preprocessed.result +10 -0
- data/test/data/users_guide/example12_preprocessed_source.result +10 -0
- data/test/data/users_guide/example13.rbhtml +6 -0
- data/test/data/users_guide/example13_preprocessed.result +2 -0
- data/test/data/users_guide/example13_preprocessed_source.result +2 -0
- data/test/data/users_guide/example14.rb +32 -0
- data/test/data/users_guide/example14.rbhtml +6 -0
- data/test/data/users_guide/example14_tmplclass.result +15 -0
- data/test/data/users_guide/example15.rb +10 -0
- data/test/data/users_guide/example15_escapefunc.result +14 -0
- data/test/data/users_guide/example16.rbhtml +4 -0
- data/test/data/users_guide/example16a.rb +10 -0
- data/test/data/users_guide/example16a.result +4 -0
- data/test/data/users_guide/example16b.rb +13 -0
- data/test/data/users_guide/example16b.result +4 -0
- data/test/data/users_guide/example16c.rb +12 -0
- data/test/data/users_guide/example16c.result +4 -0
- data/test/data/users_guide/example1_S.result +14 -0
- data/test/data/users_guide/example1_SXNC.result +10 -0
- data/test/data/users_guide/example1_source.result +14 -0
- data/test/data/users_guide/example2.rbhtml +3 -0
- data/test/data/users_guide/example2_sb.result2 +9 -0
- data/test/data/users_guide/example3.rbhtml +5 -0
- data/test/data/users_guide/example3_syntaxcheck.result +2 -0
- data/test/data/users_guide/example4.rbhtml +13 -0
- data/test/data/users_guide/example4_datafile_rb.result +13 -0
- data/test/data/users_guide/example4_yaml.result +13 -0
- data/test/data/users_guide/example5.rbhtml +9 -0
- data/test/data/users_guide/example5_datastr_rb.result +9 -0
- data/test/data/users_guide/example5_datastr_yaml.result +9 -0
- data/test/data/users_guide/example6.rbhtml +19 -0
- data/test/data/users_guide/example6_layout.result +29 -0
- data/test/data/users_guide/example6_nested.result +28 -0
- data/test/data/users_guide/example7_layout2.result +13 -0
- data/test/data/users_guide/example8_layout3.result +8 -0
- data/test/data/users_guide/example9.rbhtml +18 -0
- data/test/data/users_guide/example9_capture.result +26 -0
- data/test/data/users_guide/footer.html +5 -0
- data/test/data/users_guide/footer.rbhtml +4 -0
- data/test/data/users_guide/layout6.rbhtml +17 -0
- data/test/data/users_guide/layout7.rbhtml +9 -0
- data/test/data/users_guide/layout8_html.rbhtml +5 -0
- data/test/data/users_guide/layout8_xhtml.rbhtml +6 -0
- data/test/data/users_guide/layout9.rbhtml +25 -0
- data/test/data/users_guide/sidemenu.rbhtml +5 -0
- data/test/data/users_guide/user_app.cgi +39 -0
- data/test/data/users_guide/user_app.result +30 -0
- data/test/data/users_guide/user_create.rbhtml +6 -0
- data/test/data/users_guide/user_edit.rbhtml +7 -0
- data/test/data/users_guide/user_form.rbhtml +10 -0
- data/test/data/users_guide/user_layout.rbhtml +16 -0
- data/test/test_all.rb +23 -0
- data/test/test_engine.rb +526 -0
- data/test/test_engine.yaml +2039 -0
- data/test/test_examples.rb +81 -0
- data/test/test_faq.rb +60 -0
- data/test/test_htmlhelper.rb +78 -0
- data/test/test_main.rb +564 -0
- data/test/test_main.yaml +174 -0
- data/test/test_template.rb +113 -0
- data/test/test_template.yaml +1244 -0
- data/test/test_users_guide.rb +75 -0
- data/test/testcase-helper.rb +166 -0
- metadata +226 -0
@@ -0,0 +1,12 @@
|
|
1
|
+
<?RB states = { "CA" => "California", ?>
|
2
|
+
<?RB "NY" => "New York", ?>
|
3
|
+
<?RB "FL" => "Florida", ?>
|
4
|
+
<?RB "TX" => "Texas", ?>
|
5
|
+
<?RB "HI" => "Hawaii", } ?>
|
6
|
+
<?rb chk = { @params['state'] => ' selected="selected"' } ?>
|
7
|
+
<select name="state">
|
8
|
+
<option value="">-</option>
|
9
|
+
<?RB for code in states.keys.sort ?>
|
10
|
+
<option value="#{{code}}"#{chk[#{{code.inspect}}]}>${{states[code]}}</option>
|
11
|
+
<?RB end ?>
|
12
|
+
</select>
|
@@ -0,0 +1,10 @@
|
|
1
|
+
$ rbtenjin -P example12.rbhtml
|
2
|
+
<?rb chk = { @params['state'] => ' selected="selected"' } ?>
|
3
|
+
<select name="state">
|
4
|
+
<option value="">-</option>
|
5
|
+
<option value="CA"#{chk["CA"]}>California</option>
|
6
|
+
<option value="FL"#{chk["FL"]}>Florida</option>
|
7
|
+
<option value="HI"#{chk["HI"]}>Hawaii</option>
|
8
|
+
<option value="NY"#{chk["NY"]}>New York</option>
|
9
|
+
<option value="TX"#{chk["TX"]}>Texas</option>
|
10
|
+
</select>
|
@@ -0,0 +1,10 @@
|
|
1
|
+
$ rbtenjin --preprocess -sb example12.rbhtml
|
2
|
+
chk = { @params['state'] => ' selected="selected"' }
|
3
|
+
_buf << %Q`<select name="state">
|
4
|
+
<option value="">-</option>
|
5
|
+
<option value="CA"#{chk["CA"]}>California</option>
|
6
|
+
<option value="FL"#{chk["FL"]}>Florida</option>
|
7
|
+
<option value="HI"#{chk["HI"]}>Hawaii</option>
|
8
|
+
<option value="NY"#{chk["NY"]}>New York</option>
|
9
|
+
<option value="TX"#{chk["TX"]}>Texas</option>
|
10
|
+
</select>\n`
|
@@ -0,0 +1,6 @@
|
|
1
|
+
<?RB require 'cgi' ?>
|
2
|
+
<?RB ## ex. link_to('Show', '/show/1') => <a href="/show/1">Show</a> ?>
|
3
|
+
<?RB def link_to(label, url) ?>
|
4
|
+
<?RB return "<a href=\"#{CGI.unescape(url)}\">#{label}</a>" ?>
|
5
|
+
<?RB end ?>
|
6
|
+
#{{link_to 'Show '+_P('@params["name"]'), '/items/show/'+_p('@params["id"]')}}
|
@@ -0,0 +1,32 @@
|
|
1
|
+
## template file
|
2
|
+
filename = 'example14.rbhtml'
|
3
|
+
|
4
|
+
## convert into ruby code
|
5
|
+
require 'tenjin'
|
6
|
+
template = Tenjin::Template.new(filename)
|
7
|
+
## or
|
8
|
+
# template = Tenjin::Template.new()
|
9
|
+
# script = template.convert_file(filename)
|
10
|
+
## or
|
11
|
+
# template = Tenjin::Template.new()
|
12
|
+
# input = File.read(filename)
|
13
|
+
# script = template.convert(input, filename) # filename is optional
|
14
|
+
|
15
|
+
## show converted ruby code
|
16
|
+
puts "---- ruby code ----"
|
17
|
+
puts template.script
|
18
|
+
|
19
|
+
## evaluate ruby code
|
20
|
+
hash = {:title=>'rbTenjin Example', :items=>['<AAA>','B&B','"CCC"']}
|
21
|
+
output = template.render(hash)
|
22
|
+
puts "---- output ----"
|
23
|
+
puts output
|
24
|
+
## or
|
25
|
+
#hash = {:title=>'rbTenjin Example', :items=>['<AAA>','B&B','"CCC"']}
|
26
|
+
#context = Tenjin::Context.new(hash)
|
27
|
+
#output = template.render(context)
|
28
|
+
## or
|
29
|
+
# context = Tenjin::Context.new
|
30
|
+
# context[:title] = 'rbTenjin Example'
|
31
|
+
# context[:items] = ['<AAA>','B&B','"CCC"']
|
32
|
+
# output = template.render(context)
|
@@ -0,0 +1,15 @@
|
|
1
|
+
$ ruby example14.rb
|
2
|
+
---- ruby code ----
|
3
|
+
_buf << %Q`<h1>#{@title}</h1>
|
4
|
+
<ul>\n`
|
5
|
+
for item in @items
|
6
|
+
_buf << %Q` <li>#{escape((item).to_s)}</li>\n`
|
7
|
+
end
|
8
|
+
_buf << %Q`</ul>\n`
|
9
|
+
---- output ----
|
10
|
+
<h1>rbTenjin Example</h1>
|
11
|
+
<ul>
|
12
|
+
<li><AAA></li>
|
13
|
+
<li>B&B</li>
|
14
|
+
<li>"CCC"</li>
|
15
|
+
</ul>
|
@@ -0,0 +1,10 @@
|
|
1
|
+
require 'tenjin'
|
2
|
+
filename = 'example14.rbhtml'
|
3
|
+
template = Tenjin::Template.new(filename, :escapefunc=>'CGI.escapeHTML')
|
4
|
+
print template.script, "\n"
|
5
|
+
|
6
|
+
require 'cgi'
|
7
|
+
title = 'rbTenjin Example'
|
8
|
+
items = ['<foo>', '&bar', '"baz"']
|
9
|
+
output = template.render(:title=>title, :items=>items)
|
10
|
+
print output
|
@@ -0,0 +1,14 @@
|
|
1
|
+
$ ruby example15.rb
|
2
|
+
_buf << %Q`<h1>#{@title}</h1>
|
3
|
+
<ul>\n`
|
4
|
+
for item in @items
|
5
|
+
_buf << %Q` <li>#{CGI.escapeHTML((item).to_s)}</li>\n`
|
6
|
+
end
|
7
|
+
_buf << %Q`</ul>\n`
|
8
|
+
|
9
|
+
<h1>rbTenjin Example</h1>
|
10
|
+
<ul>
|
11
|
+
<li><foo></li>
|
12
|
+
<li>&bar</li>
|
13
|
+
<li>"baz"</li>
|
14
|
+
</ul>
|
@@ -0,0 +1,10 @@
|
|
1
|
+
require 'tenjin'
|
2
|
+
|
3
|
+
def link_to(label, url)
|
4
|
+
return "<a href=\"#{escape_xml(url)}\">#{escape_xml(label)}</a>"
|
5
|
+
end
|
6
|
+
|
7
|
+
engine = Tenjin::Engine.new()
|
8
|
+
context = { :label=>'Top', :url=>'/' }
|
9
|
+
output = engine.render('example16.rbhtml', context)
|
10
|
+
print output
|
@@ -0,0 +1,13 @@
|
|
1
|
+
require 'tenjin'
|
2
|
+
|
3
|
+
module Tenjin::ContextHelper
|
4
|
+
module_function
|
5
|
+
def link_to(label, url)
|
6
|
+
return "<a href=\"#{escape_xml(url)}\">#{escape_xml(label)}</a>"
|
7
|
+
end
|
8
|
+
end
|
9
|
+
|
10
|
+
engine = Tenjin::Engine.new()
|
11
|
+
context = { :label=>'Top', :url=>'/' }
|
12
|
+
output = engine.render('example16.rbhtml', context)
|
13
|
+
print output
|
@@ -0,0 +1,12 @@
|
|
1
|
+
require 'tenjin'
|
2
|
+
|
3
|
+
class MyContext < Tenjin::Context
|
4
|
+
def link_to(label, url)
|
5
|
+
return "<a href=\"#{escape_xml(url)}\">#{escape_xml(label)}</a>"
|
6
|
+
end
|
7
|
+
end
|
8
|
+
|
9
|
+
engine = Tenjin::Engine.new()
|
10
|
+
context = MyContext.new(:label=>'Top', :url=>'/')
|
11
|
+
output = engine.render('example16.rbhtml', context)
|
12
|
+
print output
|
@@ -0,0 +1,14 @@
|
|
1
|
+
$ rbtenjin -s example1.rbhtml
|
2
|
+
_buf = ''; _buf << %Q`<table>
|
3
|
+
<tbody>\n`
|
4
|
+
i = 0
|
5
|
+
for item in ['<foo>', 'bar&bar', '"baz"']
|
6
|
+
i += 1
|
7
|
+
_buf << %Q` <tr>
|
8
|
+
<td>#{item}</td>
|
9
|
+
<td>#{escape((item).to_s)}</td>
|
10
|
+
</tr>\n`
|
11
|
+
end
|
12
|
+
_buf << %Q` <tbody>
|
13
|
+
</table>\n`
|
14
|
+
_buf.to_s
|