Sha256: 9d9a1f598319ac908166fd94667668837c12f4668c1d4ed52f43c3d0c0ae9724

Contents?: true

Size: 1.15 KB

Versions: 1

Compression:

Stored size: 1.15 KB

Contents

module SortableNestedSetHelper
  def sns_tree(class_or_category)
    if class_or_category.is_a?(Class)
      @category_class = class_or_category
      @categories = @category_class.includes(@category_class.sns_items_type)
    else
      @category_class = class_or_category.class
      @categories = class_or_category.self_and_descendants.includes(@category_class.sns_items_type)
    end

    render 'sortable_nested_set/tree', :category_class => @category_class, :categories => @categories.arrange
  end

  def sns_lineage(category, options={})
    content_for :head do
      stylesheet_link_tag 'sortable_nested_set'
    end

    ancestors = category.send(options[:include_self] ? :self_and_ancestors : :ancestors)

    links = ancestors.collect do |c|
      link_to c, c, :class => :lineage
    end

    content_tag :p, links.join.html_safe unless links.empty?
  end

  def sns_options(category_class, mover=nil)
    sorted_nested_set_options(category_class, lambda(&:left_column_name), mover) { |cat, lvl| "#{'.'*lvl}#{cat}" }.collect do |option|
      option.first.gsub! /^(\.*)/, ''
      option << {:style => "padding-left: #{0.5 + $1.length/2.0}em"}
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
sortable_nested_set-0.4.2 app/helpers/sortable_nested_set_helper.rb