Module YuiTree
In: vendor/plugins/yui_tree/lib/yui_tree.rb
(C):Hipposoft 2009
Purpose:A Rails interface to the Yahoo Interface Library tree component, for YUI version 2.7.0.

          06-Apr-2009 (ADH): Created.


Classes and Modules

Module YuiTree::ClassMethods
Module YuiTree::YuiTreeHelper



Public Class methods

Simple helper method which builds an object suitable for rendering as JSON and sending to the YUI tree as node data. Pass an object ID, name to show in the tree and ‘true’ if this is a leaf, else ‘false’. Returns an appropriate Ruby object upon which “to_json“ may be called. Call using code such as “YuiTree::make_node_object(…)”.

The text given in the second parameter is made HTML-safe with “h(…)”. The output must be made JS-safe somehow, e.g. by “render :js => ” for one returned object or an array of them in controller handling XHR requests in a “format.js do …” block or by the necessity of turning the objects into a JS equivalent by calling “to_json“, which handles escaping for you.

An optional fourth parameter can be given - this is used as an extra class name on the node text. You can specialise individual node appearance with this and CSS, but only if you make custom nodes externally. If you use the default internal code for acts-as-tree-like data sets, no special class name will be applied to any nodes.


     # File vendor/plugins/yui_tree/lib/yui_tree.rb, line 382
382:   def self.make_node_object( id, name, isLeaf, className = nil )
383:     {
384:       :id        => id.to_s,
385:       :label     => ERB::Util.h( name.to_s ),
386:       :isLeaf    => !! isLeaf,
387:       :className => className
388:     }
389:   end