Method: BootstrapBaseHelper::List#to_s

Defined in:
app/helpers/bootstrap_base_helper.rb

#to_sObject



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 = options.delete(:type) || 'unordered'
  tag = (type == 'ordered') ? 'ol' : 'ul'
  unstyled_class = (type == 'unstyled') ? 'unstyled ' : ''

  template.(tag, nil, template.merge_predef_class(unstyled_class, options)) do
    ul_content = ''

    collection.each do |obj|
      if obj.is_a?(Hash)
        if obj.has_key?(:options) && obj.has_key?(:content)
          ul_content << template.('li', nil, obj[:options].reverse_merge!(li_options)) do
            obj[:content].html_safe
          end
        else
          nested_collection = obj.to_a.first
          ul_content << template.('li', nil, li_options) do
            (nested_collection.first + template.list(*nested_collection.last, options)).html_safe
          end
        end
      elsif obj.is_a?(Array)
        ul_content << template.list(*obj, options)
      else
        ul_content << template.('li', nil, li_options) do
          obj.html_safe
        end
      end
    end

    ul_content.html_safe
  end
end