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).



336
337
338
339
# File 'lib/docter/common.rb', line 336

def initialize(title, url = nil)
  super title
  @url = url
end

Instance Attribute Details

#urlObject (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)
  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