Class: Docter::ToCEntry

Inherits:
ToC
  • Object
show all
Defined in:
lib/docter/common.rb

Overview

Table of contents entry.

Direct Known Subclasses

Page::ToCEntryForPage

Constant Summary

Constants inherited from ToC

Docter::ToC::ARRAY_METHODS

Instance Attribute Summary collapse

Attributes inherited from ToC

#entries, #title

Instance Method Summary collapse

Methods inherited from ToC

#add, from_yaml

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

#urlObject (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)
  options = Hash === args.last ? args.pop.clone : {}
  args.each { |arg| options[arg.to_sym] = true }
  if options[:nested] && !empty?
    if Integer === options[:nested]
      nested = super(options.merge(:nested=>options[:nested] - 1)) if options[:nested] > 0
    else
      nested = super(options)
    end
  end
  if url
    %{<li><a href="#{url}">#{title}</a>#{nested}</li>}
  else
    %{<li>#{title}#{nested}</li>}
  end
end