Class: Minidown::ListElement

Inherits:
Element
  • Object
show all
Defined in:
lib/minidown/elements/list_element.rb

Constant Summary collapse

CheckedBox =
'<input type="checkbox" class="task-list-item-checkbox" checked="" disabled="">'.freeze
UnCheckedBox =
'<input type="checkbox" class="task-list-item-checkbox" disabled="">'.freeze

Instance Attribute Summary collapse

Attributes inherited from Element

#children, #content, #doc, #nodes

Instance Method Summary collapse

Methods inherited from Element

#blank?, #parse, #raw_content, #raw_content=, #unparsed_lines

Methods included from HtmlHelper

#br_tag, #build_tag

Constructor Details

#initialize(*_) ⇒ ListElement

Returns a new instance of ListElement.



7
8
9
10
11
12
13
# File 'lib/minidown/elements/list_element.rb', line 7

def initialize *_
  super
  @p_tag_content = false
  @contents = [TextElement.new(doc, content)]
  @task_list = false
  @checked = false
end

Instance Attribute Details

#checkedObject

Returns the value of attribute checked.



3
4
5
# File 'lib/minidown/elements/list_element.rb', line 3

def checked
  @checked
end

#contentsObject

Returns the value of attribute contents.



3
4
5
# File 'lib/minidown/elements/list_element.rb', line 3

def contents
  @contents
end

#p_tag_contentObject

Returns the value of attribute p_tag_content.



3
4
5
# File 'lib/minidown/elements/list_element.rb', line 3

def p_tag_content
  @p_tag_content
end

#task_listObject

Returns the value of attribute task_list.



3
4
5
# File 'lib/minidown/elements/list_element.rb', line 3

def task_list
  @task_list
end

Instance Method Details

#list_contentObject



28
29
30
31
32
33
34
# File 'lib/minidown/elements/list_element.rb', line 28

def list_content
  content = @contents.map(&:to_html).join(@p_tag_content ? br_tag : "\n".freeze)
  if @task_list
    content = (@checked ? CheckedBox : UnCheckedBox) + content
  end
  content
end

#to_htmlObject



15
16
17
18
19
20
21
22
23
24
25
26
# File 'lib/minidown/elements/list_element.rb', line 15

def to_html
  @contents.map! do |content|
    ParagraphElement === content ? content.text : content
  end if @p_tag_content
  content = list_content
  content = build_tag('p'.freeze){|p| p << content} if @p_tag_content
  attr = nil
  attr = {class: 'task-list-item'.freeze} if @task_list
  build_tag 'li'.freeze, attr do |li|
    li << content
  end
end