2008-01-07 13:40:50 +03:00
|
|
|
require 'erb'
|
|
|
|
|
2008-04-26 20:14:19 +04:00
|
|
|
module RDoc; end
|
|
|
|
|
2008-01-07 13:40:50 +03:00
|
|
|
##
|
2008-04-26 20:14:19 +04:00
|
|
|
# An ERb wrapper that allows nesting of one ERb template inside another.
|
2003-12-01 10:12:49 +03:00
|
|
|
#
|
2008-01-07 13:40:50 +03:00
|
|
|
# This TemplatePage operates similarly to RDoc 1.x's TemplatePage, but uses
|
2008-04-26 20:14:19 +04:00
|
|
|
# ERb instead of a custom template language.
|
2003-12-01 10:12:49 +03:00
|
|
|
#
|
2008-01-07 13:40:50 +03:00
|
|
|
# Converting from a RDoc 1.x template to an RDoc 2.x template is fairly easy.
|
2003-12-01 10:12:49 +03:00
|
|
|
#
|
2008-01-07 13:40:50 +03:00
|
|
|
# * %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 %>
|
2003-12-01 10:12:49 +03:00
|
|
|
#
|
2008-01-07 13:40:50 +03:00
|
|
|
# To make nested loops easier to convert, start by converting START statements
|
|
|
|
# to:
|
2003-12-01 10:12:49 +03:00
|
|
|
#
|
2008-01-07 13:40:50 +03:00
|
|
|
# <% values["blah"].each do |blah| $stderr.puts blah.keys %>
|
2003-12-01 10:12:49 +03:00
|
|
|
#
|
2008-01-07 13:40:50 +03:00
|
|
|
# So you can see what is being used inside which loop.
|
2003-12-01 10:12:49 +03:00
|
|
|
|
2008-01-07 09:56:46 +03:00
|
|
|
class RDoc::TemplatePage
|
2003-12-01 10:12:49 +03:00
|
|
|
|
2008-01-07 13:40:50 +03:00
|
|
|
##
|
|
|
|
# Create a new TemplatePage that will use +templates+.
|
2003-12-01 10:12:49 +03:00
|
|
|
|
|
|
|
def initialize(*templates)
|
2008-01-07 13:40:50 +03:00
|
|
|
@templates = templates
|
2003-12-01 10:12:49 +03:00
|
|
|
end
|
|
|
|
|
2008-01-07 13:40:50 +03:00
|
|
|
##
|
|
|
|
# Returns "<a href=\"#{ref}\">#{name}</a>"
|
2003-12-01 10:12:49 +03:00
|
|
|
|
2008-01-07 13:40:50 +03:00
|
|
|
def href(ref, name)
|
|
|
|
if ref then
|
|
|
|
"<a href=\"#{ref}\">#{name}</a>"
|
|
|
|
else
|
|
|
|
name
|
2003-12-01 10:12:49 +03:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2008-01-07 13:40:50 +03:00
|
|
|
##
|
|
|
|
# Process the template using +values+, writing the result to +io+.
|
2003-12-01 10:12:49 +03:00
|
|
|
|
2008-01-07 13:40:50 +03:00
|
|
|
def write_html_on(io, values)
|
|
|
|
b = binding
|
2008-01-08 12:07:31 +03:00
|
|
|
template_include = ""
|
2003-12-01 10:12:49 +03:00
|
|
|
|
2008-01-07 13:40:50 +03:00
|
|
|
@templates.reverse_each do |template|
|
|
|
|
template_include = ERB.new(template).result b
|
|
|
|
end
|
2003-12-01 10:12:49 +03:00
|
|
|
|
2008-01-07 13:40:50 +03:00
|
|
|
io.write template_include
|
2003-12-01 10:12:49 +03:00
|
|
|
end
|
|
|
|
|
|
|
|
end
|
|
|
|
|