Sha256: f316d1f13fe1dfbe9c643eb1a8a9d196a57a2b8deb83cddfd0d3582a2c8b64ee

Contents?: true

Size: 1.48 KB

Versions: 13

Compression:

Stored size: 1.48 KB

Contents

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

Version data entries

13 entries across 13 versions & 3 rubygems

Version Path
iownbey-rdoc-2.0.1 lib/rdoc/template.rb
shoesgem-0.1514.0 shoes/ruby/lib/rdoc/template.rb
shoesgem-0.1480.0 shoes/ruby/lib/rdoc/template.rb
shoesgem-0.1469.0 shoes/ruby/lib/rdoc/template.rb
shoesgem-0.1430.0 shoes/ruby/lib/rdoc/template.rb
shoesgem-0.1429.0 shoes/ruby/lib/rdoc/template.rb
shoesgem-0.1428.0 shoes/ruby/lib/rdoc/template.rb
shoesgem-0.1426.0 shoes/ruby/lib/rdoc/template.rb
shoesgem-0.1424.0 shoes/ruby/lib/rdoc/template.rb
rdoc-2.0.0 lib/rdoc/template.rb
rdoc-2.2.0 lib/rdoc/template.rb
rdoc-2.2.1 lib/rdoc/template.rb
rdoc-2.1.0 lib/rdoc/template.rb