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).
336 337 338 339 |
# File 'lib/docter/common.rb', line 336 def initialize(title, url = nil) super title @url = url end |
Instance Attribute Details
#url ⇒ Object (readonly)
The URL for this entry.
329 330 331 |
# File 'lib/docter/common.rb', line 329 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.
346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 |
# File 'lib/docter/common.rb', line 346 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 |