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

Instance Method Summary collapse

Methods inherited from ToC

#add

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

#titleObject (readonly)

The title of this entry.



274
275
276
# File 'lib/docter/common.rb', line 274

def title
  @title
end

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