Module: Shoppe::ProductCategoryHelper

Defined in:
app/helpers/shoppe/product_category_helper.rb

Instance Method Summary collapse

Instance Method Details

#nested_product_category_rows(category, current_category = nil, link_to_current = true, relative_depth = 0) ⇒ Object


10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
# File 'app/helpers/shoppe/product_category_helper.rb', line 10

def nested_product_category_rows(category, current_category = nil, link_to_current = true, relative_depth = 0)
  if category.present? && category.children.count > 0
    String.new.tap do |s|
      category.children.ordered.each do |child|
        s << "<tr>"
        s << "<td>"
        if child == current_category
          if link_to_current == false
            s << "#{nested_product_category_spacing_adjusted_for_depth child, relative_depth} &#8627; #{child.name} (#{t('shoppe.product_category.nesting.current_category')})"
          else
            s << "#{nested_product_category_spacing_adjusted_for_depth child, relative_depth} &#8627; #{link_to(child.name, [:edit, child]).html_safe} (#{t('shoppe.product_category.nesting.current_category')})"
          end
        else
          s << "#{nested_product_category_spacing_adjusted_for_depth child, relative_depth} &#8627; #{link_to(child.name, [:edit, child]).html_safe}"
        end
        s << "</td>"
        s << "</tr>"
        s << nested_product_category_rows(child, current_category, link_to_current, relative_depth)
      end
    end.html_safe
  else
    ""
  end
end

#nested_product_category_spacing_adjusted_for_depth(category, relative_depth) ⇒ Object


4
5
6
7
8
# File 'app/helpers/shoppe/product_category_helper.rb', line 4

def nested_product_category_spacing_adjusted_for_depth(category, relative_depth)
  depth = category.depth - relative_depth
  spacing = depth < 2 ? 0.8 : 1.5
  ("<span style='display:inline-block;width:#{spacing}em;'></span>"*category.depth).html_safe
end