Class: Docter::ToCEntry
Overview
Table of contents entry.
Direct Known Subclasses
Constant Summary
Constants inherited from ToC
Instance Attribute Summary collapse
-
#url ⇒ Object
readonly
The URL for this entry.
Attributes inherited from ToC
Instance Method Summary collapse
-
#initialize(title, url = nil) ⇒ ToCEntry
constructor
:call-seq: new(title, url).
-
#to_html(*args) ⇒ Object
:call-seq: to_html(nested?) => html.
Methods inherited from ToC
Constructor Details
#initialize(title, url = nil) ⇒ ToCEntry
:call-seq:
new(title, url)
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).
317 318 319 320 |
# File 'lib/docter/common.rb', line 317 def initialize(title, url = nil) super title @url = url end |
Instance Attribute Details
#url ⇒ Object (readonly)
The URL for this entry.
310 311 312 |
# File 'lib/docter/common.rb', line 310 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.
327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 |
# File 'lib/docter/common.rb', line 327 def to_html(*args) = Hash === args.last ? args.pop.clone : {} args.each { |arg| [arg.to_sym] = true } if [:nested] && !empty? if Integer === [:nested] nested = super(.merge(:nested=>[:nested] - 1)) if [:nested] > 0 else nested = super() end end if url %{<li><a href="#{url}">#{title}</a>#{nested}</li>} else %{<li>#{title}#{nested}</li>} end end |