Class: Fdoc::HtmlPresenter
- Inherits:
-
Object
- Object
- Fdoc::HtmlPresenter
show all
- Defined in:
- lib/fdoc/presenters/html_presenter.rb
Overview
HtmlPresenters assist in generating Html for fdoc classes. HtmlPresenters is an abstract class with a lot of helper methods for URLs and common text styling tasks (like #render_markdown and #render_json)
Instance Attribute Summary collapse
Instance Method Summary
collapse
Constructor Details
#initialize(options = {}) ⇒ HtmlPresenter
12
13
14
|
# File 'lib/fdoc/presenters/html_presenter.rb', line 12
def initialize(options = {})
@options = options
end
|
Instance Attribute Details
#options ⇒ Object
Returns the value of attribute options.
10
11
12
|
# File 'lib/fdoc/presenters/html_presenter.rb', line 10
def options
@options
end
|
Instance Method Details
#css_path ⇒ Object
47
48
49
|
# File 'lib/fdoc/presenters/html_presenter.rb', line 47
def css_path
File.join(html_directory, "styles.css")
end
|
#html_directory ⇒ Object
43
44
45
|
# File 'lib/fdoc/presenters/html_presenter.rb', line 43
def html_directory
options[:url_base_path] || options[:html_directory] || ""
end
|
#index_path(subdirectory = "") ⇒ Object
51
52
53
54
55
56
57
58
|
# File 'lib/fdoc/presenters/html_presenter.rb', line 51
def index_path(subdirectory = "")
html_path = File.join(html_directory, subdirectory)
if options[:static_html]
File.join(html_path, 'index.html')
else
html_path
end
end
|
#render_erb(erb_name) ⇒ Object
16
17
18
19
20
|
# File 'lib/fdoc/presenters/html_presenter.rb', line 16
def render_erb(erb_name)
template_path = File.join(File.dirname(__FILE__), "../templates", erb_name)
template = ERB.new(File.read(template_path))
template.result(binding)
end
|
#render_json(json) ⇒ Object
30
31
32
33
34
35
36
37
38
39
40
41
|
# File 'lib/fdoc/presenters/html_presenter.rb', line 30
def render_json(json)
if json.kind_of? String
'<tt>"%s"</tt>' % json.gsub(/\"/, 'quot;')
elsif json.kind_of?(Numeric) ||
json.kind_of?(TrueClass) ||
json.kind_of?(FalseClass)
'<tt>%s</tt>' % json
elsif json.kind_of?(Hash) ||
json.kind_of?(Array)
'<pre><code>%s</code></pre>' % JSON.pretty_generate(json)
end
end
|
#render_markdown(markdown_str) ⇒ Object
22
23
24
25
26
27
28
|
# File 'lib/fdoc/presenters/html_presenter.rb', line 22
def render_markdown(markdown_str)
if markdown_str
Kramdown::Document.new(markdown_str, :entity_output => :numeric).to_html
else
nil
end
end
|
#tag_with_anchor(tag, content, anchor_slug = nil) ⇒ Object
60
61
62
63
64
65
66
67
68
69
|
# File 'lib/fdoc/presenters/html_presenter.rb', line 60
def tag_with_anchor(tag, content, anchor_slug = nil)
anchor_slug ||= content.downcase.gsub(' ', '_')
<<-EOS
<#{tag} id="#{anchor_slug}">
<a href="##{anchor_slug}" class="anchor">
#{content}
</a>
</#{tag}>
EOS
end
|