Class: Bootstrap::TypographyHelper::List

Inherits:
Object
  • Object
show all
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

Instance Method Summary collapse

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', **options)
  @template = templte
  @type = type
  @options = options
  @li_options = li_options
  @collection = []
end

Instance Attribute Details

#collectionObject (readonly)

Returns the value of attribute collection.



13
14
15
# File 'app/helpers/bootstrap/typography_helper.rb', line 13

def collection
  @collection
end

#li_optionsObject (readonly)

Returns the value of attribute li_options.



13
14
15
# File 'app/helpers/bootstrap/typography_helper.rb', line 13

def li_options
  @li_options
end

#optionsObject (readonly)

Returns the value of attribute options.



13
14
15
# File 'app/helpers/bootstrap/typography_helper.rb', line 13

def options
  @options
end

#templateObject (readonly)

Returns the value of attribute template.



13
14
15
# File 'app/helpers/bootstrap/typography_helper.rb', line 13

def template
  @template
end

#typeObject (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(content_or_options = nil, options = {})
  content_or_options, options = '', content_or_options if content_or_options.is_a?(Hash)

  collection << {options: options, content: content_or_options}
end

#to_sObject



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.(tag, nil, template.merge_predef_class(unstyled_class, options)) do
    tag_content = ''

    collection.each do |obj|
      tag_content << template.('li', nil, obj[:options].reverse_merge(li_options)) do
        obj[:content].html_safe
      end
    end

    tag_content.html_safe
  end
end