PageTemplate 1.1.2 → 1.2.0
Sign up to get free protection for your applications and to get access to all the features.
- data/CVS/Entries +10 -0
- data/CVS/Repository +1 -0
- data/CVS/Root +1 -0
- data/Changes +13 -0
- data/Changes~ +7 -0
- data/InstalledFiles +7 -0
- data/README.txt +1 -1
- data/Rakefile +1 -1
- data/Rakefile~ +54 -0
- data/TC_PageTemplate.rb +137 -19
- data/TC_PageTemplate.rb~ +965 -0
- data/doc/classes/BlockCommand.html +1 -1
- data/doc/classes/BlockCommand.src/M000004.html +1 -1
- data/doc/classes/BlockCommand.src/M000005.html +1 -1
- data/doc/classes/BlockCommand.src/M000006.html +1 -1
- data/doc/classes/BlockCommand.src/M000007.html +1 -1
- data/doc/classes/BlockCommand.src/M000008.html +1 -1
- data/doc/classes/Command.html +10 -10
- data/doc/classes/Command.src/{M000029.html → M000032.html} +0 -0
- data/doc/classes/Command.src/{M000030.html → M000033.html} +0 -0
- data/doc/classes/CommentCommand.html +146 -0
- data/doc/classes/CommentCommand.src/M000009.html +18 -0
- data/doc/classes/IfCommand.html +15 -15
- data/doc/classes/IfCommand.src/{M000039.html → M000042.html} +1 -1
- data/doc/classes/IfCommand.src/{M000040.html → M000043.html} +1 -1
- data/doc/classes/IfCommand.src/{M000041.html → M000044.html} +1 -1
- data/doc/classes/IfElseCommand.html +15 -15
- data/doc/classes/IfElseCommand.src/M000025.html +5 -6
- data/doc/classes/IfElseCommand.src/{M000024.html → M000026.html} +1 -1
- data/doc/classes/IfElseCommand.src/M000027.html +20 -0
- data/doc/classes/IncludeCommand.html +16 -23
- data/doc/classes/IncludeCommand.src/M000019.html +12 -4
- data/doc/classes/IncludeCommand.src/{M000018.html → M000020.html} +10 -5
- data/doc/classes/IncludeCommand.src/M000021.html +18 -0
- data/doc/classes/IncludeCommandError.html +118 -0
- data/doc/classes/LoopCommand.src/M000001.html +1 -1
- data/doc/classes/LoopCommand.src/M000002.html +11 -2
- data/doc/classes/LoopCommand.src/M000003.html +1 -1
- data/doc/classes/LoopElseCommand.html +15 -15
- data/doc/classes/LoopElseCommand.src/M000022.html +5 -6
- data/doc/classes/LoopElseCommand.src/{M000021.html → M000023.html} +1 -1
- data/doc/classes/LoopElseCommand.src/M000024.html +20 -0
- data/doc/classes/Namespace.html +42 -42
- data/doc/classes/Namespace.src/M000034.html +5 -5
- data/doc/classes/Namespace.src/M000035.html +4 -22
- data/doc/classes/Namespace.src/M000036.html +4 -7
- data/doc/classes/Namespace.src/M000037.html +5 -4
- data/doc/classes/Namespace.src/M000038.html +22 -4
- data/doc/classes/Namespace.src/M000039.html +21 -0
- data/doc/classes/Namespace.src/M000040.html +18 -0
- data/doc/classes/Namespace.src/{M000031.html → M000041.html} +4 -5
- data/doc/classes/PageTemplate.html +72 -44
- data/doc/classes/PageTemplate.src/M000010.html +31 -11
- data/doc/classes/PageTemplate.src/M000011.html +4 -4
- data/doc/classes/PageTemplate.src/M000012.html +15 -4
- data/doc/classes/PageTemplate.src/M000013.html +4 -4
- data/doc/classes/PageTemplate.src/M000014.html +4 -4
- data/doc/classes/PageTemplate.src/M000015.html +4 -4
- data/doc/classes/PageTemplate.src/M000016.html +4 -5
- data/doc/classes/PageTemplate.src/M000017.html +18 -0
- data/doc/classes/PageTemplate.src/M000018.html +19 -0
- data/doc/classes/Syntax/CachedParser.html +10 -10
- data/doc/classes/Syntax/CachedParser.src/{M000045.html → M000048.html} +1 -1
- data/doc/classes/Syntax/CachedParser.src/{M000046.html → M000049.html} +2 -1
- data/doc/classes/Syntax/Glossary.html +16 -10
- data/doc/classes/Syntax/Glossary.src/{M000047.html → M000050.html} +1 -1
- data/doc/classes/Syntax/Glossary.src/{M000048.html → M000051.html} +1 -1
- data/doc/classes/Syntax/Parser.html +31 -31
- data/doc/classes/Syntax/Parser.src/M000052.html +6 -5
- data/doc/classes/Syntax/Parser.src/M000053.html +20 -37
- data/doc/classes/Syntax/Parser.src/M000054.html +4 -93
- data/doc/classes/Syntax/Parser.src/{M000049.html → M000055.html} +5 -6
- data/doc/classes/Syntax/Parser.src/M000056.html +53 -0
- data/doc/classes/Syntax/Parser.src/M000057.html +111 -0
- data/doc/classes/Syntax.html +1 -1
- data/doc/classes/TextCommand.html +15 -15
- data/doc/classes/TextCommand.src/{M000042.html → M000045.html} +1 -1
- data/doc/classes/TextCommand.src/{M000043.html → M000046.html} +1 -1
- data/doc/classes/TextCommand.src/{M000044.html → M000047.html} +1 -1
- data/doc/classes/UnlessCommand.html +151 -0
- data/doc/classes/UnlessCommand.src/M000028.html +20 -0
- data/doc/classes/ValueCommand.html +15 -15
- data/doc/classes/ValueCommand.src/{M000026.html → M000029.html} +1 -1
- data/doc/classes/ValueCommand.src/{M000027.html → M000030.html} +1 -1
- data/doc/classes/ValueCommand.src/{M000028.html → M000031.html} +1 -1
- data/doc/created.rid +1 -1
- data/doc/files/README_txt.html +2 -2
- data/doc/files/lib/PageTemplate_rb.html +1 -1
- data/doc/fr_class_index.html +3 -0
- data/doc/fr_method_index.html +52 -49
- data/lib/CVS/Entries +2 -0
- data/lib/CVS/Repository +1 -0
- data/lib/CVS/Root +1 -0
- data/lib/PageTemplate.rb +103 -26
- data/lib/PageTemplate.rb~ +1004 -0
- data/pkg/PageTemplate-1.2.0.gem +0 -0
- data/tdata/CVS/Entries +28 -0
- data/tdata/CVS/Repository +1 -0
- data/tdata/CVS/Root +1 -0
- data/tdata/cm.txt +3 -0
- data/tdata/include.4.nf.out.txt +2 -0
- data/tdata/metadata.1.txt +5 -0
- data/tdata/metadata.2.txt +5 -0
- data/tdata/metadata.3.txt +5 -0
- data/tdata/metadata.4.txt +5 -0
- data/tdata/p/CVS/Entries +5 -0
- data/tdata/p/CVS/Repository +1 -0
- data/tdata/p/CVS/Root +1 -0
- data/tdata/p/CVS/b2.txt,t +0 -0
- data/tdata/p/b2.txt +4 -0
- data/tdata/p/b2.txt~ +4 -0
- metadata +70 -32
- data/doc/classes/IfElseCommand.src/M000023.html +0 -19
- data/doc/classes/IncludeCommand.src/M000017.html +0 -21
- data/doc/classes/LoopElseCommand.src/M000020.html +0 -19
- data/doc/classes/Namespace.src/M000032.html +0 -18
- data/doc/classes/Namespace.src/M000033.html +0 -18
- data/doc/classes/PageTemplate.src/M000009.html +0 -46
- data/doc/classes/Syntax/Parser.src/M000050.html +0 -35
- data/doc/classes/Syntax/Parser.src/M000051.html +0 -18
- data/lib/MANIFEST +0 -2
- data/pkg/PageTemplate-1.1.2.gem +0 -0
data/CVS/Entries
ADDED
@@ -0,0 +1,10 @@
|
|
1
|
+
/MANIFEST/1.1.1.1/Wed Mar 9 01:30:10 2005//
|
2
|
+
/config.save/1.1.1.1/Wed Mar 9 01:30:10 2005//
|
3
|
+
/install.rb/1.1.1.1/Wed Mar 9 01:30:10 2005//
|
4
|
+
/test-install.rb/1.1.1.1/Wed Mar 9 01:30:10 2005//
|
5
|
+
D/lib////
|
6
|
+
D/tdata////
|
7
|
+
/Changes/1.1/Fri Mar 11 08:56:02 2005//
|
8
|
+
/README.txt/1.2/Fri Mar 11 01:48:29 2005//
|
9
|
+
/Rakefile/1.2/Fri Mar 11 09:01:10 2005//
|
10
|
+
/TC_PageTemplate.rb/1.12/Fri Mar 11 19:04:51 2005//
|
data/CVS/Repository
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
PageTemplate
|
data/CVS/Root
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
/home/wisti/CVS
|
data/Changes
ADDED
@@ -0,0 +1,13 @@
|
|
1
|
+
1.2
|
2
|
+
- Added: UnlessCommand (including '[%unless foo %]' syntax)
|
3
|
+
- Added: Loop Metavariables __FIRST__, __LAST__, and __ODD__
|
4
|
+
- Added: CommentCommand (including '[%-- blah --%]' syntax)
|
5
|
+
- Added: IncludeCommands allow multiple include paths
|
6
|
+
- Changed: VariableCommands access via 'obj.respond_to?' rather than 'obj.class.has_method?'
|
7
|
+
- Fixed: Unhandled SecurityError when 'include' is called in a mod_ruby environment
|
8
|
+
- Fixed: MANIFEST file being installed to rubylib directory
|
9
|
+
- Fixed: Returns a failure string when include fails, rather than raising an exception.
|
10
|
+
1.1
|
11
|
+
- Added: IncludeCommand
|
12
|
+
1.0
|
13
|
+
- Moved to Rubyforge
|
data/Changes~
ADDED
data/InstalledFiles
ADDED
data/README.txt
CHANGED
@@ -19,7 +19,7 @@ http://www.coolnamehere.com/products/pagetemplate/
|
|
19
19
|
== Features
|
20
20
|
|
21
21
|
* Variable substitution
|
22
|
-
* If and If/Else structures
|
22
|
+
* If, Unless, and If/Else structures
|
23
23
|
* Loops and Loop/Else structures
|
24
24
|
* Customizable Syntax
|
25
25
|
* Include content from external files (new in 1.1)
|
data/Rakefile
CHANGED
data/Rakefile~
ADDED
@@ -0,0 +1,54 @@
|
|
1
|
+
# -*- ruby -*-
|
2
|
+
|
3
|
+
require 'rubygems'
|
4
|
+
Gem::manage_gems
|
5
|
+
require 'rake/gempackagetask'
|
6
|
+
|
7
|
+
task :default => [:all, :test]
|
8
|
+
|
9
|
+
task :all do
|
10
|
+
ruby %{-c lib/PageTemplate.rb}
|
11
|
+
ruby %{-c TC_PageTemplate.rb}
|
12
|
+
end
|
13
|
+
|
14
|
+
task :test do
|
15
|
+
ruby %{-w TC_PageTemplate.rb}
|
16
|
+
end
|
17
|
+
|
18
|
+
task :install do
|
19
|
+
ruby %{install.rb config}
|
20
|
+
ruby %{install.rb setup}
|
21
|
+
ruby %{install.rb install}
|
22
|
+
end
|
23
|
+
|
24
|
+
task :doc do
|
25
|
+
sh %{rdoc lib/PageTemplate.rb README.txt}
|
26
|
+
end
|
27
|
+
|
28
|
+
task :cnh_doc do
|
29
|
+
sh %{cp -R --remove-destination doc /home/wisti/Sites/coolnamehere/extras/doc/PageTemplate}
|
30
|
+
end
|
31
|
+
|
32
|
+
spec = Gem::Specification.new do |s|
|
33
|
+
s.name = "PageTemplate"
|
34
|
+
s.version = "1.1.2"
|
35
|
+
s.author = "Brian Wisti"
|
36
|
+
s.email = "brian@coolnamehere.com"
|
37
|
+
s.homepage = "http://coolnamehere.com/products/pagetemplate"
|
38
|
+
s.platform = Gem::Platform::RUBY
|
39
|
+
s.summary = "A simple templating system for Web sites."
|
40
|
+
s.files = Dir.glob("**/*")
|
41
|
+
s.require_path = "lib"
|
42
|
+
s.autorequire = "PageTemplate.rb"
|
43
|
+
s.test_file = "TC_PageTemplate.rb"
|
44
|
+
s.has_rdoc = true
|
45
|
+
s.extra_rdoc_files = ["README.txt"]
|
46
|
+
end
|
47
|
+
|
48
|
+
Rake::GemPackageTask.new(spec) do |pkg|
|
49
|
+
pkg.need_tar = true
|
50
|
+
end
|
51
|
+
|
52
|
+
task :gem do
|
53
|
+
sh %{rake pkg/PageTemplate-#{spec.version}.gem}
|
54
|
+
end
|
data/TC_PageTemplate.rb
CHANGED
@@ -60,6 +60,16 @@ class TC_Command < Test::Unit::TestCase
|
|
60
60
|
|
61
61
|
end
|
62
62
|
|
63
|
+
class TC_CommentCommand < Test::Unit::TestCase
|
64
|
+
@@command = CommentCommand.new()
|
65
|
+
|
66
|
+
def testCommentCommand
|
67
|
+
assert_equal(nil, @@command.output,
|
68
|
+
"CommentCommands don't have any output")
|
69
|
+
end
|
70
|
+
|
71
|
+
end
|
72
|
+
|
63
73
|
class TC_BlockCommand < Test::Unit::TestCase
|
64
74
|
@@command = BlockCommand.new()
|
65
75
|
|
@@ -125,6 +135,24 @@ class TC_IfCommand < Test::Unit::TestCase
|
|
125
135
|
end
|
126
136
|
end
|
127
137
|
|
138
|
+
class TC_UnlessCommand < Test::Unit::TestCase
|
139
|
+
def testOutput
|
140
|
+
aCommand = TextCommand.new("Dude!")
|
141
|
+
bCommand = TextCommand.new("Sweet!")
|
142
|
+
commandBlock = BlockCommand.new()
|
143
|
+
commandBlock.add(aCommand)
|
144
|
+
commandBlock.add(bCommand)
|
145
|
+
ns = Namespace.new()
|
146
|
+
ns["testing"] = false
|
147
|
+
|
148
|
+
# First test for output with false condition
|
149
|
+
unlessCommand = UnlessCommand.new("testing", commandBlock)
|
150
|
+
assert_equal("Dude!Sweet!", unlessCommand.output(ns))
|
151
|
+
ns["testing"] = true
|
152
|
+
assert_nil(unlessCommand.output(ns))
|
153
|
+
end
|
154
|
+
end
|
155
|
+
|
128
156
|
class TC_IfElseCommand < Test::Unit::TestCase
|
129
157
|
|
130
158
|
def testOutput
|
@@ -349,14 +377,17 @@ end
|
|
349
377
|
|
350
378
|
class TC_SyntaxGlossary < Test::Unit::TestCase
|
351
379
|
@@syntax = Syntax::Glossary.new( /\[%(.+?)%\]/,
|
352
|
-
'value'
|
353
|
-
'ifopen'
|
354
|
-
'ifclose'
|
355
|
-
'
|
356
|
-
'
|
357
|
-
'
|
358
|
-
'
|
359
|
-
'
|
380
|
+
'value' => /var (\w+)/,
|
381
|
+
'ifopen' => /if (\w+)/,
|
382
|
+
'ifclose' => /endif/,
|
383
|
+
'unlessopen' => /unless (\w+)/,
|
384
|
+
'unlessclose' => /endunless/,
|
385
|
+
'ifbranch' => /else/,
|
386
|
+
'loopopen' => /in (\w+)/,
|
387
|
+
'loopclose' => /endin/,
|
388
|
+
'loopbranch' => /no/,
|
389
|
+
'include' => /include (\w+)/,
|
390
|
+
'comment' => /--.+?--/
|
360
391
|
)
|
361
392
|
|
362
393
|
def testGlossary
|
@@ -380,6 +411,7 @@ class TC_SyntaxGlossary < Test::Unit::TestCase
|
|
380
411
|
assert_equal(["loopclose", nil], @@syntax.lookup("endin"))
|
381
412
|
assert_equal(["loopbranch", nil], @@syntax.lookup("no"))
|
382
413
|
assert_equal(["include", "foo"], @@syntax.lookup("include foo"))
|
414
|
+
assert_equal(["comment", nil], @@syntax.lookup("-- blarg! --"))
|
383
415
|
assert_nil(@@syntax.lookup("foo"))
|
384
416
|
assert_nil(@@syntax.lookup("foo bar"))
|
385
417
|
end
|
@@ -430,6 +462,29 @@ class TC_SyntaxParser < Test::Unit::TestCase
|
|
430
462
|
]
|
431
463
|
|
432
464
|
assert_equal(mResult, @@parser.parse(multiline))
|
465
|
+
|
466
|
+
multiline = [
|
467
|
+
"Hello [%var world%\]",
|
468
|
+
"[%unless return%]",
|
469
|
+
"Welcome!",
|
470
|
+
"[%endunless%]"
|
471
|
+
]
|
472
|
+
|
473
|
+
mResult = [
|
474
|
+
[1, "Hello "],
|
475
|
+
[1, ["value", "world"]],
|
476
|
+
[1, ""],
|
477
|
+
[2, ""],
|
478
|
+
[2, ["unlessopen", "return"]],
|
479
|
+
[2, ""],
|
480
|
+
[3, "Welcome!"],
|
481
|
+
[4, ""],
|
482
|
+
[4, ["unlessclose", nil]],
|
483
|
+
[4, ""]
|
484
|
+
]
|
485
|
+
|
486
|
+
assert_equal(mResult, @@parser.parse(multiline))
|
487
|
+
|
433
488
|
end
|
434
489
|
|
435
490
|
def testCompile
|
@@ -440,12 +495,21 @@ class TC_SyntaxParser < Test::Unit::TestCase
|
|
440
495
|
"[%endif%]"
|
441
496
|
]
|
442
497
|
assert(@@parser.compile(@@parser.parse(directives)))
|
498
|
+
|
499
|
+
directives = [
|
500
|
+
"Hello [%var world%]",
|
501
|
+
"[%unless return%]",
|
502
|
+
"Welcome!",
|
503
|
+
"[%endunless%]"
|
504
|
+
]
|
505
|
+
assert(@@parser.compile(@@parser.parse(directives)))
|
443
506
|
end
|
444
507
|
|
445
508
|
def testBuild
|
446
509
|
assert(@@parser.build("tdata/p/b1.txt"))
|
447
510
|
# Make sure nothing panics if we ask for the commands again.
|
448
511
|
assert(@@parser.build("tdata/p/b1.txt"))
|
512
|
+
assert(@@parser.build("tdata/p/b2.txt"))
|
449
513
|
end
|
450
514
|
end
|
451
515
|
|
@@ -513,6 +577,11 @@ class TC_PageTemplate < Test::Unit::TestCase
|
|
513
577
|
cmpFile = File.open("tdata/nm.txt").read()
|
514
578
|
assert_equal(cmpFile, @@template.output())
|
515
579
|
end
|
580
|
+
|
581
|
+
def testOutputCommentMarkup
|
582
|
+
@@template.load("tdata/cm.txt")
|
583
|
+
assert(@@template.output !~ /\[%--/)
|
584
|
+
end
|
516
585
|
|
517
586
|
def testOutputValueMarkup
|
518
587
|
|
@@ -530,6 +599,14 @@ class TC_PageTemplate < Test::Unit::TestCase
|
|
530
599
|
assert(@@template.output =~ /<h1>title%\]<\/h1>/)
|
531
600
|
end
|
532
601
|
|
602
|
+
def testOutputUnlessMarkup
|
603
|
+
@@template['return'] = true
|
604
|
+
@@template.load("tdata/p/b2.txt")
|
605
|
+
assert(@@template.output !~ /Welcome/)
|
606
|
+
@@template['return'] = false
|
607
|
+
assert(@@template.output =~ /Welcome/)
|
608
|
+
end
|
609
|
+
|
533
610
|
def testOutputIfMarkup
|
534
611
|
@@template['flag'] = true
|
535
612
|
@@template.load("tdata/i1.txt")
|
@@ -621,6 +698,30 @@ class TC_PageTemplate < Test::Unit::TestCase
|
|
621
698
|
assert(@@template.output !~ /<li>.*?<\/li>/)
|
622
699
|
end
|
623
700
|
|
701
|
+
def testLoopMetavariables
|
702
|
+
@@template.load("tdata/metadata.1.txt")
|
703
|
+
myLoop = []
|
704
|
+
1.upto(5) { |v| myLoop << {'v' => v} }
|
705
|
+
|
706
|
+
@@template['loop'] = myLoop
|
707
|
+
assert(@@template.output =~ /<li>--1--<\/li>/,
|
708
|
+
"__FIRST__ is set for the first iteration through a loop")
|
709
|
+
assert(@@template.output =~ /<li>5<\/li>/,
|
710
|
+
"__FIRST__ is unset after the first iteration through a loop")
|
711
|
+
|
712
|
+
@@template.load("tdata/metadata.2.txt")
|
713
|
+
assert(@@template.output =~ /<li>--5--<\/li>/,
|
714
|
+
"__LAST__ is set for the last iteration through a loop")
|
715
|
+
assert(@@template.output =~ /<li>1<\/li>/,
|
716
|
+
"__LAST__ is unset before the last iteration through a loop")
|
717
|
+
|
718
|
+
@@template.load("tdata/metadata.3.txt")
|
719
|
+
assert(@@template.output =~ /<li>--1--<\/li>/,
|
720
|
+
"__ODD__ is set for odd-numbered iterations through a loop (1st, 3rd, etc)")
|
721
|
+
assert(@@template.output =~ /<li>2<\/li>/,
|
722
|
+
"__ODD__ is unset for even-numbered iterations through a loop (2nd, 4th, etc)")
|
723
|
+
end
|
724
|
+
|
624
725
|
def testOutputNestedLoopMarkup
|
625
726
|
@@template.load("tdata/l2.txt")
|
626
727
|
|
@@ -734,9 +835,7 @@ class TC_PageTemplate < Test::Unit::TestCase
|
|
734
835
|
'creator'=> 'Tom Waits'}]}
|
735
836
|
]
|
736
837
|
|
737
|
-
page = PageTemplate.new(
|
738
|
-
'filename' => "tdata/complex.txt"
|
739
|
-
)
|
838
|
+
page = PageTemplate.new('filename' => "tdata/complex.txt")
|
740
839
|
page.setParameter("title", title)
|
741
840
|
page.setParameter("ifTest", 1)
|
742
841
|
page.setParameter("languages", languages)
|
@@ -749,8 +848,7 @@ class TC_PageTemplate < Test::Unit::TestCase
|
|
749
848
|
end
|
750
849
|
|
751
850
|
def testCachedTemplate
|
752
|
-
assert(ct = PageTemplate.new(
|
753
|
-
'filename' => "tdata/complex.txt",
|
851
|
+
assert(ct = PageTemplate.new('filename' => "tdata/complex.txt",
|
754
852
|
'use_cache' => true
|
755
853
|
))
|
756
854
|
|
@@ -804,7 +902,6 @@ class TC_Include < Test::Unit::TestCase
|
|
804
902
|
def testIncludeCommand()
|
805
903
|
ns = Namespace.new()
|
806
904
|
|
807
|
-
|
808
905
|
incCommand = IncludeCommand.new("tdata/include.1.txt")
|
809
906
|
text = File.open("tdata/include.1.txt").read()
|
810
907
|
assert_equal(text, incCommand.output(ns),
|
@@ -822,22 +919,43 @@ class TC_Include < Test::Unit::TestCase
|
|
822
919
|
incCommand = IncludeCommand.new("tdata/include.3.txt")
|
823
920
|
assert_equal(pt.output(), incCommand.output(ns),
|
824
921
|
"Include Commands can parse standard Template markup")
|
825
|
-
|
826
922
|
end
|
827
923
|
|
828
924
|
def testIncludePath
|
829
|
-
incCommand = IncludeCommand.new("include.4.txt", "tdata")
|
925
|
+
incCommand = IncludeCommand.new("include.4.txt", [ "tdata" ])
|
830
926
|
text = File.open("tdata/include.4.out.txt").read()
|
831
927
|
assert_equal(text, incCommand.output,
|
832
|
-
"IncludeCommand accepts an
|
928
|
+
"IncludeCommand accepts an array of paths as a second arg")
|
929
|
+
|
930
|
+
incCommand = IncludeCommand.new("include.4.txt", [ "/etc", "tdata" ])
|
931
|
+
text = File.open("tdata/include.4.out.txt").read()
|
932
|
+
assert_equal(text, incCommand.output,
|
933
|
+
"IncludeCommand accepts an array of paths as a second arg")
|
833
934
|
|
834
935
|
pt = PageTemplate.new('include_path' => "tdata")
|
835
|
-
pt.load("tdata/include.
|
836
|
-
pt["file"] = "include.
|
936
|
+
pt.load("tdata/include.4b.txt")
|
937
|
+
pt["file"] = "include.4a.txt"
|
837
938
|
text = File.open("tdata/include.4.out.txt").read()
|
838
939
|
assert_equal(text, pt.output,
|
839
940
|
"Include Commands can be given a variable name as an argument")
|
840
941
|
|
942
|
+
pt = PageTemplate.new('include_path' => "tdata")
|
943
|
+
pt.load("tdata/include.4b.txt")
|
944
|
+
pt["file"] = "secret-of-life.txt"
|
945
|
+
text = File.open("tdata/include.4.nf.out.txt").read()
|
946
|
+
assert_equal(text, pt.output,
|
947
|
+
"Include Commands will output a warning if file isn't found.")
|
948
|
+
|
949
|
+
# Support for multiple include paths.
|
950
|
+
pt = PageTemplate.new()
|
951
|
+
assert_equal([ Dir.getwd() ], pt.path)
|
952
|
+
assert(pt.add_path('tdata'),
|
953
|
+
"Use #add_path(path) to add an include path.")
|
954
|
+
assert_equal([ Dir.getwd(), 'tdata'], pt.path)
|
955
|
+
pt.add_path('tdata/inc-1')
|
956
|
+
assert_equal([ Dir.getwd, "tdata", "tdata/inc-1"], pt.path)
|
957
|
+
pt = PageTemplate.new('include_path' => %w{tdata tdata/inc-1})
|
958
|
+
assert_equal([ Dir.getwd, "tdata", "tdata/inc-1"], pt.path)
|
841
959
|
end
|
842
960
|
|
843
961
|
def testIncludeSyntax
|