Module: Para::TagHelper

Included in:
Admin::CrudResourcesController
Defined in:
app/helpers/para/tag_helper.rb

Instance Method Summary collapse

Instance Method Details

#add_button_for(component, relation, model) ⇒ Object



54
55
56
57
58
59
60
61
62
63
64
65
66
# File 'app/helpers/para/tag_helper.rb', line 54

def add_button_for(component, relation, model)
  return unless can?(:create, model)

  partial_name = if component.subclassable?
    :subclassable_add_button
  else
    :add_button
  end

  render partial: find_partial_for(relation, partial_name), locals: {
    component: component, model: model
  }
end


3
4
5
6
7
8
9
10
11
12
13
14
15
# File 'app/helpers/para/tag_helper.rb', line 3

def icon_link_to(name, url_options = nil, options = nil, &block)
  if block
    options, url_options = url_options, name
    name = capture { block.call }
  end

  if (icon = options.delete(:icon))
    icon_tag = (:i, '', class: "fa fa-#{ icon }")
    name = [icon_tag, name].join(' ').html_safe
  end

  link_to(name, url_options, options)
end

#listing_for(resources, options = {}) ⇒ Object



17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
# File 'app/helpers/para/tag_helper.rb', line 17

def listing_for(resources, options = {})
  model = resources.model
  attributes = model_field_mappings(model).fields
  relation = options.fetch(:relation, model.name.to_s.underscore.pluralize)
  allow_adding_resource = options.fetch(:addable, true)
  force_list = options.fetch(:force_list, false)

  partial = if !force_list && model.respond_to?(:roots) && can?(:tree, model)
    :tree
  else
    :list
  end

  render(
    partial: find_partial_for(relation, partial),
    locals: {
      component: @component,
      resources: resources,
      relation: relation,
      model: model,
      attributes: attributes,
      allow_adding_resource: allow_adding_resource
    }
  )
end

#table_for(options) ⇒ Object



43
44
45
46
47
48
49
50
51
52
# File 'app/helpers/para/tag_helper.rb', line 43

def table_for(options)
  partial = :table
  render(
    partial: find_partial_for(
      options[:model].name.underscore.pluralize,
      partial
    ),
    locals: options
  )
end