Class: Minidown::ListElement
- 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
-
#checked ⇒ Object
Returns the value of attribute checked.
-
#contents ⇒ Object
Returns the value of attribute contents.
-
#p_tag_content ⇒ Object
Returns the value of attribute p_tag_content.
-
#task_list ⇒ Object
Returns the value of attribute task_list.
Attributes inherited from Element
#children, #content, #doc, #nodes
Instance Method Summary collapse
-
#initialize(*_) ⇒ ListElement
constructor
A new instance of ListElement.
- #list_content ⇒ Object
- #to_html ⇒ Object
Methods inherited from Element
#blank?, #parse, #raw_content, #raw_content=, #unparsed_lines
Methods included from HtmlHelper
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
#checked ⇒ Object
Returns the value of attribute checked.
3 4 5 |
# File 'lib/minidown/elements/list_element.rb', line 3 def checked @checked end |
#contents ⇒ Object
Returns the value of attribute contents.
3 4 5 |
# File 'lib/minidown/elements/list_element.rb', line 3 def contents @contents end |
#p_tag_content ⇒ Object
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_list ⇒ Object
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_content ⇒ Object
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_html ⇒ Object
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 |