Sha256: 0cdad482eb1c510422c2b0430dcfef8dcbf0837ce52903cac47da0a3131dae44

Contents?: true

Size: 1.13 KB

Versions: 2

Compression:

Stored size: 1.13 KB

Contents

# DOC:
# We use Helper Methods for tree building,
# because it's faster than View Templates and Partials

# SECURITY note
# Prepare your data on server side for rendering
# or use h.html_escape(node.content)
# for escape potentially dangerous content
module RenderSortableTreeHelper
  module Render 
    class << self
      attr_accessor :h, :options

      def render_node(h, options)
        @h, @options = h, options

        node = options[:node]

        "
          <li id='#{ node.id }_#{ options[:klass] }'>
            <div class='item #{"page-hidden" if node.hidden? }'>
              <i class='handle'></i>
              #{show_link}
            </div>
            #{children}
          </li>
        "
      end

      def show_link
        node = options[:node]
        ns   = options[:namespace]
        url  = h.url_for(ns + [node])
        title_field = options[:title]

        h.link_to(node.send(title_field), url)
      end

      def children
        unless options[:children].blank?
          "<ol class='nested_set'>#{ options[:children] }</ol>"
        end
      end

    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
brightcontent-pages-2.0.30 app/helpers/render_sortable_tree_helper.rb
brightcontent-pages-2.0.29 app/helpers/render_sortable_tree_helper.rb