ct_table_for 0.1.14.beta → 0.1.15.beta

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 041f6baa92ac9afa0958cc533634b04a227375a78ad0112e04443c918769960a
4
- data.tar.gz: 106b8f09e6c614d19de6063cb0beaed28ce8d8751a2c126f300070ab00460907
3
+ metadata.gz: 47d43adfaf238986ed6bc4a3179a2c1d88754ac7bdac76514b94425e189e3a4a
4
+ data.tar.gz: edfb06df4f5c923a5982dda3121639006c749f23ea06b28bbc1a72d29786d0d8
5
5
  SHA512:
6
- metadata.gz: db5fee74fd15bd4ce79e9afd1ab1bf17d2e54664f6db63f34ba0fea0e1749302175e59413dfd8976298e6cc7a11574258d33575918e4d3ffed0badd02c8fe476
7
- data.tar.gz: d123e433841e73634945b587f7e398a46ef70c6349e50e4a9923b5bb9816c911997d95cdd76b49baf659c6b5aa0c8387d665470b354e79b4a3c826a76b5e8c18
6
+ metadata.gz: eb1cbb2e933b3af1be135e9ec7ae13a93abcb442fe7820bfb28e73e3bbe800937d9282d64beb2a0dcd2dbb8caf0ba791a861a2e75602570dbb5ef78b41b7b4b2
7
+ data.tar.gz: 2e8fedb77519ce6ace6e965863889ae052e97bf725e096a11c16d8e82fbaacdfeae432f44c4bb8f8e6340d1f1e37858193036ab5ccbd044a2165d8bd8fe834bb
@@ -176,29 +176,19 @@ module CtTableFor
176
176
  html << %Q{<td data-link-enabled="false">}
177
177
  html << %Q{<div class="btn-group btn-group-sm" role="group" aria-label="#{I18n.t(:actions, scope: [:table_for]).capitalize}">}
178
178
  nesting = (options[:actions][:premodel] || []) + [record]
179
- buttons, *btn_options = options[:actions][:buttons].split(":")
180
- buttons.each do |action|
179
+ buttons = options[:actions][:buttons].map{ |b| b.split("|")}
180
+ buttons.each do |action, *extras|
181
181
  return "" if defined?(CanCanCan) and cannot?(action, record)
182
- label = I18n.t(action.to_sym, scope: [:table_for, :buttons]).capitalize
183
- custom_action_class = %Q{#{CtTableFor.table_for_default_action_base_class} #{options.dig(:btn_class, action.to_sym) || CtTableFor.table_for_action_class[action.to_sym]}}
184
182
  case action.to_sym
185
183
  when :show
186
- if options[:actions][:icons] != false
187
- label = %Q{<i class="#{CtTableFor.table_for_icon_font_base_class} #{CtTableFor.table_for_icon_font_base_class}-#{CtTableFor.table_for_action_icons[:show]}"></i>}
188
- end
189
- html << link_to(label.html_safe, polymorphic_path(nesting), class: custom_action_class)
184
+ html << link_to(label_for_action(action, options[:actions][:icons]).html_safe, polymorphic_path(nesting), class: class_for_action(action, options))
190
185
  when :edit
191
- if options[:actions][:icons] != false
192
- label = %Q{<i class="#{CtTableFor.table_for_icon_font_base_class} #{CtTableFor.table_for_icon_font_base_class}-#{CtTableFor.table_for_action_icons[:edit]}"></i>}
193
- end
194
- html << link_to(label.html_safe, edit_polymorphic_path(nesting), class: custom_action_class)
186
+ html << link_to(label_for_action(action, options[:actions][:icons]).html_safe, edit_polymorphic_path(nesting), class: class_for_action(action, options))
195
187
  when :destroy
196
- if options[:actions][:icons] != false
197
- label = %Q{<i class="#{CtTableFor.table_for_icon_font_base_class} #{CtTableFor.table_for_icon_font_base_class}-#{CtTableFor.table_for_action_icons[:destroy]}"></i>}
198
- end
199
- html << link_to(label.html_safe, polymorphic_path(nesting),
200
- method: :delete, class: custom_action_class,
201
- data: { confirm: I18n.t('table_for.messages.are_you_sure').capitalize })
188
+ html << link_to(label_for_action(action, options[:actions][:icons]).html_safe, polymorphic_path(nesting),
189
+ method: :delete, class: class_for_action(action, options), data: { confirm: I18n.t('table_for.messages.are_you_sure').capitalize })
190
+ when :custom
191
+ html << button_for_custom_action(record, options, extras)
202
192
  else
203
193
  # TODO:
204
194
  # nesting_custom = nesting + btn_options[0]
@@ -211,6 +201,27 @@ module CtTableFor
211
201
  html.html_safe
212
202
  end
213
203
 
204
+ def label_for_action action, icons = true
205
+ label = I18n.t(action.to_sym, scope: [:table_for, :buttons]).capitalize
206
+ if icons != false
207
+ label = %Q{<i class="#{CtTableFor.table_for_icon_font_base_class} #{CtTableFor.table_for_icon_font_base_class}-#{CtTableFor.table_for_action_icons[action.to_sym]}"></i>}
208
+ end
209
+ label
210
+ end
211
+
212
+ def class_for_action action, options
213
+ %Q{#{CtTableFor.table_for_default_action_base_class} #{options.dig(:btn_class, action.to_sym) || CtTableFor.table_for_action_class[action.to_sym]}}
214
+ end
215
+
216
+ def button_for_custom_action record, options, extras
217
+ parsed_extras = parse_extras(extras)
218
+ if options[:actions][:icons] != false
219
+ label = %Q{<i class="#{CtTableFor.table_for_icon_font_base_class} #{CtTableFor.table_for_icon_font_base_class}-#{parsed_extras[:icon]}"></i>}
220
+ end
221
+ custom_action_class = %Q{#{CtTableFor.table_for_default_action_base_class} #{parsed_extras[:class]}}
222
+ link_to(label.html_safe, polymorphic_path([parsed_extras[:link], record]), class: custom_action_class, title: parsed_extras[:title])
223
+ end
224
+
214
225
  def uri?(string)
215
226
  # http://ruby-doc.org/stdlib-2.4.0/libdoc/uri/rdoc/URI.html
216
227
  uri = URI.parse(string)
@@ -220,5 +231,9 @@ module CtTableFor
220
231
  rescue URI::InvalidURIError
221
232
  false
222
233
  end
234
+
235
+ def parse_extras(extras)
236
+ Hash[extras.collect { |extra| [extra.split(":").first, extra.split(":").last] } ].with_indifferent_access
237
+ end
223
238
  end
224
239
  end
@@ -1,3 +1,3 @@
1
1
  module CtTableFor
2
- VERSION = '0.1.14.beta'
2
+ VERSION = '0.1.15.beta'
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ct_table_for
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.14.beta
4
+ version: 0.1.15.beta
5
5
  platform: ruby
6
6
  authors:
7
7
  - Agustí B.R.
@@ -10,7 +10,7 @@ authors:
10
10
  autorequire:
11
11
  bindir: bin
12
12
  cert_chain: []
13
- date: 2018-11-13 00:00:00.000000000 Z
13
+ date: 2019-01-07 00:00:00.000000000 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: rails