Class: DaimonMarkdown::Plugin::TableOfContents::UnorderedList
- Inherits:
-
Object
- Object
- DaimonMarkdown::Plugin::TableOfContents::UnorderedList
- Defined in:
- lib/daimon_markdown/plugin/toc.rb
Instance Attribute Summary collapse
-
#items ⇒ Object
readonly
Returns the value of attribute items.
-
#level ⇒ Object
readonly
Returns the value of attribute level.
Instance Method Summary collapse
- #<<(item) ⇒ Object
-
#initialize(html_class: nil, level: 1) ⇒ UnorderedList
constructor
A new instance of UnorderedList.
- #to_html ⇒ Object
Constructor Details
#initialize(html_class: nil, level: 1) ⇒ UnorderedList
Returns a new instance of UnorderedList.
89 90 91 92 93 |
# File 'lib/daimon_markdown/plugin/toc.rb', line 89 def initialize(html_class: nil, level: 1) @html_class = html_class @level = level @items = [] end |
Instance Attribute Details
#items ⇒ Object (readonly)
Returns the value of attribute items.
87 88 89 |
# File 'lib/daimon_markdown/plugin/toc.rb', line 87 def items @items end |
#level ⇒ Object (readonly)
Returns the value of attribute level.
87 88 89 |
# File 'lib/daimon_markdown/plugin/toc.rb', line 87 def level @level end |
Instance Method Details
#<<(item) ⇒ Object
95 96 97 98 99 100 101 102 103 104 105 106 |
# File 'lib/daimon_markdown/plugin/toc.rb', line 95 def <<(item) case when item.is_a?(UnorderedList) && @items.last.is_a?(ListItem) @items.last << item when item.is_a?(UnorderedList) && @items.last.nil? li = ListItem.new li << item @items << li else @items << item end end |
#to_html ⇒ Object
108 109 110 111 112 113 114 |
# File 'lib/daimon_markdown/plugin/toc.rb', line 108 def to_html if @html_class %Q(<ul class="#{@html_class}">\n#{@items.map(&:to_html).join("\n")}\n</ul>) else %Q(<ul>\n#{@items.map(&:to_html).join("\n")}\n</ul>) end end |