Sha256: dc249543a5f294e07e88f3c8679ecc7b2cf0a321397e6ff03cec9c6d85a6363d

Contents?: true

Size: 1.19 KB

Versions: 1

Compression:

Stored size: 1.19 KB

Contents

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.for_indented_list_with_items.all
    else
      @category_class = class_or_category.class
      @categories = class_or_category.self_and_descendants.for_indented_list_with_items
    end

    render 'sortable_nested_set/tree', :categories => @categories, :category_class => @category_class
  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.select([:id, :name]).collect do |c|
      link_to(c.name, c, :class => :lineage)
    end

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

  def sns_options(category_class, mover=nil)
    options = []

    category_class.each_with_level(category_class.for_indented_list) do |category, level|
      if mover.nil? || mover.new_record? || mover.move_possible?(category)
        options << ['.' * level + category.name, category.id]
      end
    end

    options
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

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