Class: Bootstrap::TypographyHelper::List
- Inherits:
-
Object
- Object
- Bootstrap::TypographyHelper::List
- Defined in:
- app/helpers/bootstrap/typography_helper.rb
Overview
Internal: List class that represents a ul, li list with Bootstrap styles.
template - ActionView::Template instance. li_options - Default options of all li tags. ( default: {} ) type - Type of the list, can be unordered, ordered or unstyled.
( default: 'unordered' )
options - Options can be accepted by ol or ul.
Instance Attribute Summary collapse
-
#collection ⇒ Object
readonly
Returns the value of attribute collection.
-
#li_options ⇒ Object
readonly
Returns the value of attribute li_options.
-
#options ⇒ Object
readonly
Returns the value of attribute options.
-
#template ⇒ Object
readonly
Returns the value of attribute template.
-
#type ⇒ Object
readonly
Returns the value of attribute type.
Instance Method Summary collapse
- #add(content_or_options = nil, options = {}) ⇒ Object (also: #<<)
-
#initialize(templte, li_options: {}, type: 'unordered', **options) ⇒ List
constructor
A new instance of List.
- #to_s ⇒ Object
Constructor Details
#initialize(templte, li_options: {}, type: 'unordered', **options) ⇒ List
Returns a new instance of List.
15 16 17 18 19 20 21 |
# File 'app/helpers/bootstrap/typography_helper.rb', line 15 def initialize(templte, li_options: {}, type: 'unordered', **) @template = templte @type = type @options = @li_options = @collection = [] end |
Instance Attribute Details
#collection ⇒ Object (readonly)
Returns the value of attribute collection.
13 14 15 |
# File 'app/helpers/bootstrap/typography_helper.rb', line 13 def collection @collection end |
#li_options ⇒ Object (readonly)
Returns the value of attribute li_options.
13 14 15 |
# File 'app/helpers/bootstrap/typography_helper.rb', line 13 def @li_options end |
#options ⇒ Object (readonly)
Returns the value of attribute options.
13 14 15 |
# File 'app/helpers/bootstrap/typography_helper.rb', line 13 def @options end |
#template ⇒ Object (readonly)
Returns the value of attribute template.
13 14 15 |
# File 'app/helpers/bootstrap/typography_helper.rb', line 13 def template @template end |
#type ⇒ Object (readonly)
Returns the value of attribute type.
13 14 15 |
# File 'app/helpers/bootstrap/typography_helper.rb', line 13 def type @type end |
Instance Method Details
#add(content_or_options = nil, options = {}) ⇒ Object Also known as: <<
23 24 25 26 27 |
# File 'app/helpers/bootstrap/typography_helper.rb', line 23 def add( = nil, = {}) , = '', if .is_a?(Hash) collection << {options: , content: } end |
#to_s ⇒ Object
31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 |
# File 'app/helpers/bootstrap/typography_helper.rb', line 31 def to_s tag = (type == 'ordered') ? 'ol' : 'ul' unstyled_class = (type == 'unstyled') ? 'unstyled ' : '' template.content_tag(tag, nil, template.merge_predef_class(unstyled_class, )) do tag_content = '' collection.each do |obj| tag_content << template.content_tag('li', nil, obj[:options].reverse_merge()) do obj[:content].html_safe end end tag_content.html_safe end end |