Class: ActionTable::View
- Inherits:
-
Object
- Object
- ActionTable::View
- Includes:
- ActionView::Helpers::UrlHelper
- Defined in:
- lib/action_table/view.rb
Instance Attribute Summary collapse
-
#rows ⇒ Object
readonly
Returns the value of attribute rows.
Instance Method Summary collapse
-
#actions_header ⇒ Object
add header column padding for actions.
- #columns(record) ⇒ Object
-
#controller ⇒ Object
This must be defined for record_path to work.
- #headers ⇒ Object
-
#initialize(columns:, records:, paginate: false, links: ActionTable.config.links, actions: ActionTable.config.actions) ⇒ View
constructor
A new instance of View.
- #paginate? ⇒ Boolean
- #paginate_param_name ⇒ Object
-
#record_path(record, action: nil) ⇒ Object
Contstruct path to record, i.e programs_path(record).
Constructor Details
#initialize(columns:, records:, paginate: false, links: ActionTable.config.links, actions: ActionTable.config.actions) ⇒ View
Returns a new instance of View.
12 13 14 15 16 17 18 19 20 21 22 23 24 |
# File 'lib/action_table/view.rb', line 12 def initialize( columns:, records:, paginate: false, links: ActionTable.config.links, actions: ActionTable.config.actions ) @columns = Array(columns).map(&:to_s) @rows = records @paginate = paginate @links = Set.new(Array(links).map(&:to_s)).reject(&:empty?) @actions = Array(actions).map(&:to_s) end |
Instance Attribute Details
#rows ⇒ Object (readonly)
Returns the value of attribute rows.
10 11 12 |
# File 'lib/action_table/view.rb', line 10 def rows @rows end |
Instance Method Details
#actions_header ⇒ Object
add header column padding for actions
31 32 33 |
# File 'lib/action_table/view.rb', line 31 def actions_header @actions_header ||= [''] * @actions.length end |
#columns(record) ⇒ Object
35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 |
# File 'lib/action_table/view.rb', line 35 def columns(record) attribute_columns = @columns.map do |name| title = record.public_send(name) if title.present? && @links.include?(name) link_to(title, record_path(record)) else title end end actions = t_actions.zip(@actions).map! do |data| title, name = data link_to(title, record_path(record, action: name)) end attribute_columns + actions end |
#controller ⇒ Object
This must be defined for record_path to work
62 63 64 |
# File 'lib/action_table/view.rb', line 62 def controller table_name end |
#headers ⇒ Object
26 27 28 |
# File 'lib/action_table/view.rb', line 26 def headers @headers ||= @columns.map { |name| t_col(name) } end |
#paginate? ⇒ Boolean
53 54 55 |
# File 'lib/action_table/view.rb', line 53 def paginate? @paginate end |
#paginate_param_name ⇒ Object
57 58 59 |
# File 'lib/action_table/view.rb', line 57 def paginate_param_name "#{model_name}_page" end |
#record_path(record, action: nil) ⇒ Object
Contstruct path to record, i.e programs_path(record)
67 68 69 70 71 |
# File 'lib/action_table/view.rb', line 67 def record_path(record, action: nil) action = nil if action.to_s == 'show' path = [action, model_name, 'path'].compact.join('_') public_send(path, record) end |