Module: Rock::Doc::HTML
- Defined in:
- lib/rock/doc.rb
Defined Under Namespace
Classes: PackageRenderingContext, RenderingContext, TaskRenderingContext, TypeRenderingContext, VCSRenderingContext
Constant Summary
collapse
- TEMPLATE_DIR =
File.expand_path(File.join('templates', 'html'), File.dirname(__FILE__))
Class Attribute Summary collapse
Class Method Summary
collapse
Class Attribute Details
.templates ⇒ Object
Returns the value of attribute templates
14
15
16
|
# File 'lib/rock/doc.rb', line 14
def templates
@templates
end
|
Class Method Details
.allocate_help_id ⇒ Object
36
37
38
|
# File 'lib/rock/doc.rb', line 36
def self.allocate_help_id
@help_id += 1
end
|
.escape_html(string) ⇒ Object
18
19
20
21
22
|
# File 'lib/rock/doc.rb', line 18
def self.escape_html(string)
string.
gsub('<', '<').
gsub('>', '>')
end
|
.help_tip(doc) ⇒ Object
40
41
42
43
|
# 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) ⇒ Object
45
46
47
48
49
50
|
# 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) ⇒ Object
24
25
26
27
28
29
30
31
32
33
|
# File 'lib/rock/doc.rb', line 24
def self.obscure_email(email)
return nil if email.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) ⇒ Object
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
|
# 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) ⇒ Object
70
71
72
73
74
75
76
77
78
79
80
81
|
# 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) ⇒ Object
60
61
62
63
64
65
66
67
68
|
# 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) ⇒ Object
.template_path(*relpath) ⇒ Object
52
53
54
55
56
57
58
|
# 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
|