Class: BootstrapBaseHelper::List
- Inherits:
-
Object
- Object
- BootstrapBaseHelper::List
- Defined in:
- app/helpers/bootstrap_base_helper.rb
Instance Attribute Summary collapse
-
#block ⇒ Object
Returns the value of attribute block.
-
#collection ⇒ Object
Returns the value of attribute collection.
-
#li_options ⇒ Object
Returns the value of attribute li_options.
-
#options ⇒ Object
Returns the value of attribute options.
-
#template ⇒ Object
Returns the value of attribute template.
Instance Method Summary collapse
- #add(*args) ⇒ Object (also: #<<)
-
#initialize(templte, *args) ⇒ List
constructor
A new instance of List.
- #to_s ⇒ Object
Constructor Details
#initialize(templte, *args) ⇒ List
Returns a new instance of List.
10 11 12 13 14 15 |
# File 'app/helpers/bootstrap_base_helper.rb', line 10 def initialize(templte, *args) self.template = templte self. = args..dup self. = .delete(:li_options) || {} self.collection = args end |
Instance Attribute Details
#block ⇒ Object
Returns the value of attribute block.
8 9 10 |
# File 'app/helpers/bootstrap_base_helper.rb', line 8 def block @block end |
#collection ⇒ Object
Returns the value of attribute collection.
8 9 10 |
# File 'app/helpers/bootstrap_base_helper.rb', line 8 def collection @collection end |
#li_options ⇒ Object
Returns the value of attribute li_options.
8 9 10 |
# File 'app/helpers/bootstrap_base_helper.rb', line 8 def @li_options end |
#options ⇒ Object
Returns the value of attribute options.
8 9 10 |
# File 'app/helpers/bootstrap_base_helper.rb', line 8 def @options end |
#template ⇒ Object
Returns the value of attribute template.
8 9 10 |
# File 'app/helpers/bootstrap_base_helper.rb', line 8 def template @template end |
Instance Method Details
#add(*args) ⇒ Object Also known as: <<
17 18 19 20 |
# File 'app/helpers/bootstrap_base_helper.rb', line 17 def add(*args) li_opts = args. collection << {options: li_opts, content: args.join} end |
#to_s ⇒ Object
24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 |
# File 'app/helpers/bootstrap_base_helper.rb', line 24 def to_s type = .delete(:type) || 'unordered' tag = (type == 'ordered') ? 'ol' : 'ul' unstyled_class = (type == 'unstyled') ? 'unstyled ' : '' template.content_tag(tag, nil, template.merge_predef_class(unstyled_class, )) do ul_content = '' collection.each do |obj| if obj.is_a?(Hash) if obj.has_key?(:options) && obj.has_key?(:content) ul_content << template.content_tag('li', nil, obj[:options].reverse_merge!()) do obj[:content].html_safe end else nested_collection = obj.to_a.first ul_content << template.content_tag('li', nil, ) do (nested_collection.first + template.list(*nested_collection.last, )).html_safe end end elsif obj.is_a?(Array) ul_content << template.list(*obj, ) else ul_content << template.content_tag('li', nil, ) do obj.html_safe end end end ul_content.html_safe end end |