blob: 53d0e3ce684a6f60f9a2b3fc62eef1e098755f2f (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
|
require 'erb'
module RDoc; end
##
# An ERb wrapper that allows nesting of one ERb template inside another.
#
# This TemplatePage operates similarly to RDoc 1.x's TemplatePage, but uses
# ERb instead of a custom template language.
#
# Converting from a RDoc 1.x template to an RDoc 2.x template is fairly easy.
#
# * %blah% becomes <%= values["blah"] %>
# * !INCLUDE! becomes <%= template_include %>
# * HREF:aref:name becomes <%= href values["aref"], values["name"] %>
# * IF:blah becomes <% if values["blah"] then %>
# * IFNOT:blah becomes <% unless values["blah"] then %>
# * ENDIF:blah becomes <% end %>
# * START:blah becomes <% values["blah"].each do |blah| %>
# * END:blah becomes <% end %>
#
# To make nested loops easier to convert, start by converting START statements
# to:
#
# <% values["blah"].each do |blah| $stderr.puts blah.keys %>
#
# So you can see what is being used inside which loop.
class RDoc::TemplatePage
##
# Create a new TemplatePage that will use +templates+.
def initialize(*templates)
@templates = templates
end
##
# Returns "<a href=\"#{ref}\">#{name}</a>"
def href(ref, name)
if ref then
"<a href=\"#{ref}\">#{name}</a>"
else
name
end
end
##
# Process the template using +values+, writing the result to +io+.
def write_html_on(io, values)
b = binding
template_include = ""
@templates.reverse_each do |template|
template_include = ERB.new(template).result b
end
io.write template_include
end
end
|