Module: ActionAdmin::AdminHelper

Defined in:
app/helpers/action_admin/admin_helper.rb

Instance Method Summary collapse

Instance Method Details

#admin_action_title(action = nil) ⇒ Object



7
8
9
10
11
12
# File 'app/helpers/action_admin/admin_helper.rb', line 7

def admin_action_title(action=nil)
  if controller.respond_to? :action_header
    name = action || action_name
    controller.action_header.action_title(name, self)
  end
end

#admin_app_nameObject



3
4
5
# File 'app/helpers/action_admin/admin_helper.rb', line 3

def admin_app_name
  ActionAdmin.config.app_name
end

#admin_meta_tagsObject



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

def admin_meta_tags
  tags = {
    site:     admin_app_name,
    noindex:  true,
    nofollow: true,
    reverse:  true,
    title:    admin_action_title || "#{action_name}".titleize,
    charset:  'utf-8',
    viewport: 'width=device-width, initial-scale=1.0'
  }

  set_meta_tags tags
  display_meta_tags
end

#admin_present(record, presenter = nil) ⇒ Object



29
30
31
32
33
34
35
36
# File 'app/helpers/action_admin/admin_helper.rb', line 29

def admin_present(record, presenter=nil)
  record     = record.new if record.respond_to? :new
  class_name = record.class.name
  presenter  = presenter || "Admin::#{class_name}Presenter"
  presenter  = "#{presenter}".safe_constantize || 'ActionAdmin::Presenter'.constantize

  presenter.new(record, self)
end

#admin_present_many(records, presenter = nil) ⇒ Object



38
39
40
# File 'app/helpers/action_admin/admin_helper.rb', line 38

def admin_present_many(records, presenter=nil)
  records.to_a.map { |r| admin_present(r, presenter) }
end

#admin_render_shortcode(string) ⇒ Object



73
74
75
# File 'app/helpers/action_admin/admin_helper.rb', line 73

def admin_render_shortcode(string)
  method(ActionAdmin.config.shortcode_helper).call(string)
end

#admin_render_template(fallback) ⇒ Object



42
43
44
45
46
47
48
# File 'app/helpers/action_admin/admin_helper.rb', line 42

def admin_render_template(fallback)
  template = Hash(controller._action_templates[:"#{action_name}"])
  partial  = template.fetch :partial, fallback
  options  = template.except(:partial)

  render partial, options
end

#admin_search?Boolean

Returns:

  • (Boolean)


50
51
52
# File 'app/helpers/action_admin/admin_helper.rb', line 50

def admin_search?
  params[:search].present?
end

#admin_search_urlObject



61
62
63
# File 'app/helpers/action_admin/admin_helper.rb', line 61

def admin_search_url
  url_for merge_params({}, [:per_page, :filter, :sort], params.permit(:per_page, filter: {}, sort: {}).to_h)
end

#admin_shortcode_assetsObject



77
78
79
80
81
82
83
84
85
86
87
88
89
# File 'app/helpers/action_admin/admin_helper.rb', line 77

def admin_shortcode_assets
  assets = ActionAdmin.config.shortcode_assets.map do |asset|
    type = asset.split('.').last
    type == 'css' ? stylesheet_link_tag(asset) : javascript_include_tag(asset)
  end

  packs = ActionAdmin.config.shortcode_packs.map do |asset|
    type = asset.split('.').last
    type == 'css' ? stylesheet_pack_tag(asset) : javascript_pack_tag(asset)
  end

  assets.join.html_safe + packs.join.html_safe
end

#admin_shortcode_present(shortcode, presenter = nil) ⇒ Object



65
66
67
68
69
70
71
# File 'app/helpers/action_admin/admin_helper.rb', line 65

def admin_shortcode_present(shortcode, presenter=nil)
  class_name = shortcode.classify
  presenter  = presenter || "Admin::Shortcode::#{class_name}Presenter"
  presenter  = "#{presenter}".safe_constantize || 'ActionAdmin::ShortcodePresenter'.constantize

  presenter.new(shortcode, self)
end

#merge_params(original, keys, candidates) ⇒ Object



54
55
56
57
58
59
# File 'app/helpers/action_admin/admin_helper.rb', line 54

def merge_params(original, keys, candidates)
  original = Hash(original)
  selected = candidates.select { |k, _v| Array(keys).include? :"#{k}" }

  original.merge(selected)
end