Class: ActionAdmin::Header
- Inherits:
-
Object
- Object
- ActionAdmin::Header
- Defined in:
- lib/action_admin/header.rb
Instance Method Summary collapse
- #action(names) ⇒ Object
- #action_links(name, context) ⇒ Object
- #action_title(name, context) ⇒ Object
- #default_action_links(name, context) ⇒ Object
- #default_links(context) ⇒ Object
- #default_title(context) ⇒ Object
-
#initialize ⇒ Header
constructor
A new instance of Header.
- #link(options) ⇒ Object
- #title(value) ⇒ Object
Constructor Details
#initialize ⇒ Header
6 7 8 |
# File 'lib/action_admin/header.rb', line 6 def initialize self.actions = {} end |
Instance Method Details
#action(names) ⇒ Object
10 11 12 |
# File 'lib/action_admin/header.rb', line 10 def action(names) self.current_actions = Array(names) end |
#action_links(name, context) ⇒ Object
27 28 29 30 31 32 33 |
# File 'lib/action_admin/header.rb', line 27 def action_links(name, context) links = Hash(actions[:"#{name}"]).fetch :links, default_action_links(name, context) Array(links).map do |link| Hash[link.map { |k, v| [k, evaluate_value(v, context)] }] end end |
#action_title(name, context) ⇒ Object
22 23 24 25 |
# File 'lib/action_admin/header.rb', line 22 def action_title(name, context) title = Hash(actions[:"#{name}"]).fetch :title, default_title(context) evaluate_value(title, context) end |
#default_action_links(name, context) ⇒ Object
43 44 45 46 47 48 |
# File 'lib/action_admin/header.rb', line 43 def default_action_links(name, context) setup = { index: :new, new: :index, show: [:index, :edit, :destroy], edit: [:index, :show, :destroy] } links = default_links(context) Array(setup[:"#{name}"]).map { |l| links[l] }.reject(&:nil?) end |
#default_links(context) ⇒ Object
50 51 52 53 54 55 56 57 58 59 60 |
# File 'lib/action_admin/header.rb', line 50 def default_links(context) return {} unless context.controller.respond_to? :permitted_params { show: { label: 'View', icon: 'eye', url: :record_path, html: { class: 'success' } }, index: { label: 'Back', icon: 'arrow-left', url: :records_path, html: { class: 'secondary' } }, new: { label: 'New', icon: 'plus', url: :new_record_path, html: { class: 'success' } }, edit: { label: 'Edit', icon: 'pencil', url: :edit_record_path, html: { class: 'warning' } }, destroy: { label: 'Delete', icon: 'delete', url: :record_path, html: { class: 'alert' }, method: 'delete' } } end |
#default_title(context) ⇒ Object
35 36 37 38 39 40 41 |
# File 'lib/action_admin/header.rb', line 35 def default_title(context) if context.action_name == 'index' context.controller_name.titleize else context.action_name.titleize end end |
#link(options) ⇒ Object
18 19 20 |
# File 'lib/action_admin/header.rb', line 18 def link() current_actions.each { |a| add_action_key(a, :links, , true) } end |
#title(value) ⇒ Object
14 15 16 |
# File 'lib/action_admin/header.rb', line 14 def title(value) current_actions.each { |a| add_action_key(a, :title, value) } end |