PageTemplate 2.1.2 → 2.1.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/Changes +13 -0
- data/Rakefile +1 -1
- data/lib/PageTemplate/commands.rb +3 -0
- data/lib/PageTemplate/htglossary.rb +22 -12
- data/lib/PageTemplate/parser.rb +39 -22
- data/lib/PageTemplate.rb +0 -1
- data/setup-usage.txt +1 -1
- data/setup.rb +16 -8
- data/test.rb +34 -0
- metadata +12 -10
data/Changes
CHANGED
@@ -1,3 +1,16 @@
|
|
1
|
+
2.1.3:
|
2
|
+
Bugfixes:
|
3
|
+
HTGlossary didn't survive the change from 2.0 to 2.1. I've
|
4
|
+
added unit tests and fixed the HTGlossary bugs. Whoops.
|
5
|
+
setup.rb attempted to chmod every directory in its path on install.
|
6
|
+
Report and fix by: Lars Olsson
|
7
|
+
Changes:
|
8
|
+
If a glossary directive has multiple captures, PT will use
|
9
|
+
the first non-nil one.
|
10
|
+
Namespaces now use parser.method_separator. Defined on creation
|
11
|
+
by PageTemplate.new('method_separator' => <regex>).
|
12
|
+
Inspired by Jeremy Apthorp and YAML paths.
|
13
|
+
|
1
14
|
2.1.2:
|
2
15
|
Bugfixes:
|
3
16
|
Added File.chmod statements to setup.rb to fix rake install.
|
data/Rakefile
CHANGED
@@ -413,6 +413,7 @@ class PageTemplate
|
|
413
413
|
ns['__FIRST__'] = (i == 1) ? true : false
|
414
414
|
ns['__LAST__'] = (i == len) ? true : false
|
415
415
|
ns['__ODD__'] = odd
|
416
|
+
ns['__INDEX__'] = i-1
|
416
417
|
odd = ! odd
|
417
418
|
i += 1
|
418
419
|
@commands.output(ns)
|
@@ -426,6 +427,7 @@ class PageTemplate
|
|
426
427
|
ns['__FIRST__'] = (i == 1) ? true : false
|
427
428
|
ns['__LAST__'] = (i == len) ? true : false
|
428
429
|
ns['__ODD__'] = odd
|
430
|
+
ns['__INDEX__'] = i-1
|
429
431
|
odd = ! odd
|
430
432
|
ns[iterator] = item
|
431
433
|
i += 1
|
@@ -437,6 +439,7 @@ class PageTemplate
|
|
437
439
|
ns['__FIRST__'] = (i == 1) ? true : false
|
438
440
|
ns['__LAST__'] = (i == len) ? true : false
|
439
441
|
ns['__ODD__'] = odd
|
442
|
+
ns['__INDEX__'] = i-1
|
440
443
|
@iterators.each_with_index do |iterator,index|
|
441
444
|
ns[iterator] = list[index]
|
442
445
|
end
|
@@ -7,39 +7,49 @@
|
|
7
7
|
|
8
8
|
class PageTemplate
|
9
9
|
class HTGlossary < SyntaxGlossary
|
10
|
-
@directive =
|
10
|
+
# @directive = /<(?:!--\s*(tmpl.+?)\s*--|(TMPL.+?)(?:\/)?)>/mi
|
11
|
+
@directive = /(?:<\s*((?:\/?)TMPL_.*?)>|<!--\s*((?:\/?)TMPL.+?)\s*-->)/i
|
11
12
|
|
12
|
-
default { |command
|
13
|
-
|
13
|
+
default { |command|
|
14
|
+
puts "default: #{command}"
|
15
|
+
TextCommand.new("<!--#{command}-->")
|
14
16
|
}
|
15
17
|
|
16
18
|
define(/^tmpl_var (?:name=)?"?((?:\w+)(?:\.\w+\??)*)"?(?:\s+processor="?(\w+)"?)?$/i) {
|
17
|
-
|match
|
19
|
+
|match|
|
18
20
|
# Value, Preprocessor, Parser
|
19
|
-
ValueCommand.new(match[1],match[2]
|
21
|
+
ValueCommand.new(match[1],match[2])
|
20
22
|
}
|
21
23
|
|
22
24
|
define(/^(tmpl_if|tmpl_unless) (?:name=)?"?((\w+)(\.\w+\??)*)"?$/i) {
|
23
|
-
|match
|
25
|
+
|match|
|
24
26
|
# Called_As, Value, parser
|
25
|
-
IfCommand.new(match[1],match[2]
|
27
|
+
IfCommand.new(match[1],match[2])
|
26
28
|
}
|
27
29
|
|
28
30
|
define(/^(tmpl_loop) (?:name=)"?(\w+(?:\.\w+\??)*)"?(?:\s+iterators?="?((?:\s*\w+)+)"?)?$/i) {
|
29
|
-
|match
|
31
|
+
|match|
|
30
32
|
# Called_As, Value, Iterators
|
31
33
|
LoopCommand.new(match[1],match[2],match[3])
|
32
34
|
}
|
33
35
|
|
34
36
|
define(/^tmpl_include (?:name=|file=)?"?((\w+)(?:\.\w+\??)*)"?$/i) {
|
35
|
-
|match
|
37
|
+
|match|
|
36
38
|
# Value, parser
|
37
|
-
IncludeCommand.new(match[1]
|
39
|
+
IncludeCommand.new(match[1])
|
38
40
|
}
|
39
41
|
|
40
42
|
# Command#else's expect only to be called
|
43
|
+
modifier(:elsif) { |cmd,command|
|
44
|
+
if command =~ /^\s*tmpl_else\s*$/i
|
45
|
+
cmd.else
|
46
|
+
true
|
47
|
+
else
|
48
|
+
false
|
49
|
+
end
|
50
|
+
}
|
41
51
|
modifier(:else) { |cmd,command|
|
42
|
-
if command =~
|
52
|
+
if command =~ /^\s*tmpl_else\s*$/i
|
43
53
|
cmd.else
|
44
54
|
true
|
45
55
|
else
|
@@ -47,7 +57,7 @@ class PageTemplate
|
|
47
57
|
end
|
48
58
|
}
|
49
59
|
modifier(:end) { |cmd,command|
|
50
|
-
if command =~
|
60
|
+
if command =~ /^\s*\/\s*#{cmd.called_as}\s*$/i
|
51
61
|
cmd.end
|
52
62
|
true
|
53
63
|
else
|
data/lib/PageTemplate/parser.rb
CHANGED
@@ -53,41 +53,52 @@ class PageTemplate
|
|
53
53
|
# (and further results) to premit accessing attributes of objects.
|
54
54
|
def get(val,clean_rescue=true)
|
55
55
|
args = parser.args
|
56
|
-
clean_rescue = !args['raise_on_error'] if clean_rescue
|
57
56
|
@values ||= {}
|
58
57
|
@object ||= nil
|
59
|
-
|
60
|
-
|
58
|
+
|
59
|
+
clean_rescue = !args['raise_on_error'] if clean_rescue
|
60
|
+
|
61
|
+
val.gsub!(/[#{Regexp.escape(parser.method_separators)}]/,'.')
|
62
|
+
|
63
|
+
key, rest = val.split(/\./, 2)
|
64
|
+
|
61
65
|
value = case
|
62
66
|
when @values.has_key?(key)
|
63
67
|
@values[key]
|
64
|
-
when
|
68
|
+
when !@object
|
69
|
+
return @parent.get(val) if @parent
|
70
|
+
return nil
|
71
|
+
when @object.respond_to?(:has_key?)
|
65
72
|
@values[key] = @object[key]
|
66
|
-
when @object.respond_to?(key.to_sym)
|
67
|
-
|
68
|
-
|
69
|
-
when @object && key == '__ITEM__'
|
73
|
+
when @object.respond_to?(sym = key.to_sym)
|
74
|
+
@values[key] = @object.send(sym)
|
75
|
+
when key == '__ITEM__'
|
70
76
|
@object
|
71
|
-
when @parent
|
72
|
-
# Return what the parent gets
|
73
|
-
return @parent.get(val)
|
74
77
|
else
|
75
|
-
# We're the global namespace
|
76
78
|
nil
|
77
79
|
end
|
78
80
|
|
79
81
|
if rest
|
82
|
+
names = [key]
|
80
83
|
rest.split(/\./).each do |i|
|
84
|
+
names << i
|
85
|
+
name = names.join('.')
|
81
86
|
begin
|
82
|
-
value =
|
83
|
-
|
84
|
-
value[i]
|
85
|
-
when value.respond_to?(:[]) && i =~ /^\d+$/
|
86
|
-
value[i.to_i]
|
87
|
-
when value.respond_to?(i)
|
88
|
-
value.send(i)
|
87
|
+
value = if @values.has_key?(name)
|
88
|
+
@values[name]
|
89
89
|
else
|
90
|
-
|
90
|
+
@values[name] = value = case
|
91
|
+
when @values.has_key?(name)
|
92
|
+
@values[name]
|
93
|
+
when value.respond_to?(:has_key?) # Hash
|
94
|
+
value[i]
|
95
|
+
when value.respond_to?(:[]) && i =~ /^\d+$/ # Array
|
96
|
+
value[i.to_i]
|
97
|
+
when value.respond_to?(i) # Just a method
|
98
|
+
value.send(i)
|
99
|
+
else
|
100
|
+
nil
|
101
|
+
end
|
91
102
|
end
|
92
103
|
rescue NoMethodError => er
|
93
104
|
return nil
|
@@ -193,11 +204,15 @@ class PageTemplate
|
|
193
204
|
return "[ Unable to open file #{fn} because of #{er.message} ]"
|
194
205
|
end
|
195
206
|
end
|
207
|
+
|
196
208
|
def cache(name,cmds)
|
197
209
|
fn = get_filename(name)
|
198
210
|
@cache[fn] = cmds.dup
|
199
211
|
@mtime[fn] = Time.now.to_i
|
200
212
|
end
|
213
|
+
|
214
|
+
# Return the absolute pathname of the first name +file+
|
215
|
+
# found in the include_paths.
|
201
216
|
def get_filename(file)
|
202
217
|
file = file.gsub(/\.\.\//,'')
|
203
218
|
file.untaint
|
@@ -312,6 +327,7 @@ class PageTemplate
|
|
312
327
|
|
313
328
|
# Command#else's expect only to be called
|
314
329
|
modifier(:else) { |cmd,command|
|
330
|
+
puts "Uh, whoops? #{command}" if command =~ /tmpl/mi
|
315
331
|
case command
|
316
332
|
when /^(else|no|empty)$/i
|
317
333
|
cmd.else
|
@@ -428,7 +444,7 @@ class PageTemplate
|
|
428
444
|
class Parser
|
429
445
|
attr_reader :preprocessor, :default_processor
|
430
446
|
attr_reader :glossary, :namespace, :source
|
431
|
-
attr_reader :args, :commands
|
447
|
+
attr_reader :args, :commands, :method_separators
|
432
448
|
|
433
449
|
# This is corny, but recent_parser returns the most recently created
|
434
450
|
# Parser.
|
@@ -451,6 +467,7 @@ class PageTemplate
|
|
451
467
|
@glossary = args['glossary'] || DefaultGlossary
|
452
468
|
@preprocessor = args['preprocessor'] || DefaultPreprocessor
|
453
469
|
@default_processor = args['default_processor'] || :unescaped
|
470
|
+
@method_separators = args['method_separators'] || './'
|
454
471
|
@source = (args['source'] || FileSource).new(@args)
|
455
472
|
@commands = nil
|
456
473
|
end
|
@@ -486,7 +503,7 @@ class PageTemplate
|
|
486
503
|
closer = nil
|
487
504
|
while (m = rx.match(body))
|
488
505
|
pre = m.pre_match
|
489
|
-
command = m[1].strip.gsub(/\s+/,' ')
|
506
|
+
command = m[1..-1].compact.first.strip.gsub(/\s+/,' ')
|
490
507
|
body = m.post_match
|
491
508
|
|
492
509
|
# Convert all pre-text to a TextCommand
|
data/lib/PageTemplate.rb
CHANGED
data/setup-usage.txt
CHANGED
data/setup.rb
CHANGED
@@ -452,8 +452,10 @@ module FileOperations
|
|
452
452
|
end
|
453
453
|
dirs.each_index do |idx|
|
454
454
|
path = dirs[0..idx].join('')
|
455
|
-
|
456
|
-
|
455
|
+
unless File.dir?(path)
|
456
|
+
Dir.mkdir path
|
457
|
+
File.chmod(0755,path)
|
458
|
+
end
|
457
459
|
end
|
458
460
|
end
|
459
461
|
|
@@ -1012,12 +1014,16 @@ class ToplevelInstallerMulti < ToplevelInstaller
|
|
1012
1014
|
#
|
1013
1015
|
|
1014
1016
|
def each_selected_installers
|
1015
|
-
|
1016
|
-
|
1017
|
+
unless File.dir?('packages')
|
1018
|
+
Dir.mkdir 'packages'
|
1019
|
+
File.chmod(0755,'packages')
|
1020
|
+
end
|
1017
1021
|
@selected.each do |pack|
|
1018
1022
|
$stderr.puts "Processing the package `#{pack}' ..." if @options['verbose']
|
1019
|
-
|
1020
|
-
|
1023
|
+
unless File.dir?("packages/#{pack}")
|
1024
|
+
Dir.mkdir "packages/#{pack}"
|
1025
|
+
File.chmod(0755,"packages/#{pack}")
|
1026
|
+
end
|
1021
1027
|
Dir.chdir "packages/#{pack}"
|
1022
1028
|
yield @installers[pack]
|
1023
1029
|
Dir.chdir '../..'
|
@@ -1333,8 +1339,10 @@ class Installer
|
|
1333
1339
|
return unless File.dir?("#{@srcdir}/#{rel}")
|
1334
1340
|
|
1335
1341
|
dir = File.basename(rel)
|
1336
|
-
|
1337
|
-
|
1342
|
+
unless File.dir?(dir)
|
1343
|
+
Dir.mkdir dir
|
1344
|
+
File.chmod(0755,dir)
|
1345
|
+
end
|
1338
1346
|
prevdir = Dir.pwd
|
1339
1347
|
Dir.chdir dir
|
1340
1348
|
$stderr.puts '---> ' + rel if verbose?
|
data/test.rb
CHANGED
@@ -654,6 +654,40 @@ module TestPageTemplate
|
|
654
654
|
end
|
655
655
|
end
|
656
656
|
|
657
|
+
class TestHTGlossary < Test::Unit::TestCase
|
658
|
+
def setup
|
659
|
+
begin
|
660
|
+
require 'PageTemplate/htglossary'
|
661
|
+
@parser = PageTemplate::Parser.new('glossary' => PageTemplate::HTGlossary)
|
662
|
+
rescue Exception => er
|
663
|
+
puts "error: #{er}"
|
664
|
+
@parser = nil
|
665
|
+
end
|
666
|
+
end
|
667
|
+
def test_comment_style
|
668
|
+
assert(@parser,'HTGlossary parser was not created')
|
669
|
+
tmpl = @parser.parse('<!-- TMPL_VAR foo -->')
|
670
|
+
tmpl['foo'] = 'bar'
|
671
|
+
assert_equal('bar',tmpl.output,'A TMPL_VAR command by itself')
|
672
|
+
tmpl = @parser.parse('<!-- TMPL_IF foo -->foo<!--TMPL_ELSE-->bar<!-- /TMPL_IF -->')
|
673
|
+
tmpl['foo'] = true
|
674
|
+
assert_equal('foo',tmpl.output,'TMPL_IF does not work in comment style')
|
675
|
+
tmpl['foo'] = false
|
676
|
+
assert_equal('bar',tmpl.output,'TMPL_IF does not work in comment style')
|
677
|
+
end
|
678
|
+
def test_tag_style
|
679
|
+
assert(@parser,'HTGlossary parser was not created')
|
680
|
+
tmpl = @parser.parse('<TMPL_VAR foo>')
|
681
|
+
tmpl['foo'] = 'bar'
|
682
|
+
assert_equal('bar',tmpl.output,'A TMPL_VAR command by itself')
|
683
|
+
tmpl = @parser.parse('<TMPL_IF foo>foo<TMPL_ELSE>bar</TMPL_IF>')
|
684
|
+
tmpl['foo'] = true
|
685
|
+
assert_equal('foo',tmpl.output,'TMPL_IF does not work in comment style')
|
686
|
+
tmpl['foo'] = false
|
687
|
+
assert_equal('bar',tmpl.output,'TMPL_IF does not work in comment style')
|
688
|
+
end
|
689
|
+
end
|
690
|
+
|
657
691
|
class TestValueCommand < Test::Unit::TestCase
|
658
692
|
def test_output
|
659
693
|
p = PageTemplate::Parser.new()
|
metadata
CHANGED
@@ -1,10 +1,10 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
|
-
rubygems_version: 0.8.
|
2
|
+
rubygems_version: 0.8.11
|
3
3
|
specification_version: 1
|
4
4
|
name: PageTemplate
|
5
5
|
version: !ruby/object:Gem::Version
|
6
|
-
version: 2.1.
|
7
|
-
date: 2005-
|
6
|
+
version: 2.1.3
|
7
|
+
date: 2005-10-30 00:00:00 -07:00
|
8
8
|
summary: A simple templating system for Web sites.
|
9
9
|
require_paths:
|
10
10
|
- lib
|
@@ -24,25 +24,27 @@ required_ruby_version: !ruby/object:Gem::Version::Requirement
|
|
24
24
|
version: 0.0.0
|
25
25
|
version:
|
26
26
|
platform: ruby
|
27
|
+
signing_key:
|
28
|
+
cert_chain:
|
27
29
|
authors:
|
28
30
|
- Brian Wisti
|
29
31
|
files:
|
32
|
+
- Changes
|
30
33
|
- lib
|
31
|
-
-
|
34
|
+
- MANIFEST
|
32
35
|
- Rakefile
|
33
|
-
- tdata
|
34
|
-
- Changes
|
35
|
-
- test.rb
|
36
36
|
- README.txt
|
37
|
+
- setup-usage.txt
|
37
38
|
- setup.rb
|
38
|
-
-
|
39
|
+
- tdata
|
39
40
|
- test-install.rb
|
41
|
+
- test.rb
|
40
42
|
- lib/PageTemplate
|
41
43
|
- lib/PageTemplate.rb
|
42
|
-
- lib/PageTemplate/
|
44
|
+
- lib/PageTemplate/case.rb
|
43
45
|
- lib/PageTemplate/commands.rb
|
44
46
|
- lib/PageTemplate/htglossary.rb
|
45
|
-
- lib/PageTemplate/
|
47
|
+
- lib/PageTemplate/parser.rb
|
46
48
|
- tdata/dummy.txt
|
47
49
|
test_files:
|
48
50
|
- test.rb
|