Class: AwesomeNestedSetRenderer

Inherits:
ResourceRenderer::AttributeRenderer::Base show all
Defined in:
app/attribute_renderers/awesome_nested_set_renderer.rb

Instance Attribute Summary

Attributes inherited from ResourceRenderer::AttributeRenderer::Base

#helper, #model

Instance Method Summary collapse

Methods inherited from ResourceRenderer::AttributeRenderer::Base

#initialize

Constructor Details

This class inherits a constructor from ResourceRenderer::AttributeRenderer::Base

Instance Method Details

#display(attribute_name, label, options = {}, &block) ⇒ Object



2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
# File 'app/attribute_renderers/awesome_nested_set_renderer.rb', line 2

def display(attribute_name, label, options = {}, &block)
  options.reverse_merge!(scope: nil)

  scope = options.delete(:scope)

  # scope = "#{scope}_id".intern if scope.is_a?(Symbol) && scope.to_s !~ /_id$/

  data_attributes = {
    'awesome-nested-set-item':                true,
    'awesome-nested-set-item-uid':            model.to_param,
    'awesome-nested-set-item-on-drop-target': h.url_for([:reposition, model])
  }
  # data_attributes['awesome-nested-set-item-scope'] = "#{scope}-#{model.send(scope)}" if scope.present?
  data_attributes['awesome-nested-set-item-scope'] = scope.call(model) if scope.present?


  h.(:span, data: data_attributes, class: 'btn btn-xs btn-default awesome-nested-set-item') do
    h.tag(:span, class: 'glyphicon glyphicon-sort')
  end
end