Class: Docter::ToCEntry
Overview
Table of contents entry.
Direct Known Subclasses
Constant Summary
Constants inherited from ToC
Instance Attribute Summary collapse
-
#title ⇒ Object
readonly
The title of this entry.
-
#url ⇒ Object
readonly
The URL for this entry.
Attributes inherited from ToC
Instance Method Summary collapse
-
#initialize(url, title) ⇒ ToCEntry
constructor
:call-seq: new(url, title).
-
#to_html(*args) ⇒ Object
:call-seq: to_html(nested?) => html.
Methods inherited from ToC
Constructor Details
#initialize(url, title) ⇒ ToCEntry
:call-seq:
new(url, title)
URL links to the ToC entry, and must be a valid URL (use CGI.escape is necessary). The title must be HTML-encoded (use CGI.escapeHTML if necessary).
281 282 283 284 |
# File 'lib/docter/common.rb', line 281 def initialize(url, title) super() @url, @title = url, title end |
Instance Attribute Details
#title ⇒ Object (readonly)
The title of this entry.
274 275 276 |
# File 'lib/docter/common.rb', line 274 def title @title end |
#url ⇒ Object (readonly)
The URL for this entry.
271 272 273 |
# File 'lib/docter/common.rb', line 271 def url @url end |
Instance Method Details
#to_html(*args) ⇒ Object
:call-seq:
to_html(nested?) => html
Transforms this ToC entry into an HTML list item (LI). Depending on the nested argument, can also expand nested ToC.
291 292 293 294 295 296 297 298 299 |
# File 'lib/docter/common.rb', line 291 def to_html(*args) = Hash === args.last ? args.pop.clone : {} args.each { |arg| [arg.to_sym] = true } if [:nested] && !empty? nested = [:nested].respond_to?(:to_i) && [:nested].to_i > 0 ? super(.merge(:nested=>[:nested] - 1)) : super() end %{<li><a href="#{url}">#{title}</a>#{nested}</li>} end |