Class: Caracal::Core::Models::ListItemModel
- Inherits:
-
ParagraphModel
- Object
- BaseModel
- ParagraphModel
- Caracal::Core::Models::ListItemModel
- Defined in:
- lib/caracal/core/models/list_item_model.rb
Overview
This class encapsulates the logic needed to store and manipulate list item data.
Instance Attribute Summary collapse
-
#list_item_level ⇒ Object
readonly
Returns the value of attribute list_item_level.
-
#list_item_type ⇒ Object
readonly
readers (create aliases for superclass methods to conform to expected naming convention.).
-
#nested_list ⇒ Object
accessors.
Attributes inherited from ParagraphModel
#paragraph_align, #paragraph_bgcolor, #paragraph_bold, #paragraph_color, #paragraph_italic, #paragraph_size, #paragraph_style, #paragraph_underline
Instance Method Summary collapse
-
#ol(options = {}, &block) ⇒ Object
.ol.
-
#ul(options = {}, &block) ⇒ Object
.ul.
-
#valid? ⇒ Boolean
VALIDATION ===========================.
Methods inherited from ParagraphModel
#bookmark_end, #bookmark_start, #br, #initialize, #link, #page, #run_attributes, #runs, #text
Methods inherited from BaseModel
Constructor Details
This class inherits a constructor from Caracal::Core::Models::ParagraphModel
Instance Attribute Details
#list_item_level ⇒ Object (readonly)
Returns the value of attribute list_item_level.
25 26 27 |
# File 'lib/caracal/core/models/list_item_model.rb', line 25 def list_item_level @list_item_level end |
#list_item_type ⇒ Object (readonly)
readers (create aliases for superclass methods to conform to expected naming convention.)
24 25 26 |
# File 'lib/caracal/core/models/list_item_model.rb', line 24 def list_item_type @list_item_type end |
#nested_list ⇒ Object
accessors
20 21 22 |
# File 'lib/caracal/core/models/list_item_model.rb', line 20 def nested_list @nested_list end |
Instance Method Details
#ol(options = {}, &block) ⇒ Object
.ol
60 61 62 63 64 65 66 67 68 69 70 |
# File 'lib/caracal/core/models/list_item_model.rb', line 60 def ol(={}, &block) .merge!({ type: :ordered, level: list_item_level + 1 }) model = Caracal::Core::Models::ListModel.new(, &block) if model.valid? @nested_list = model else raise Caracal::Errors::InvalidModelError, 'Ordered lists require at least one list item.' end model end |
#ul(options = {}, &block) ⇒ Object
.ul
73 74 75 76 77 78 79 80 81 82 83 |
# File 'lib/caracal/core/models/list_item_model.rb', line 73 def ul(={}, &block) .merge!({ type: :unordered, level: list_item_level + 1 }) model = Caracal::Core::Models::ListModel.new(, &block) if model.valid? @nested_list = model else raise Caracal::Errors::InvalidModelError, 'Unordered lists require at least one list item.' end model end |
#valid? ⇒ Boolean
VALIDATION ===========================
88 89 90 91 92 |
# File 'lib/caracal/core/models/list_item_model.rb', line 88 def valid? a = [:type, :level] required = a.map { |m| send("list_item_#{ m }") }.compact.size == a.size required && !runs.empty? end |