module Rock::Doc::HTML
Constants
- TEMPLATE_DIR
Attributes
templates[R]
Public Class Methods
allocate_help_id()
click to toggle source
# File lib/rock/doc.rb, line 36 def self.allocate_help_id @help_id += 1 end
escape_html(string)
click to toggle source
# File lib/rock/doc.rb, line 18 def self.escape_html(string) string. gsub('<', '<'). gsub('>', '>') end
help_tip(doc)
click to toggle source
# File lib/rock/doc.rb, line 40 def self.help_tip(doc) id = allocate_help_id "<span class=\"help_trigger\" id=\"#{id}\"><img src=\"{relocatable: /img/help.png}\" /></span><div class=\"help\" id=\"help_#{id}\">#{doc}</div>" end
load_template(full_path)
click to toggle source
# File lib/rock/doc.rb, line 45 def self.load_template(full_path) if template = @templates[full_path] return template end @templates[full_path] = ERB.new(File.read(full_path), nil, nil, full_path.gsub(/[\/\.-]/, '_')) end
obscure_email(email)
click to toggle source
# File lib/rock/doc.rb, line 24 def self.obscure_email(email) return nil if email.nil? #Don't bother if the parameter is nil. lower = ('a'..'z').to_a upper = ('A'..'Z').to_a email.split('').map { |char| output = lower.index(char) + 97 if lower.include?(char) output = upper.index(char) + 65 if upper.include?(char) output ? "&##{output};" : (char == '@' ? '@' : char) }.join end
render_object(object, *template_path)
click to toggle source
# File lib/rock/doc.rb, line 102 def self.render_object(object, *template_path) if template_path.last.kind_of?(Hash) options = template_path.pop else options = Hash.new end options = Kernel.validate_options options, :context => nil context = options[:context] || rendering_context_for(object) if template_path.empty? template_path = context.default_template if !template_path || template_path.empty? raise ArgumentError, "no default fragment defined for #{object}, of class #{object.class}" end end context.render(*template_path) rescue Exception => e raise e, "failed to render object #{object}: #{e.message}", e.backtrace end
render_page(body)
click to toggle source
# File lib/rock/doc.rb, line 70 def self.render_page(body) html =<<-EOF <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> <html xmlns="http://www.w3.org/1999/xhtml" lang="en"> <head> <link rel="stylesheet" href="file://#{File.join(Rock::Doc::HTML.template_path, "style.css")}" type="text/css" /> </head> <body> #{body} </body> EOF end
render_template(*path)
click to toggle source
# File lib/rock/doc.rb, line 60 def self.render_template(*path) binding = path.pop path = template_path(*path) template = load_template(path) begin template.result(binding) rescue Exception => e raise e, "failed to render #{File.join(*path)}: #{e.message}", e.backtrace end end
rendering_context_for(object)
click to toggle source
# File lib/rock/doc.rb, line 83 def self.rendering_context_for(object) case object when Autoproj::PackageDefinition PackageRenderingContext.new(object) when Autoproj::VCSDefinition VCSRenderingContext.new(object) when Orocos::Spec::TaskContext TaskRenderingContext.new(object) when Class if object <= Typelib::Type TypeRenderingContext.new(object) else RenderingContext.new(object) end else RenderingContext.new(object) end end
template_path(*relpath)
click to toggle source
# File lib/rock/doc.rb, line 52 def self.template_path(*relpath) if relpath.empty? TEMPLATE_DIR else File.expand_path(File.join(*relpath), TEMPLATE_DIR) end end