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,19 @@
|
|
1
|
+
<html>
|
2
|
+
<body>
|
3
|
+
|
4
|
+
<div id="sidemenu">
|
5
|
+
<?rb import 'sidemenu.rbhtml' ?>
|
6
|
+
</div>
|
7
|
+
|
8
|
+
<div id="main-content">
|
9
|
+
<?rb for item in @items ?>
|
10
|
+
<p>${item}</p>
|
11
|
+
<?rb end ?>
|
12
|
+
</div>
|
13
|
+
|
14
|
+
<div id="footer">
|
15
|
+
#{import 'footer.rbhtml', false}
|
16
|
+
</div>
|
17
|
+
|
18
|
+
</body>
|
19
|
+
</table>
|
@@ -0,0 +1,29 @@
|
|
1
|
+
$ rbtenjin -f contextdata.rb --layout=layout6.rbhtml content6.rbhtml
|
2
|
+
<html>
|
3
|
+
<body>
|
4
|
+
|
5
|
+
<div id="sidemenu">
|
6
|
+
<ul>
|
7
|
+
<li><a href="/">Top</a></li>
|
8
|
+
<li><a href="/prod">Products</a></li>
|
9
|
+
<li><a href="/support">Support</a></li>
|
10
|
+
</ul>
|
11
|
+
</div>
|
12
|
+
|
13
|
+
<div id="main-content">
|
14
|
+
<p><FOO></p>
|
15
|
+
<p>&BAR</p>
|
16
|
+
<p>"BAZ"</p>
|
17
|
+
|
18
|
+
</div>
|
19
|
+
|
20
|
+
<div id="footer">
|
21
|
+
<hr />
|
22
|
+
<address>
|
23
|
+
<a href="mailto:webmaster@example.com">webmaster@example.com</a>
|
24
|
+
</address>
|
25
|
+
|
26
|
+
</div>
|
27
|
+
|
28
|
+
</body>
|
29
|
+
</table>
|
@@ -0,0 +1,28 @@
|
|
1
|
+
$ rbtenjin -f contextdata.rb example6.rbhtml
|
2
|
+
<html>
|
3
|
+
<body>
|
4
|
+
|
5
|
+
<div id="sidemenu">
|
6
|
+
<ul>
|
7
|
+
<li><a href="/">Top</a></li>
|
8
|
+
<li><a href="/prod">Products</a></li>
|
9
|
+
<li><a href="/support">Support</a></li>
|
10
|
+
</ul>
|
11
|
+
</div>
|
12
|
+
|
13
|
+
<div id="main-content">
|
14
|
+
<p><FOO></p>
|
15
|
+
<p>&BAR</p>
|
16
|
+
<p>"BAZ"</p>
|
17
|
+
</div>
|
18
|
+
|
19
|
+
<div id="footer">
|
20
|
+
<hr />
|
21
|
+
<address>
|
22
|
+
<a href="mailto:webmaster@example.com">webmaster@example.com</a>
|
23
|
+
</address>
|
24
|
+
|
25
|
+
</div>
|
26
|
+
|
27
|
+
</body>
|
28
|
+
</table>
|
@@ -0,0 +1,18 @@
|
|
1
|
+
<?rb @title = 'Capture Test' ?>
|
2
|
+
<html>
|
3
|
+
<body>
|
4
|
+
|
5
|
+
<?rb start_capture(:content_part) ?>
|
6
|
+
<ul>
|
7
|
+
<?rb for i in [0, 1, 2] ?>
|
8
|
+
<li>i = #{i}</li>
|
9
|
+
<?rb end ?>
|
10
|
+
</ul>
|
11
|
+
<?rb stop_capture() ?>
|
12
|
+
|
13
|
+
<?rb start_capture('footer_part') ?>
|
14
|
+
<div class="footer">copyright© 2007 kuwata-lab.com</div>
|
15
|
+
<?rb stop_capture() ?>
|
16
|
+
|
17
|
+
</body>
|
18
|
+
</html>
|
@@ -0,0 +1,26 @@
|
|
1
|
+
$ rbtenjin --layout=layout9.rbhtml example9.rbhtml
|
2
|
+
<html lang="en">
|
3
|
+
<head>
|
4
|
+
<title>Capture Test</title>
|
5
|
+
</head>
|
6
|
+
<body>
|
7
|
+
|
8
|
+
<!-- HEADER -->
|
9
|
+
<h1>Capture Test</h1>
|
10
|
+
<!-- /HEADER -->
|
11
|
+
|
12
|
+
<!-- CONTENT -->
|
13
|
+
<ul>
|
14
|
+
<li>i = 0</li>
|
15
|
+
<li>i = 1</li>
|
16
|
+
<li>i = 2</li>
|
17
|
+
</ul>
|
18
|
+
|
19
|
+
<!-- /CONTENT -->
|
20
|
+
|
21
|
+
<!-- FOOTER -->
|
22
|
+
<div class="footer">copyright© 2007 kuwata-lab.com</div>
|
23
|
+
<!-- /FOOTER -->
|
24
|
+
|
25
|
+
</body>
|
26
|
+
</html>
|
@@ -0,0 +1,25 @@
|
|
1
|
+
<html lang="en">
|
2
|
+
<head>
|
3
|
+
<title>${@title}</title>
|
4
|
+
</head>
|
5
|
+
<body>
|
6
|
+
|
7
|
+
<!-- HEADER -->
|
8
|
+
<?rb unless captured_as('header_part') ?>
|
9
|
+
<h1>${@title}</h1>
|
10
|
+
<?rb end ?>
|
11
|
+
<!-- /HEADER -->
|
12
|
+
|
13
|
+
<!-- CONTENT -->
|
14
|
+
#{@content_part}
|
15
|
+
<!-- /CONTENT -->
|
16
|
+
|
17
|
+
<!-- FOOTER -->
|
18
|
+
<?rb unless captured_as('footer_part') ?>
|
19
|
+
<hr />
|
20
|
+
<address>webmaster@localhost</address>
|
21
|
+
<?rb end ?>
|
22
|
+
<!-- /FOOTER -->
|
23
|
+
|
24
|
+
</body>
|
25
|
+
</html>
|
@@ -0,0 +1,39 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require 'cgi'
|
4
|
+
require 'tenjin'
|
5
|
+
|
6
|
+
## set action ('create' or 'edit')
|
7
|
+
action = nil
|
8
|
+
cgi = nil
|
9
|
+
if ENV['REQUEST_METHOD']
|
10
|
+
cgi = CGI.new
|
11
|
+
action = cgi['action']
|
12
|
+
elsif ARGV[0]
|
13
|
+
action = ARGV[0]
|
14
|
+
end
|
15
|
+
action = 'create' unless ['create', 'edit'].include?(action)
|
16
|
+
|
17
|
+
## set context data
|
18
|
+
if action == 'create'
|
19
|
+
title = 'Create User'
|
20
|
+
params = {}
|
21
|
+
else
|
22
|
+
title = 'Edit User'
|
23
|
+
params = {:name=>'Margalette',
|
24
|
+
:email=>'meg@example.com',
|
25
|
+
:gender=>'f',
|
26
|
+
:id=>123 }
|
27
|
+
end
|
28
|
+
context = { :title=>title, :params=>params }
|
29
|
+
# or context = Tenjin::Context.new(:title=>title, :params=>params)
|
30
|
+
|
31
|
+
## create engine object
|
32
|
+
layout = :layout # or 'user_layout.rbhtml'
|
33
|
+
engine = Tenjin::Engine.new(:prefix=>'user_', :postfix=>'.rbhtml', :layout=>layout)
|
34
|
+
|
35
|
+
## evaluate template
|
36
|
+
template_name = action.intern # :create or :edit
|
37
|
+
output = engine.render(template_name, context)
|
38
|
+
print cgi.header() if cgi
|
39
|
+
print output
|
@@ -0,0 +1,30 @@
|
|
1
|
+
$ ruby user_app.cgi create
|
2
|
+
<html>
|
3
|
+
<body>
|
4
|
+
|
5
|
+
<h1>Create User</h1>
|
6
|
+
|
7
|
+
<div id="main-content">
|
8
|
+
<form action="user_app.cgi" method="post">
|
9
|
+
<input type="hidden" name="action" value="create" />
|
10
|
+
<p>
|
11
|
+
Name: <input type="text" name="name" value="" /><br />
|
12
|
+
Email: <input type="text" name="email" value="" /><br />
|
13
|
+
Gender:
|
14
|
+
<input type="radio" name="gender" value="m" />Male
|
15
|
+
<input type="radio" name="gender" value="f" />Female
|
16
|
+
</p>
|
17
|
+
<input type="submit" value="Create" />
|
18
|
+
</form>
|
19
|
+
|
20
|
+
</div>
|
21
|
+
|
22
|
+
<div id="footer">
|
23
|
+
<hr />
|
24
|
+
<address>
|
25
|
+
<a href="mailto:webmaster@example.com">webmaster@example.com</a>
|
26
|
+
</address>
|
27
|
+
</div>
|
28
|
+
|
29
|
+
</body>
|
30
|
+
</html>
|
@@ -0,0 +1,10 @@
|
|
1
|
+
<?rb #@ARGS params ?>
|
2
|
+
<p>
|
3
|
+
Name: <input type="text" name="name" value="${params['name']}" /><br />
|
4
|
+
Email: <input type="text" name="email" value="${params['email']}" /><br />
|
5
|
+
Gender:
|
6
|
+
<?rb gender = @params['gender'] ?>
|
7
|
+
<?rb chk = { true=>' checked="checked"', false=>'' } ?>
|
8
|
+
<input type="radio" name="gender" value="m" #{chk[gender=='m']} />Male
|
9
|
+
<input type="radio" name="gender" value="f" #{chk[gender=='f']} />Female
|
10
|
+
</p>
|
data/test/test_all.rb
ADDED
@@ -0,0 +1,23 @@
|
|
1
|
+
###
|
2
|
+
### $Rev: 45 $
|
3
|
+
### $Release: 0.6.0 $
|
4
|
+
### copyright(c) 2007 kuwata-lab all rights reserved.
|
5
|
+
###
|
6
|
+
|
7
|
+
basedir = File.dirname(File.dirname(File.expand_path(__FILE__)))
|
8
|
+
testdir = basedir + '/test'
|
9
|
+
$: << testdir
|
10
|
+
|
11
|
+
require 'test/unit'
|
12
|
+
#require 'testutil'
|
13
|
+
require 'testcase-helper'
|
14
|
+
require 'assert-text-equal'
|
15
|
+
require 'tenjin'
|
16
|
+
|
17
|
+
Dir.chdir testdir
|
18
|
+
load 'test_template.rb'
|
19
|
+
load 'test_engine.rb'
|
20
|
+
load 'test_main.rb'
|
21
|
+
load 'test_htmlhelper.rb'
|
22
|
+
load 'test_users_guide.rb'
|
23
|
+
load 'test_faq.rb'
|
data/test/test_engine.rb
ADDED
@@ -0,0 +1,526 @@
|
|
1
|
+
###
|
2
|
+
### $Rev: 59 $
|
3
|
+
### $Release: 0.6.0 $
|
4
|
+
### copyright(c) 2007 kuwata-lab all rights reserved.
|
5
|
+
###
|
6
|
+
|
7
|
+
require 'test/unit'
|
8
|
+
#require 'testutil'
|
9
|
+
require 'testcase-helper'
|
10
|
+
require 'assert-text-equal'
|
11
|
+
require 'yaml'
|
12
|
+
|
13
|
+
require 'tenjin'
|
14
|
+
|
15
|
+
|
16
|
+
class TenjinEngineTest < Test::Unit::TestCase
|
17
|
+
|
18
|
+
s = File.read(__FILE__.sub(/\.\w+$/, '.yaml'))
|
19
|
+
s.gsub!(/^\t/, ' ' * 8)
|
20
|
+
ydoc = YAML.load(s)
|
21
|
+
_data_convert(ydoc, 'ruby')
|
22
|
+
TESTDATA = {}
|
23
|
+
ydoc.each { |e| TESTDATA[e['name']] = e }
|
24
|
+
TESTDATA['basic']['templates'].each do |d|
|
25
|
+
d['filename'].sub!(/\.xxhtml$/, '.rbhtml')
|
26
|
+
end
|
27
|
+
|
28
|
+
def _setup
|
29
|
+
TESTDATA['basic']['templates'].each do |hash|
|
30
|
+
File.write(hash['filename'], hash['content'])
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
34
|
+
def _teardown
|
35
|
+
TESTDATA['basic']['templates'].each do |hash|
|
36
|
+
filenames = [hash['filename'], hash['filename']+'.cache']
|
37
|
+
filenames.each do |fname|
|
38
|
+
File.unlink(fname) if test(?f, fname)
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|
42
|
+
|
43
|
+
def _remove_files(*filenames)
|
44
|
+
for filename in filenames.flatten
|
45
|
+
for fname in Dir.glob("#{filename}*")
|
46
|
+
File.unlink(fname)
|
47
|
+
end
|
48
|
+
end
|
49
|
+
end
|
50
|
+
|
51
|
+
def _template_class
|
52
|
+
Tenjin::Template
|
53
|
+
end
|
54
|
+
|
55
|
+
def _test_basic
|
56
|
+
|
57
|
+
## setup
|
58
|
+
_setup()
|
59
|
+
|
60
|
+
## body
|
61
|
+
begin
|
62
|
+
testname = (caller[0] =~ /`(.*)'/) && $1
|
63
|
+
list = testname.split('_')
|
64
|
+
action = list[2] # 'list', 'show', 'create', or 'edit'
|
65
|
+
shortp = list[3] != 'filename' # template short name or filename
|
66
|
+
layoutp = list[4] != 'nolayout' # use layout or not
|
67
|
+
layout = layoutp ? 'user_layout.rbhtml' : nil
|
68
|
+
engine = Tenjin::Engine.new(:prefix=>'user_', :postfix=>'.rbhtml', :layout=>layout, :templateclass=>_template_class())
|
69
|
+
context = TESTDATA['basic']['contexts'][action]
|
70
|
+
key = 'user_' + action + (layout ? '_withlayout' : '_nolayout')
|
71
|
+
expected = TESTDATA['basic']['expected'].find{|h| h['name'] == key}['content']
|
72
|
+
filename = 'user_%s.rbhtml' % action
|
73
|
+
tplname = shortp ? action.intern : filename
|
74
|
+
output = engine.render(tplname, context, layoutp)
|
75
|
+
assert_text_equal(expected, output)
|
76
|
+
|
77
|
+
## teardown
|
78
|
+
ensure
|
79
|
+
_teardown
|
80
|
+
end
|
81
|
+
end
|
82
|
+
|
83
|
+
|
84
|
+
# fileame, nolayout
|
85
|
+
|
86
|
+
def test_basic_list_filename_nolayout
|
87
|
+
_test_basic
|
88
|
+
end
|
89
|
+
|
90
|
+
def test_basic_show_filename_nolayout
|
91
|
+
_test_basic
|
92
|
+
end
|
93
|
+
|
94
|
+
def test_basic_create_filename_nolayout
|
95
|
+
_test_basic
|
96
|
+
end
|
97
|
+
|
98
|
+
def test_basic_edit_filename_nolayout
|
99
|
+
_test_basic
|
100
|
+
end
|
101
|
+
|
102
|
+
|
103
|
+
# shortname, nolayout
|
104
|
+
|
105
|
+
def test_basic_list_shortname_nolayout
|
106
|
+
_test_basic
|
107
|
+
end
|
108
|
+
|
109
|
+
def test_basic_show_shortname_nolayout
|
110
|
+
_test_basic
|
111
|
+
end
|
112
|
+
|
113
|
+
def test_basic_create_shortname_nolayout
|
114
|
+
_test_basic
|
115
|
+
end
|
116
|
+
|
117
|
+
def test_basic_edit_shortname_nolayout
|
118
|
+
_test_basic
|
119
|
+
end
|
120
|
+
|
121
|
+
|
122
|
+
# filename, withlayout
|
123
|
+
|
124
|
+
def test_basic_list_filename_withlayout
|
125
|
+
_test_basic
|
126
|
+
end
|
127
|
+
|
128
|
+
def test_basic_show_filename_withlayout
|
129
|
+
_test_basic
|
130
|
+
end
|
131
|
+
|
132
|
+
def test_basic_create_filename_withlayout
|
133
|
+
_test_basic
|
134
|
+
end
|
135
|
+
|
136
|
+
def test_basic_edit_filename_withlayout
|
137
|
+
_test_basic
|
138
|
+
end
|
139
|
+
|
140
|
+
|
141
|
+
# shortname, withlayout
|
142
|
+
|
143
|
+
def test_basic_list_shortname_withlayout
|
144
|
+
_test_basic
|
145
|
+
end
|
146
|
+
|
147
|
+
def test_basic_show_shortname_withlayout
|
148
|
+
_test_basic
|
149
|
+
end
|
150
|
+
|
151
|
+
def test_basic_create_shortname_withlayout
|
152
|
+
_test_basic
|
153
|
+
end
|
154
|
+
|
155
|
+
def test_basic_edit_shortname_withlayout
|
156
|
+
_test_basic
|
157
|
+
end
|
158
|
+
|
159
|
+
|
160
|
+
## ----------------------------------------
|
161
|
+
|
162
|
+
def test_capture_and_echo
|
163
|
+
hash = TESTDATA['test_capture_and_echo']
|
164
|
+
layout = hash['layout']
|
165
|
+
content = hash['content']
|
166
|
+
expected = hash['expected']
|
167
|
+
layout_filename = 'user_layout.rbhtml'
|
168
|
+
content_filename = 'user_content.rbhtml'
|
169
|
+
begin
|
170
|
+
File.write(layout_filename, layout)
|
171
|
+
File.write(content_filename, content)
|
172
|
+
engine = Tenjin::Engine.new(:prefix=>'user_', :postfix=>'.rbhtml', :layout=>:layout, :templateclass=>_template_class())
|
173
|
+
context = { :items => %w[AAA BBB CCC] }
|
174
|
+
result = engine.render(:content, context)
|
175
|
+
assert_text_equal(expected, result)
|
176
|
+
ensure
|
177
|
+
[layout_filename, layout_filename + '.cache',
|
178
|
+
content_filename, content_filename + '.cache'].each do |filename|
|
179
|
+
File.unlink(filename) if test(?f, filename)
|
180
|
+
end
|
181
|
+
end
|
182
|
+
end
|
183
|
+
|
184
|
+
|
185
|
+
def test_captured_as
|
186
|
+
hash = TESTDATA['test_captured_as']
|
187
|
+
files = [
|
188
|
+
['baselayout.rbhtml', hash['baselayout']],
|
189
|
+
['customlayout.rbhtml', hash['customlayout']],
|
190
|
+
['content.rbhtml', hash['content']],
|
191
|
+
]
|
192
|
+
context = hash['context']
|
193
|
+
expected = hash['expected']
|
194
|
+
begin
|
195
|
+
for filename, content in files
|
196
|
+
File.write(filename, content)
|
197
|
+
end
|
198
|
+
engine = Tenjin::Engine.new(:postfix=>'.rbhtml', :templateclass=>_template_class())
|
199
|
+
result = engine.render(:content, context)
|
200
|
+
assert_text_equal(expected, result)
|
201
|
+
ensure
|
202
|
+
for filename, content in files
|
203
|
+
for fname in Dir.glob("#{filename}*")
|
204
|
+
File.unlink(fname) if test(?f, fname)
|
205
|
+
end
|
206
|
+
end
|
207
|
+
end
|
208
|
+
end
|
209
|
+
|
210
|
+
|
211
|
+
def test_local_layout
|
212
|
+
hash = TESTDATA['test_local_layout']
|
213
|
+
context = hash['context']
|
214
|
+
names = ['layout_html', 'layout_xhtml', 'content_html']
|
215
|
+
fname = lambda { |base| 'local_%s.rbhtml' % base }
|
216
|
+
begin
|
217
|
+
names.each do |name|
|
218
|
+
File.write(fname.call(name), hash[name])
|
219
|
+
end
|
220
|
+
engine = Tenjin::Engine.new(:prefix=>'local_', :postfix=>'.rbhtml', :layout=>:layout_html, :templateclass=>_template_class())
|
221
|
+
##
|
222
|
+
content_html = hash['content_html']
|
223
|
+
File.write(fname.call('content_html'), content_html)
|
224
|
+
actual = engine.render(:content_html, context)
|
225
|
+
assert_text_equal(hash['expected_html'], actual)
|
226
|
+
##
|
227
|
+
sleep(1)
|
228
|
+
content_html = hash['content_html'] + "<?rb @_layout = :layout_xhtml ?>\n"
|
229
|
+
File.write(fname.call('content_html'), content_html)
|
230
|
+
actual = engine.render(:content_html, context)
|
231
|
+
assert_text_equal(hash['expected_xhtml'], actual)
|
232
|
+
##
|
233
|
+
sleep(1)
|
234
|
+
content_html = hash['content_html'] + "<?rb @_layout = false ?>\n"
|
235
|
+
File.write(fname.call('content_html'), content_html)
|
236
|
+
actual = engine.render(:content_html, context)
|
237
|
+
assert_text_equal(hash['expected_nolayout'], actual)
|
238
|
+
ensure
|
239
|
+
names.collect {|name| fname.call(name)}.each do |filename|
|
240
|
+
File.unlink(filename) if test(?f, filename)
|
241
|
+
filename += '.cache'
|
242
|
+
File.unlink(filename) if test(?f, filename)
|
243
|
+
end
|
244
|
+
end
|
245
|
+
end
|
246
|
+
|
247
|
+
|
248
|
+
def test_cachefile
|
249
|
+
data = TESTDATA['test_cachefile']
|
250
|
+
filenames = {
|
251
|
+
'layout'=> 'layout.rbhtml',
|
252
|
+
'page' => 'account_create.rbhtml',
|
253
|
+
'form' => 'account_form.rbhtml',
|
254
|
+
}
|
255
|
+
expected = data['expected']
|
256
|
+
context = { 'params'=> { } }
|
257
|
+
begin
|
258
|
+
for key, filename in filenames
|
259
|
+
File.write(filename, data[key])
|
260
|
+
end
|
261
|
+
args = { :prefix=>'account_', :postfix=>'.rbhtml',
|
262
|
+
:layout=>'layout.rbhtml', :templateclass=>_template_class() }
|
263
|
+
## no caching
|
264
|
+
args[:cache] = false
|
265
|
+
engine = Tenjin::Engine.new(args)
|
266
|
+
output = engine.render(:create, context)
|
267
|
+
assert_text_equal(expected, output)
|
268
|
+
assert !test(?f, 'account_create.rbhtml.cache')
|
269
|
+
#assert !test(?f, 'account_create.rbhtml.pstore')
|
270
|
+
assert !test(?f, 'account_form.rbhtml.cache')
|
271
|
+
#assert !test(?f, 'account_form.rbhtml.pstore')
|
272
|
+
## ruby code caching
|
273
|
+
args[:cache] = true
|
274
|
+
engine = Tenjin::Engine.new(args)
|
275
|
+
output = engine.render(:create, context)
|
276
|
+
assert test(?f, 'account_create.rbhtml.cache')
|
277
|
+
#assert !test(?f, 'account_create.rbhtml.pstore')
|
278
|
+
assert test(?f, 'account_form.rbhtml.cache')
|
279
|
+
#assert !test(?f, 'account_form.rbhtml.pstore')
|
280
|
+
File.unlink('account_create.rbhtml.cache')
|
281
|
+
File.unlink('account_form.rbhtml.cache')
|
282
|
+
## pstore caching
|
283
|
+
#args[:cache] = true
|
284
|
+
#engine = Tenjin::Engine(args)
|
285
|
+
#output = engine.render(:create, context)
|
286
|
+
#assert !test(?f, 'account_create.rbhtml.cache')
|
287
|
+
#assert !test(?f, 'account_create.rbhtml.pstore')
|
288
|
+
#assert !test(?f, 'account_form.rbhtml.cache')
|
289
|
+
#assert !test(?f, 'account_form.rbhtml.pstore')
|
290
|
+
ensure
|
291
|
+
for key, filename in filenames
|
292
|
+
for fname in [filename, filename+'.cache', filename+'.pstore']
|
293
|
+
test(?f, fname) and File.unlink(fname)
|
294
|
+
end
|
295
|
+
end
|
296
|
+
end
|
297
|
+
|
298
|
+
end
|
299
|
+
|
300
|
+
|
301
|
+
def test_change_layout()
|
302
|
+
data = TESTDATA['test_change_layout']
|
303
|
+
## setup
|
304
|
+
basenames = %w[baselayout customlayout content]
|
305
|
+
for basename in basenames
|
306
|
+
File.write("#{basename}.rbhtml", data[basename])
|
307
|
+
end
|
308
|
+
## body
|
309
|
+
begin
|
310
|
+
engine = Tenjin::Engine.new(:layout=>'baselayout.rbhtml',
|
311
|
+
:templateclass=>_template_class())
|
312
|
+
output = engine.render('content.rbhtml')
|
313
|
+
expected = data['expected']
|
314
|
+
assert_text_equal(expected, output)
|
315
|
+
ensure
|
316
|
+
for basename in basenames
|
317
|
+
Dir.glob("#{basename}.rbhtml*").each do |fname|
|
318
|
+
File.unlink(fname)
|
319
|
+
end
|
320
|
+
end
|
321
|
+
end
|
322
|
+
end
|
323
|
+
|
324
|
+
|
325
|
+
def test_context_scope
|
326
|
+
return if ENV['TEST'] && ENV['TEST'] != 'template_args'
|
327
|
+
data = TESTDATA['test_context_scope']
|
328
|
+
content = data['content']
|
329
|
+
expected = data['expected']
|
330
|
+
begin
|
331
|
+
File.write('base.rbhtml', data['base'])
|
332
|
+
File.write('part.rbhtml', data['part'])
|
333
|
+
engine = Tenjin::Engine.new()
|
334
|
+
actual = engine.render('base.rbhtml');
|
335
|
+
assert_text_equal(expected, actual)
|
336
|
+
ensure
|
337
|
+
_remove_files(['base', 'part'])
|
338
|
+
end
|
339
|
+
end
|
340
|
+
|
341
|
+
|
342
|
+
def test_template_args
|
343
|
+
return if ENV['TEST'] && ENV['TEST'] != 'template_args'
|
344
|
+
data = TESTDATA['test_template_args']
|
345
|
+
content = data['content']
|
346
|
+
expected = data['expected']
|
347
|
+
errormsg = data['errormsg']
|
348
|
+
exception = eval(data['exception'])
|
349
|
+
context = data['context']
|
350
|
+
for basename in %w[content]
|
351
|
+
File.write("#{basename}.rbhtml", data[basename])
|
352
|
+
end
|
353
|
+
# when no cache file
|
354
|
+
args1 = nil;
|
355
|
+
ex = assert_raise(exception) do
|
356
|
+
assert(!test(?f, 'content.rbhtml.cache'))
|
357
|
+
engine = Tenjin::Engine.new(:cache=>true)
|
358
|
+
args1 = engine.get_template('content.rbhtml').args
|
359
|
+
assert_not_nil(args1)
|
360
|
+
output = engine.render('content.rbhtml', context)
|
361
|
+
end
|
362
|
+
assert_equal(errormsg, ex.to_s.sub(/:0x\w+>/, '>'))
|
363
|
+
# when cache file exist
|
364
|
+
ex = assert_raise(NameError) do
|
365
|
+
#File.unlink('content.rbhtml');
|
366
|
+
assert(test(?f, 'content.rbhtml.cache'))
|
367
|
+
engine = Tenjin::Engine.new(:cache=>true)
|
368
|
+
args2 = engine.get_template('content.rbhtml').args
|
369
|
+
assert_not_nil(args2)
|
370
|
+
assert_equal(args1, args2)
|
371
|
+
output = engine.render('content.rbhtml', context)
|
372
|
+
end
|
373
|
+
assert_equal(errormsg, ex.to_s.sub(/:0x\w+>/, '>'))
|
374
|
+
ensure
|
375
|
+
_remove_files(['content'])
|
376
|
+
end
|
377
|
+
|
378
|
+
|
379
|
+
def test_cached_contents
|
380
|
+
return if ENV['TEST'] && ENV['TEST'] != 'template_args'
|
381
|
+
data = TESTDATA['test_cached_contents']
|
382
|
+
filename = 'input.pyhtml'
|
383
|
+
cachename = filename+'.cache'
|
384
|
+
_testproc = proc do |cacheflag, n|
|
385
|
+
script = data["script#{n}"]
|
386
|
+
cache = data["cache#{n}"]
|
387
|
+
args = data["args#{n}"]
|
388
|
+
cachename = filename+'.cache'
|
389
|
+
engine = Tenjin::Engine.new(:cache=>cacheflag)
|
390
|
+
t = engine.get_template(filename)
|
391
|
+
assert_equal(args, t.args)
|
392
|
+
assert_text_equal(script, t.script)
|
393
|
+
cache_actual = File.read(engine.cachename(filename))
|
394
|
+
assert_text_equal(cache, cache_actual)
|
395
|
+
end
|
396
|
+
#
|
397
|
+
## args=[x,y,z], cache=1
|
398
|
+
for f in Dir.glob(filename+'*') do File.unlink(f) end
|
399
|
+
File.write(filename, data["input1"])
|
400
|
+
assert(!test(?f, cachename))
|
401
|
+
_testproc.call(cacheflag=true, n=1)
|
402
|
+
assert(test(?f, cachename))
|
403
|
+
_testproc.call(cacheflag=true, n=1)
|
404
|
+
## args=[], cache=1
|
405
|
+
sleep(1)
|
406
|
+
File.write(filename, data["input2"])
|
407
|
+
#assert(test(?f, cachename))
|
408
|
+
_testproc.call(cacheflag=true, n=2)
|
409
|
+
#assert(test(?f, cachename))
|
410
|
+
_testproc.call(cacheflag=true, n=2)
|
411
|
+
ensure
|
412
|
+
_remove_files(['input.pyhtml'])
|
413
|
+
end
|
414
|
+
|
415
|
+
|
416
|
+
def _test_template_path(arg1, arg2, arg3)
|
417
|
+
data = TESTDATA['test_template_path']
|
418
|
+
basedir = 'test_templates'
|
419
|
+
keys = [arg1, arg2, arg3]
|
420
|
+
begin
|
421
|
+
for dir in [basedir, "#{basedir}/common", "#{basedir}/user"]
|
422
|
+
Dir.mkdir(dir) unless test(?d, dir)
|
423
|
+
end
|
424
|
+
d = { 'layout'=>arg1, 'body'=>arg2, 'footer'=>arg3 }
|
425
|
+
for key in %w[layout body footer]
|
426
|
+
filename = "#{basedir}/common/#{key}.rbhtml"
|
427
|
+
File.write(filename, data["common_#{key}"])
|
428
|
+
if d[key] == 'user'
|
429
|
+
filename = "#{basedir}/user/#{key}.rbhtml"
|
430
|
+
File.write(filename, data["user_#{key}"])
|
431
|
+
end
|
432
|
+
end
|
433
|
+
#
|
434
|
+
path = ["#{basedir}/user", "#{basedir}/common"]
|
435
|
+
engine = Tenjin::Engine.new(:postfix=>'.rbhtml', :path=>path, :layout=>:layout, :templateclass=>_template_class())
|
436
|
+
context = { :items=>%w[AAA BBB CCC] }
|
437
|
+
output = engine.render(:body, context)
|
438
|
+
#
|
439
|
+
expected = data["expected_#{keys.join('_')}"]
|
440
|
+
assert_text_equal(expected, output)
|
441
|
+
ensure
|
442
|
+
require 'fileutils'
|
443
|
+
FileUtils.rm_rf(basedir)
|
444
|
+
end
|
445
|
+
end
|
446
|
+
|
447
|
+
def test_template_path_common_common_common()
|
448
|
+
_test_template_path('common', 'common', 'common')
|
449
|
+
end
|
450
|
+
def test_template_path_user_common_common()
|
451
|
+
_test_template_path('user', 'common', 'common')
|
452
|
+
end
|
453
|
+
def test_template_path_common_user_common()
|
454
|
+
_test_template_path('common', 'user', 'common')
|
455
|
+
end
|
456
|
+
def test_template_path_user_user_common()
|
457
|
+
_test_template_path('user', 'user', 'common')
|
458
|
+
end
|
459
|
+
def test_template_path_common_common_user()
|
460
|
+
_test_template_path('common', 'common', 'user')
|
461
|
+
end
|
462
|
+
def test_template_path_user_common_user()
|
463
|
+
_test_template_path('user', 'common', 'user')
|
464
|
+
end
|
465
|
+
def test_template_path_common_user_user()
|
466
|
+
_test_template_path('common', 'user', 'user')
|
467
|
+
end
|
468
|
+
def test_template_path_user_user_user()
|
469
|
+
_test_template_path('user', 'user', 'user')
|
470
|
+
end
|
471
|
+
|
472
|
+
|
473
|
+
def test_preprocessor
|
474
|
+
return if ENV['TEST'] && ENV['TEST'] != 'preprocessor'
|
475
|
+
data = TESTDATA['test_preprocessor']
|
476
|
+
form = data['form']
|
477
|
+
create = data['create']
|
478
|
+
update = data['update']
|
479
|
+
layout = data['layout']
|
480
|
+
context = data['context']
|
481
|
+
#
|
482
|
+
basenames = %w[form create update layout]
|
483
|
+
filenames = []
|
484
|
+
basenames.each do |name|
|
485
|
+
filenames << (filename = "prep_#{name}.rbhtml")
|
486
|
+
File.write(filename, data[name])
|
487
|
+
end
|
488
|
+
engine = Tenjin::Engine.new(:prefix=>'prep_', :postfix=>'.rbhtml', :layout=>:layout, :preprocess=>true)
|
489
|
+
#
|
490
|
+
context = { :title=>'Create', :action=>'create', :params=>{'state'=>:NY} }
|
491
|
+
actual = engine.render(:create, context) # 1st
|
492
|
+
assert_text_equal(data['expected1'], actual)
|
493
|
+
context[:params] = {'state'=>:xx}
|
494
|
+
actual = engine.render(:create, context) # 2nd
|
495
|
+
#assert_text_equal(data['expected1'], actual)
|
496
|
+
assert_text_equal(data['expected1'].sub(/ checked="checked"/, ''), actual)
|
497
|
+
#
|
498
|
+
context = { :title=>'Update', :action=>'update', :params=>{'state'=>:NY} }
|
499
|
+
actual = engine.render(:update, context) # 1st
|
500
|
+
assert_text_equal(data['expected2'], actual)
|
501
|
+
context[:params] = {'state'=>:xx}
|
502
|
+
actual = engine.render(:update, context) # 2nd
|
503
|
+
assert_text_equal(data['expected2'], actual) # not changed!
|
504
|
+
#assert_text_equal(data['expected2'].sub(/ checked="checked"/, ''), actual)
|
505
|
+
ensure
|
506
|
+
_remove_files(Dir.glob('prep_*'))
|
507
|
+
end
|
508
|
+
|
509
|
+
|
510
|
+
if ENV['TEST']
|
511
|
+
targetname = 'test_' + ENV['TEST']
|
512
|
+
for m in self.instance_methods
|
513
|
+
private m if m =~ /^test_/ && m != targetname
|
514
|
+
end
|
515
|
+
end
|
516
|
+
|
517
|
+
end
|
518
|
+
|
519
|
+
|
520
|
+
#if defined?(Tenjin::ArrayBufferTemplate)
|
521
|
+
# class TenjinEngine2Test < TenjinEngineTest
|
522
|
+
# def _template_class
|
523
|
+
# Tenjin::ArrayBufferTemplate
|
524
|
+
# end
|
525
|
+
# end
|
526
|
+
#end
|