module CollectiveIdea::Acts::NestedSet::Helper

def nested_set_options(class_or_item, mover = nil)


}) %>
"#{'–' * i.level} #{i.name}"
<%= f.select :parent_id, nested_set_options(Category, @category) {|i|

== Usage

* +&block+ - a block that will be used to display: { |item| ... item.name }
* +mover+ - The item that is being move, used to exclude impossible moves
* +class_or_item+ - Class name or top level times
== Params

You can pass a block receiving an item and returning the string displayed in the select.
You can exclude some items from the tree.
Returns options for select.
def nested_set_options(class_or_item, mover = nil)
  if class_or_item.is_a? Array
    items = class_or_item.reject { |e| !e.root? }
  else
    class_or_item = class_or_item.roots if class_or_item.respond_to?(:scope)
    items = Array(class_or_item)
  end
  result = []
  items.each do |root|
    result += root.class.associate_parents(root.self_and_descendants).map do |i|
      if mover.nil? || mover.new_record? || mover.move_possible?(i)
        [yield(i), i.primary_id]
      end
    end.compact
  end
  result
end