Class: Repubmark::Elems::List
- Inherits:
-
Base
- Object
- Base
- Repubmark::Elems::List
show all
- Defined in:
- lib/repubmark/elems/list.rb
Instance Attribute Summary
Attributes inherited from Base
#parent
Instance Method Summary
collapse
Methods inherited from Base
#absolute_url, #config, #count_words, #html_class, #own_url, parent?, parents, #relative_url
Constructor Details
#initialize(parent, links:, ordered:) ⇒ List
Returns a new instance of List.
8
9
10
11
12
13
14
15
|
# File 'lib/repubmark/elems/list.rb', line 8
def initialize(parent, links:, ordered:)
super parent
@links = !!links
@ordered = !!ordered
@items = []
end
|
Instance Method Details
#item ⇒ Object
53
|
# File 'lib/repubmark/elems/list.rb', line 53
def item(...) = @links ? item_links(...) : item_nolinks(...)
|
#item_links(ref_url, ref_title = nil) {|list_item| ... } ⇒ Object
75
76
77
78
79
80
81
|
# File 'lib/repubmark/elems/list.rb', line 75
def item_links(ref_url, ref_title = nil)
titled_ref = TitledRef.new ref_url, ref_title
list_item = ListItem.new self, @items.count, titled_ref
@items << list_item
yield list_item if block_given?
nil
end
|
#item_nolinks {|list_item| ... } ⇒ Object
68
69
70
71
72
73
|
# File 'lib/repubmark/elems/list.rb', line 68
def item_nolinks
list_item = ListItem.new self, @items.count
@items << list_item
yield list_item
nil
end
|
#items_count ⇒ Object
41
|
# File 'lib/repubmark/elems/list.rb', line 41
def items_count = @items.count
|
#level ⇒ Object
39
|
# File 'lib/repubmark/elems/list.rb', line 39
def level = parent.instance_of?(ListItem) ? parent.level + 1 : 0
|
#parent=(parent) ⇒ Object
57
58
59
60
61
62
63
64
|
# File 'lib/repubmark/elems/list.rb', line 57
def parent=(parent)
unless parent.instance_of?(Canvas) || parent.instance_of?(ListItem)
raise TypeError,
"Expected #{Canvas} or #{ListItem}, got #{parent.class}"
end
@parent = parent
end
|
#tag_name ⇒ Object
66
|
# File 'lib/repubmark/elems/list.rb', line 66
def tag_name = @ordered ? 'ol' : 'ul'
|
#to_gemtext ⇒ Object
33
|
# File 'lib/repubmark/elems/list.rb', line 33
def to_gemtext = @items.map(&:to_gemtext).join.freeze
|
#to_html ⇒ Object
25
26
27
28
29
30
31
|
# File 'lib/repubmark/elems/list.rb', line 25
def to_html
[
"<#{tag_name}>\n",
*@items.map(&:to_html),
"</#{tag_name}>\n",
].join.freeze
end
|
#to_summary_plain ⇒ Object
23
|
# File 'lib/repubmark/elems/list.rb', line 23
def to_summary_plain = @items.map(&:to_summary_plain).join(' ').freeze
|
#unicode_decor ⇒ Object
43
44
45
46
47
|
# File 'lib/repubmark/elems/list.rb', line 43
def unicode_decor
return if level <= 1
"#{parent.unicode_decor_parent}#{parent.last? ? '⠀ ' : '│ '}"
end
|
#word_count ⇒ Object
21
|
# File 'lib/repubmark/elems/list.rb', line 21
def word_count = @items.sum(&:word_count)
|