Module: RenderExpandableTreeHelper::Render

Defined in:
app/helpers/render_expandable_tree_helper.rb

Class Attribute Summary collapse

Class Method Summary collapse

Class Attribute Details

.hObject

Returns the value of attribute h.



12
13
14
# File 'app/helpers/render_expandable_tree_helper.rb', line 12

def h
  @h
end

.optionsObject

Returns the value of attribute options.



12
13
14
# File 'app/helpers/render_expandable_tree_helper.rb', line 12

def options
  @options
end

Class Method Details

.childrenObject



54
55
56
57
58
# File 'app/helpers/render_expandable_tree_helper.rb', line 54

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

.controlsObject



40
41
42
43
44
45
46
47
48
49
50
51
52
# File 'app/helpers/render_expandable_tree_helper.rb', line 40

def controls
  node = options[:node]

  edit_path = h.url_for(:controller => options[:klass].pluralize, :action => :edit, :id => node)
  show_path = h.url_for(:controller => options[:klass].pluralize, :action => :show, :id => node)

  "
    <div class='controls'>
      #{ h.link_to '', edit_path, :class => :edit }
      #{ h.link_to '', show_path, :class => :delete, :method => :delete, :data => { :confirm => 'Are you sure?' } }
    </div>
  "
end

.render_node(h, options) ⇒ Object



14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
# File 'app/helpers/render_expandable_tree_helper.rb', line 14

def render_node(h, options)
  @h, @options = h, options
  node = options[:node]

  "
    <li data-node-id='#{ node.id }'>
      <div class='item'>
        <i class='handle'></i>
        <b class='expand plus'>+</b>
        #{ show_link }
        #{ controls }
      </div>
      #{ children }
    </li>
  "
end


31
32
33
34
35
36
37
38
# File 'app/helpers/render_expandable_tree_helper.rb', line 31

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

  "<h4>#{ h.link_to(node.send(title_field), url) }</h4>"
end