Sha256: e99194dfbdb31ac524f209cffd2e8721d345734306668fe23bd023b5ee77dabf

Contents?: true

Size: 1.21 KB

Versions: 1

Compression:

Stored size: 1.21 KB

Contents

require 'awesome_nested_set/helper'
include CollectiveIdea::Acts::NestedSet::Helper

module SortableNestedSetHelper
  def sortable_nested_set_tree(class_or_category)
    if class_or_category.is_a?(Class)
      @category_class = class_or_category
      @categories = class_or_category.all(:include => class_or_category.sns_items_type, :order => :lft)
    else
      @category_class = class_or_category.class
      @categories = class_or_category.self_and_descendants_with_items
      @root = class_or_category
    end

    @sortable_ids = @categories.collect(&:id)

    render 'sortable_nested_set/tree',
           :category_class => @category_class,
           :categories => @categories,
           :sortable_ids => @sortable_ids,
           :root => @root
  end

  def sns_lineage(category, options=Hash.new)
    content_tag :p, category.lineage(options).collect { |a| link_to(a.name, a) }
                                             .join(image_tag('folder_closed.png', :class => :descent)).html_safe
  end

  def sns_options(class_or_category, mover=nil)
    nested_set_options(class_or_category, mover) { |category| "#{'.' * category.level} #{category.name}" }
  end
end

ActionView::Base.send :include, SortableNestedSetHelper

Version data entries

1 entries across 1 versions & 1 rubygems

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