PageTemplate 1.2.0 → 2.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (150) hide show
  1. data/Changes +24 -0
  2. data/MANIFEST +0 -1
  3. data/README.txt +10 -8
  4. data/Rakefile +30 -9
  5. data/lib/PageTemplate/case.rb +72 -0
  6. data/lib/PageTemplate/commands.rb +500 -0
  7. data/lib/PageTemplate/parser.rb +373 -0
  8. data/lib/PageTemplate.rb +47 -991
  9. data/setup-usage.txt +129 -0
  10. data/setup.rb +1360 -0
  11. data/tdata/dummy.txt +2 -0
  12. data/test.rb +616 -0
  13. metadata +13 -169
  14. data/CVS/Entries +0 -10
  15. data/CVS/Repository +0 -1
  16. data/CVS/Root +0 -1
  17. data/Changes~ +0 -7
  18. data/InstalledFiles +0 -7
  19. data/Rakefile~ +0 -54
  20. data/TC_PageTemplate.rb +0 -974
  21. data/TC_PageTemplate.rb~ +0 -965
  22. data/config.save +0 -12
  23. data/doc/classes/BlockCommand.html +0 -229
  24. data/doc/classes/BlockCommand.src/M000004.html +0 -18
  25. data/doc/classes/BlockCommand.src/M000005.html +0 -25
  26. data/doc/classes/BlockCommand.src/M000006.html +0 -18
  27. data/doc/classes/BlockCommand.src/M000007.html +0 -23
  28. data/doc/classes/BlockCommand.src/M000008.html +0 -24
  29. data/doc/classes/Command.html +0 -167
  30. data/doc/classes/Command.src/M000032.html +0 -19
  31. data/doc/classes/Command.src/M000033.html +0 -18
  32. data/doc/classes/CommentCommand.html +0 -146
  33. data/doc/classes/CommentCommand.src/M000009.html +0 -18
  34. data/doc/classes/IfCommand.html +0 -193
  35. data/doc/classes/IfCommand.src/M000042.html +0 -19
  36. data/doc/classes/IfCommand.src/M000043.html +0 -20
  37. data/doc/classes/IfCommand.src/M000044.html +0 -20
  38. data/doc/classes/IfElseCommand.html +0 -189
  39. data/doc/classes/IfElseCommand.src/M000025.html +0 -19
  40. data/doc/classes/IfElseCommand.src/M000026.html +0 -23
  41. data/doc/classes/IfElseCommand.src/M000027.html +0 -20
  42. data/doc/classes/IncludeCommand.html +0 -171
  43. data/doc/classes/IncludeCommand.src/M000019.html +0 -26
  44. data/doc/classes/IncludeCommand.src/M000020.html +0 -28
  45. data/doc/classes/IncludeCommand.src/M000021.html +0 -18
  46. data/doc/classes/IncludeCommandError.html +0 -118
  47. data/doc/classes/LoopCommand.html +0 -197
  48. data/doc/classes/LoopCommand.src/M000001.html +0 -19
  49. data/doc/classes/LoopCommand.src/M000002.html +0 -42
  50. data/doc/classes/LoopCommand.src/M000003.html +0 -20
  51. data/doc/classes/LoopElseCommand.html +0 -190
  52. data/doc/classes/LoopElseCommand.src/M000022.html +0 -19
  53. data/doc/classes/LoopElseCommand.src/M000023.html +0 -23
  54. data/doc/classes/LoopElseCommand.src/M000024.html +0 -20
  55. data/doc/classes/Namespace.html +0 -297
  56. data/doc/classes/Namespace.src/M000034.html +0 -19
  57. data/doc/classes/Namespace.src/M000035.html +0 -18
  58. data/doc/classes/Namespace.src/M000036.html +0 -18
  59. data/doc/classes/Namespace.src/M000037.html +0 -19
  60. data/doc/classes/Namespace.src/M000038.html +0 -36
  61. data/doc/classes/Namespace.src/M000039.html +0 -21
  62. data/doc/classes/Namespace.src/M000040.html +0 -18
  63. data/doc/classes/Namespace.src/M000041.html +0 -18
  64. data/doc/classes/PageTemplate.html +0 -380
  65. data/doc/classes/PageTemplate.src/M000010.html +0 -49
  66. data/doc/classes/PageTemplate.src/M000011.html +0 -18
  67. data/doc/classes/PageTemplate.src/M000012.html +0 -29
  68. data/doc/classes/PageTemplate.src/M000013.html +0 -18
  69. data/doc/classes/PageTemplate.src/M000014.html +0 -18
  70. data/doc/classes/PageTemplate.src/M000015.html +0 -18
  71. data/doc/classes/PageTemplate.src/M000016.html +0 -18
  72. data/doc/classes/PageTemplate.src/M000017.html +0 -18
  73. data/doc/classes/PageTemplate.src/M000018.html +0 -19
  74. data/doc/classes/Syntax/CachedParser.html +0 -163
  75. data/doc/classes/Syntax/CachedParser.src/M000048.html +0 -19
  76. data/doc/classes/Syntax/CachedParser.src/M000049.html +0 -53
  77. data/doc/classes/Syntax/Glossary.html +0 -251
  78. data/doc/classes/Syntax/Glossary.src/M000050.html +0 -20
  79. data/doc/classes/Syntax/Glossary.src/M000051.html +0 -29
  80. data/doc/classes/Syntax/Parser.html +0 -261
  81. data/doc/classes/Syntax/Parser.src/M000052.html +0 -22
  82. data/doc/classes/Syntax/Parser.src/M000053.html +0 -36
  83. data/doc/classes/Syntax/Parser.src/M000054.html +0 -18
  84. data/doc/classes/Syntax/Parser.src/M000055.html +0 -21
  85. data/doc/classes/Syntax/Parser.src/M000056.html +0 -53
  86. data/doc/classes/Syntax/Parser.src/M000057.html +0 -111
  87. data/doc/classes/Syntax.html +0 -139
  88. data/doc/classes/TextCommand.html +0 -185
  89. data/doc/classes/TextCommand.src/M000045.html +0 -18
  90. data/doc/classes/TextCommand.src/M000046.html +0 -18
  91. data/doc/classes/TextCommand.src/M000047.html +0 -18
  92. data/doc/classes/UnlessCommand.html +0 -151
  93. data/doc/classes/UnlessCommand.src/M000028.html +0 -20
  94. data/doc/classes/ValueCommand.html +0 -186
  95. data/doc/classes/ValueCommand.src/M000029.html +0 -18
  96. data/doc/classes/ValueCommand.src/M000030.html +0 -18
  97. data/doc/classes/ValueCommand.src/M000031.html +0 -20
  98. data/doc/created.rid +0 -1
  99. data/doc/files/README_txt.html +0 -224
  100. data/doc/files/lib/PageTemplate_rb.html +0 -119
  101. data/doc/fr_class_index.html +0 -44
  102. data/doc/fr_file_index.html +0 -28
  103. data/doc/fr_method_index.html +0 -83
  104. data/doc/index.html +0 -24
  105. data/doc/rdoc-style.css +0 -208
  106. data/install.rb +0 -1015
  107. data/lib/CVS/Entries +0 -2
  108. data/lib/CVS/Repository +0 -1
  109. data/lib/CVS/Root +0 -1
  110. data/lib/PageTemplate.rb~ +0 -1004
  111. data/pkg/PageTemplate-1.2.0.gem +0 -0
  112. data/tdata/CVS/Entries +0 -28
  113. data/tdata/CVS/Repository +0 -1
  114. data/tdata/CVS/Root +0 -1
  115. data/tdata/cm.txt +0 -3
  116. data/tdata/complex.txt +0 -116
  117. data/tdata/i1.txt +0 -1
  118. data/tdata/i2.txt +0 -7
  119. data/tdata/ib1.txt +0 -7
  120. data/tdata/ib2.txt +0 -13
  121. data/tdata/ie1.txt +0 -4
  122. data/tdata/ie2.txt +0 -15
  123. data/tdata/include.1.txt +0 -1
  124. data/tdata/include.2.txt +0 -1
  125. data/tdata/include.3.txt +0 -1
  126. data/tdata/include.4.nf.out.txt +0 -2
  127. data/tdata/include.4.out.txt +0 -3
  128. data/tdata/include.4.txt +0 -2
  129. data/tdata/include.4a.txt +0 -1
  130. data/tdata/include.4b.txt +0 -2
  131. data/tdata/include.5.txt +0 -2
  132. data/tdata/l1.txt +0 -5
  133. data/tdata/l2.txt +0 -7
  134. data/tdata/metadata.1.txt +0 -5
  135. data/tdata/metadata.2.txt +0 -5
  136. data/tdata/metadata.3.txt +0 -5
  137. data/tdata/metadata.4.txt +0 -5
  138. data/tdata/nm.txt +0 -4
  139. data/tdata/p/CVS/Entries +0 -5
  140. data/tdata/p/CVS/Repository +0 -1
  141. data/tdata/p/CVS/Root +0 -1
  142. data/tdata/p/CVS/b2.txt,t +0 -0
  143. data/tdata/p/_b1.txt +0 -0
  144. data/tdata/p/b1.txt +0 -4
  145. data/tdata/p/b2.txt +0 -4
  146. data/tdata/p/b2.txt~ +0 -4
  147. data/tdata/p/cb1.txt +0 -4
  148. data/tdata/t.txt +0 -2
  149. data/tdata/v1.txt +0 -11
  150. data/tdata/v2.txt +0 -11
data/Changes CHANGED
@@ -1,3 +1,27 @@
1
+ 2.0
2
+ Major changes:
3
+ Entire code refactored and rewritten.
4
+ Parser now iterative
5
+ Commands:
6
+ Changed: Everything is encapsulated in the PageTemplate class
7
+ Changed: If, IfElse, Unless, UnlessElse commands merged
8
+ Changed: Loop, LoopElse merged
9
+ Changed: else/end logic placed into Commands
10
+ Fixed: Loop MetaVariables
11
+ Added: ValueCommand supports 'preprocessors'. var variable :processor
12
+ Added: 'case' command added: optional in PageTemplate/case.rb
13
+ Namespace:
14
+ Fixed: false or nil variables previously caused PT to search up.
15
+ Added: ability to have 'var.name.name2' variable access.
16
+ Parser:
17
+ Changed: Syntax::Glossary became SyntaxGlossary
18
+ Changed: Syntax::Parser became just Parser
19
+ Changed: Parser is now primarily a compiler instead of a template object.
20
+ Changed: else/end logic placed into Commands instead of parser.
21
+ Changed: Iterative process should be faster
22
+ Removed: Use of a disk cache when 'use_cache' is true
23
+ Added: Ability to compile files without setting PageTemplate's current
24
+ @commands to the result.
1
25
  1.2
2
26
  - Added: UnlessCommand (including '[%unless foo %]' syntax)
3
27
  - Added: Loop Metavariables __FIRST__, __LAST__, and __ODD__
data/MANIFEST CHANGED
@@ -1,4 +1,3 @@
1
1
  MANIFEST
2
2
  README.txt
3
- TC_PageTemplate.rb
4
3
  install.rb
data/README.txt CHANGED
@@ -13,7 +13,8 @@ As a side note: if you are using PageTemplate in your projects, or
13
13
  add features to your copy, I'd love to hear about it. If you feel like
14
14
  it.
15
15
 
16
- Brian Wisti (brian@coolnamehere.com)
16
+ Brian Wisti (brianwisti@rubyforge.org)
17
+ Greg Millam (walker@rubyforge.org)
17
18
  http://www.coolnamehere.com/products/pagetemplate/
18
19
 
19
20
  == Features
@@ -35,13 +36,13 @@ http://www.coolnamehere.com/products/pagetemplate/
35
36
  De-Compress archive and enter its top directory.
36
37
  Then type:
37
38
 
38
- $ ruby install.rb config
39
- $ ruby install.rb setup
40
39
  ($ su)
41
- # ruby install.rb install
40
+ # ruby setup.rb
42
41
 
43
42
  You can also install files into your favorite directory
44
- by supplying install.rb some options. Try "ruby install.rb --help".
43
+ by supplying setup.rb some options. Try "ruby setup.rb --help".
44
+ Since we don't really know how setup.rb works, we've included
45
+ the English-language version of the setup usage file. Enjoy.
45
46
 
46
47
  === Install With Rake
47
48
 
@@ -55,7 +56,7 @@ Download the gem file from the
55
56
 
56
57
  Then, use the gem command to install it:
57
58
 
58
- $ sudo gem install -l PageTemplate-1.1.1.gem
59
+ $ sudo gem install -l PageTemplate-2.0.0.gem
59
60
 
60
61
  I think that's all there is to it. I'm new to gems, though, so let me
61
62
  know if I missed something.
@@ -72,7 +73,7 @@ http://coolnamehere.com/products/pagetemplate/
72
73
 
73
74
  The MIT License
74
75
 
75
- Copyright (c) 2002-2005 Brian Wisti
76
+ Copyright (c) 2002-2005 Brian Wisti, Greg Millam
76
77
 
77
78
  Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
78
79
 
@@ -82,4 +83,5 @@ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLI
82
83
 
83
84
 
84
85
 
85
- Brian Wisti (brian@coolnamehere.com)
86
+ Brian Wisti (brianwisti@rubyforge.org)
87
+ Greg Millam (walker@rubyforge.org)
data/Rakefile CHANGED
@@ -8,21 +8,39 @@ task :default => [:all, :test]
8
8
 
9
9
  task :all do
10
10
  ruby %{-c lib/PageTemplate.rb}
11
- ruby %{-c TC_PageTemplate.rb}
12
11
  end
13
12
 
14
13
  task :test do
15
- ruby %{-w TC_PageTemplate.rb}
14
+ ruby %{-w -Ilib test.rb}
15
+ end
16
+
17
+ task :oldTests do
18
+ ruby %{-w -Ilib TC_PageTemplate.rb}
19
+ end
20
+
21
+ task :missingTests do
22
+ filename = "../missing-tests.rb"
23
+ sh %{cd lib && ZenTest PageTemplate.rb PageTemplate/*.rb ../test.rb > #{filename}}
24
+ puts "Missing tests are in #{filename}"
25
+ end
26
+
27
+ task :newTests do
28
+ filename = "test.rb"
29
+ if File.exists?(filename)
30
+ puts "File exists"
31
+ else
32
+ puts "File does not exist."
33
+ sh %{cd lib && ZenTest PageTemplate.rb PageTemplate/*.rb > ../#{filename}}
34
+ end
35
+ puts "Tests are in #{filename}"
16
36
  end
17
37
 
18
38
  task :install do
19
- ruby %{install.rb config}
20
- ruby %{install.rb setup}
21
- ruby %{install.rb install}
39
+ ruby %{setup.rb}
22
40
  end
23
41
 
24
42
  task :doc do
25
- sh %{rdoc lib/PageTemplate.rb README.txt}
43
+ sh %{rdoc lib/PageTemplate.rb README.txt lib/PageTemplate/*.rb}
26
44
  end
27
45
 
28
46
  task :cnh_doc do
@@ -31,16 +49,16 @@ end
31
49
 
32
50
  spec = Gem::Specification.new do |s|
33
51
  s.name = "PageTemplate"
34
- s.version = "1.2.0"
52
+ s.version = "2.0.0"
35
53
  s.author = "Brian Wisti"
36
- s.email = "brian@coolnamehere.com"
54
+ s.email = "brianwisti@rubyforge.org"
37
55
  s.homepage = "http://coolnamehere.com/products/pagetemplate"
38
56
  s.platform = Gem::Platform::RUBY
39
57
  s.summary = "A simple templating system for Web sites."
40
58
  s.files = Dir.glob("**/*")
41
59
  s.require_path = "lib"
42
60
  s.autorequire = "PageTemplate.rb"
43
- s.test_file = "TC_PageTemplate.rb"
61
+ s.test_file = "test.rb"
44
62
  s.has_rdoc = true
45
63
  s.extra_rdoc_files = ["README.txt"]
46
64
  end
@@ -50,5 +68,8 @@ Rake::GemPackageTask.new(spec) do |pkg|
50
68
  end
51
69
 
52
70
  task :gem do
71
+ if File.exists?("CVS")
72
+ raise RuntimeError, "Trying to make a gem in CVS directory!"
73
+ end
53
74
  sh %{rake pkg/PageTemplate-#{spec.version}.gem}
54
75
  end
@@ -0,0 +1,72 @@
1
+ # case.rb
2
+ #
3
+ # This is a demonstration of adding a non-default command to
4
+ # PageTemplate's default glossary.
5
+ #
6
+ # Note that it adds itself to the glossary =).
7
+
8
+ class PageTemplate
9
+ # CaseCommand provides switch-command functionality.
10
+ # [% case variable %]
11
+ # [% when literal1 %]
12
+ # [% when literal2 %]
13
+ # [% when literal3 %]
14
+ # [% else %]
15
+ # [% end %]
16
+ class CaseCommand < StackableCommand
17
+ attr_reader :current_case
18
+
19
+ # +command+ is a variable that is evaluated against the namespace
20
+ # on execution, and then tested against the literals of when. It
21
+ # must return a string literal.
22
+ def initialize(command)
23
+ /^case ((\w+)(\.\w+)*)$/i =~ command
24
+ @called_as = 'case'
25
+ @value = $1
26
+ @blocks = {}
27
+ @current_case = nil
28
+ @default = BlockCommand.new
29
+ end
30
+ # Adds a command to the current case, or to the 'else'
31
+ def add(command)
32
+ unless @current_case
33
+ @default.add command
34
+ else
35
+ @blocks[@current_case].add command
36
+ end
37
+ end
38
+ # 'when' and 'else' modify this command.
39
+ def modifies?(cmd)
40
+ case cmd
41
+ when /^when (.+)$/
42
+ @current_case = $1
43
+ @blocks[$1] = BlockCommand.new unless @blocks.has_key?($1)
44
+ true
45
+ when /^else$/
46
+ @current_case = nil
47
+ true
48
+ else
49
+ false
50
+ end
51
+ end
52
+ # If namespace.get(@value) exists in the 'when' clauses, then
53
+ # print out that block.
54
+ def output(namespace=nil)
55
+ val = namespace.get(@value)
56
+ if @blocks.has_key?(val)
57
+ @blocks[val].output(namespace)
58
+ else
59
+ @default.output(namespace)
60
+ end
61
+ end
62
+ def to_s
63
+ str = "[ Case: "
64
+ @blocks.each do |key,val|
65
+ str << " #{key}: [#{val}]"
66
+ end
67
+ str << " else #{@default.to_s}"
68
+ str << " ]"
69
+ end
70
+ end
71
+ DEFAULTGLOSSARY.define(/^case (\w+)(\.\w+)*$/,CaseCommand)
72
+ end