ct_table_for 1.0.5 → 1.2.1
Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 4ed64782cf3f8a5963571ae9f299b2e5638119f12d39a500bc3e8bcca41a4486
|
4
|
+
data.tar.gz: 6b2fee9d9181d27a1626087d0936434938211beeb1db8b5964ff96e40df5c479
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: d699345c49749cd4e5f2dd1e679195cf0ec1936cbaa911ba74b487315d3872296a016b102d43ffb084049b6a2decf8d8d46a0ab7e7742b45eae0578b7e8ae9cb
|
7
|
+
data.tar.gz: 7545d61265dcf373140a8cf46d828b1e2f2699676742c95f1a0350300cf42f47a39fbe54adf54bed6678eafabd24de06d2aced9652af5aefc0ef7df41105fd68
|
@@ -6,6 +6,7 @@ module CtTableFor
|
|
6
6
|
# RWD Table
|
7
7
|
# use as: table_for Model, @collection, options: {}
|
8
8
|
# options: {
|
9
|
+
# style: "lambda {|model| method(model)}" // String: adds a method for css class
|
9
10
|
# actions: {
|
10
11
|
# buttons: %w(show, edit)}, // Hash: with array of buttons for actions
|
11
12
|
# premodel: [:bo, :admin], // Array: of symbols for nested namespaces/models
|
@@ -28,8 +29,8 @@ module CtTableFor
|
|
28
29
|
|
29
30
|
def table_for model, collection, options: {}
|
30
31
|
custom_id = options[:id].present? ? %Q{id="#{options[:id]}"} : ""
|
31
|
-
html = %Q{<div class="table-for-wrapper #{CtTableFor.table_for_wrapper_default_class}">}
|
32
|
-
html << %Q{<table #{custom_id} class="table-for #{CtTableFor.table_for_default_class} #{options[:class]} #{("table-clickable") if options[:clickable]}">}
|
32
|
+
html = %Q{<div class="table-for-wrapper #{CtTableFor.config.table_for_wrapper_default_class}">}
|
33
|
+
html << %Q{<table #{custom_id} class="table-for #{CtTableFor.config.table_for_default_class} #{options[:class]} #{("table-clickable") if options[:clickable]}">}
|
33
34
|
html << table_for_header(model, has_actions: options[:actions].present?, options: options)
|
34
35
|
html << table_for_content(model, collection, options: options)
|
35
36
|
html << %Q{</table>}
|
@@ -69,9 +70,9 @@ module CtTableFor
|
|
69
70
|
html = ""
|
70
71
|
html << %Q{<tbody>}
|
71
72
|
if collection.present?
|
72
|
-
custom_tr_class = options[:tr_class].present? ? %Q{class="#{options[:tr_class]}"} : ""
|
73
73
|
collection.each do |record|
|
74
|
-
|
74
|
+
css_classes = get_css_classes(record, options)
|
75
|
+
html << %Q{<tr data-colection-id="#{record.try(:id)}" #{css_classes} #{row_data_link(record, options)}>}
|
75
76
|
table_for_attributes(model, options).each do |attribute|
|
76
77
|
attribute, *params = attribute.split(":")
|
77
78
|
html << table_for_cell( model, record, attribute, cell_options: params )
|
@@ -110,7 +111,7 @@ module CtTableFor
|
|
110
111
|
nil
|
111
112
|
end
|
112
113
|
|
113
|
-
html << %Q{<td data-title="#{model.human_attribute_name("#{attribute}")}" class="#{CtTableFor.table_for_td_default_prefix_class}-#{attribute}">}
|
114
|
+
html << %Q{<td data-title="#{model.human_attribute_name("#{attribute}")}" class="#{CtTableFor.config.table_for_td_default_prefix_class}-#{attribute}">}
|
114
115
|
case value
|
115
116
|
when NilClass
|
116
117
|
html << %Q{<i class="fa fa-minus text-muted"></i>}
|
@@ -120,9 +121,9 @@ module CtTableFor
|
|
120
121
|
if cell_options.include? "currency"
|
121
122
|
html << number_to_currency(value)
|
122
123
|
elsif cell_options.include? "percentage"
|
123
|
-
html << number_to_percentage(value, precision: CtTableFor.table_for_numeric_percentage_precision)
|
124
|
+
html << number_to_percentage(value, precision: CtTableFor.config.table_for_numeric_percentage_precision)
|
124
125
|
else
|
125
|
-
html << %Q{
|
126
|
+
html << %Q{#{number_with_delimiter(value)}}
|
126
127
|
end
|
127
128
|
when ActiveSupport::TimeWithZone
|
128
129
|
# TODO: value.in_time_zone
|
@@ -141,7 +142,9 @@ module CtTableFor
|
|
141
142
|
when ActiveRecord::Associations::CollectionProxy
|
142
143
|
html << %Q{#{value.count}}
|
143
144
|
else
|
144
|
-
if
|
145
|
+
if defined?(ActiveStorage) && value.is_a?(ActiveStorage::Attached::One)
|
146
|
+
html << table_for_cell_for_image( record, attribute, cell_options: cell_options )
|
147
|
+
elsif uri?(value)
|
145
148
|
html << link_to(value, value)
|
146
149
|
elsif defined?(Paperclip) and value.is_a?(Paperclip::Attachment)
|
147
150
|
html << table_for_cell_for_image( record, attribute, cell_options: cell_options )
|
@@ -152,9 +155,9 @@ module CtTableFor
|
|
152
155
|
html << value.to_s
|
153
156
|
else
|
154
157
|
html << value.to_s.truncate(
|
155
|
-
CtTableFor.table_for_truncate_length,
|
156
|
-
separator: CtTableFor.table_for_truncate_separator,
|
157
|
-
omission: CtTableFor.table_for_truncate_omission
|
158
|
+
CtTableFor.config.table_for_truncate_length,
|
159
|
+
separator: CtTableFor.config.table_for_truncate_separator,
|
160
|
+
omission: CtTableFor.config.table_for_truncate_omission
|
158
161
|
)
|
159
162
|
end
|
160
163
|
end
|
@@ -166,8 +169,14 @@ module CtTableFor
|
|
166
169
|
def table_for_cell_for_image record, attribute, cell_options: {}
|
167
170
|
html = ""
|
168
171
|
size = cell_options.select{ |opt| ["thumb", "original", "small", "medium"].include? opt }.first || "thumb"
|
172
|
+
value = record.send(attribute)
|
173
|
+
return html unless value.present?
|
169
174
|
|
170
|
-
|
175
|
+
if value.is_a?(ActiveStorage::Attached::One)
|
176
|
+
html << image_tag(value, class: CtTableFor.config.table_for_cell_for_image_image_class, style: "max-height: 100px;")
|
177
|
+
else
|
178
|
+
html << image_tag(value.url(size), class: CtTableFor.config.table_for_cell_for_image_image_class, style: "max-height: 100px;")
|
179
|
+
end
|
171
180
|
html.html_safe
|
172
181
|
end
|
173
182
|
|
@@ -179,7 +188,7 @@ module CtTableFor
|
|
179
188
|
def table_for_actions(record, options: {} )
|
180
189
|
return "" if options[:actions].blank?
|
181
190
|
html = ""
|
182
|
-
html << %Q{<td data-link-enabled="false" class="#{CtTableFor.table_for_td_default_prefix_class}-actions">}
|
191
|
+
html << %Q{<td data-link-enabled="false" class="#{CtTableFor.config.table_for_td_default_prefix_class}-actions">}
|
183
192
|
html << %Q{<div class="btn-group btn-group-sm" role="group" aria-label="#{I18n.t(:actions, scope: [:table_for]).capitalize}">}
|
184
193
|
nesting = (options[:actions][:premodel] || []) + [record]
|
185
194
|
buttons = options[:actions][:buttons].map{ |b| b.split("|")}
|
@@ -191,16 +200,18 @@ module CtTableFor
|
|
191
200
|
when :show
|
192
201
|
html << link_to(label_for_action(action, options[:actions][:icons]).html_safe, polymorphic_path(nesting), class: class_for_action(action, options))
|
193
202
|
when :edit
|
194
|
-
|
203
|
+
url_helper = options.dig(:actions, :urls, :edit) || lambda{|obj| edit_polymorphic_path(nesting)}
|
204
|
+
html << link_to(label_for_action(action, options[:actions][:icons]).html_safe, url_helper.(nesting), class: class_for_action(action, options))
|
195
205
|
when :destroy
|
196
|
-
|
206
|
+
url_helper = options.dig(:actions, :urls, :destroy) || lambda{|obj| polymorphic_path(nesting)}
|
207
|
+
html << link_to(label_for_action(action, options[:actions][:icons]).html_safe, url_helper.(nesting),
|
197
208
|
method: :delete, class: class_for_action(action, options), data: { confirm: I18n.t('table_for.messages.are_you_sure').capitalize })
|
198
209
|
when :custom
|
199
210
|
html << button_for_custom_action(record, options, extras)
|
200
211
|
else
|
201
212
|
# TODO:
|
202
213
|
# nesting_custom = nesting + btn_options[0]
|
203
|
-
# label = icon CtTableFor.table_for_action_icons[:custom] if options[:actions][:icons] != false and defined?(FontAwesome)
|
214
|
+
# label = icon CtTableFor.config.table_for_action_icons[:custom] if options[:actions][:icons] != false and defined?(FontAwesome)
|
204
215
|
# html << link_to(label, polymorphic_path(nesting_custom), class: "btn btn-default btn-sm")
|
205
216
|
end
|
206
217
|
end
|
@@ -213,13 +224,13 @@ module CtTableFor
|
|
213
224
|
def label_for_action action, icons = true
|
214
225
|
label = I18n.t(action.to_sym, scope: [:table_for, :buttons]).capitalize
|
215
226
|
if icons != false
|
216
|
-
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>}
|
227
|
+
label = %Q{<i class="#{CtTableFor.config.table_for_icon_font_base_class} #{CtTableFor.config.table_for_icon_font_base_class}-#{CtTableFor.config.table_for_action_icons[action.to_sym]}"></i>}
|
217
228
|
end
|
218
229
|
label
|
219
230
|
end
|
220
231
|
|
221
232
|
def class_for_action action, options
|
222
|
-
%Q{#{CtTableFor.table_for_default_action_base_class} #{options.dig(:btn_class, action.to_sym) || CtTableFor.table_for_action_class[action.to_sym]}}
|
233
|
+
%Q{#{CtTableFor.config.table_for_default_action_base_class} #{options.dig(:btn_class, action.to_sym) || CtTableFor.config.table_for_action_class[action.to_sym]}}
|
223
234
|
end
|
224
235
|
|
225
236
|
def button_for_custom_action record, options, extras
|
@@ -228,18 +239,20 @@ module CtTableFor
|
|
228
239
|
label = if parsed_extras[:icons].to_s == "false"
|
229
240
|
parsed_extras[:title].presence || ""
|
230
241
|
else
|
231
|
-
%Q{<i class="#{CtTableFor.table_for_icon_font_base_class} #{CtTableFor.table_for_icon_font_base_class}-#{parsed_extras[:icon]}"></i>}
|
242
|
+
%Q{<i class="#{CtTableFor.config.table_for_icon_font_base_class} #{CtTableFor.config.table_for_icon_font_base_class}-#{parsed_extras[:icon]}"></i>}
|
232
243
|
end
|
233
244
|
ancestors_list = parsed_extras[:ancestors].presence || ""
|
234
245
|
ancestors = ancestors_list.split(",").map do |ancestor|
|
235
246
|
record.send(ancestor)
|
236
247
|
end
|
237
|
-
custom_action_class = %Q{#{CtTableFor.table_for_default_action_base_class} #{parsed_extras[:class]}}
|
238
|
-
|
239
|
-
|
240
|
-
|
241
|
-
|
242
|
-
|
248
|
+
custom_action_class = %Q{#{CtTableFor.config.table_for_default_action_base_class} #{parsed_extras[:class]}}
|
249
|
+
options= {
|
250
|
+
class: custom_action_class,
|
251
|
+
method: parsed_extras[:method],
|
252
|
+
title: parsed_extras[:title]
|
253
|
+
}
|
254
|
+
options[:target]= parsed_extras[:target] if parsed_extras[:target].present?
|
255
|
+
link_to(label.html_safe, polymorphic_path([parsed_extras[:link]&.to_sym, *ancestors, record]), options)
|
243
256
|
end
|
244
257
|
|
245
258
|
def uri?(string)
|
@@ -255,5 +268,11 @@ module CtTableFor
|
|
255
268
|
def parse_extras(extras)
|
256
269
|
Hash[extras.collect { |extra| [extra.split(":").first, extra.split(":").last] } ].with_indifferent_access
|
257
270
|
end
|
271
|
+
|
272
|
+
def get_css_classes(record, options = {})
|
273
|
+
style = options[:style].try(:call, record) || ""
|
274
|
+
tr_class = options[:tr_class] || ""
|
275
|
+
"class='#{tr_class} #{style}'"
|
276
|
+
end
|
258
277
|
end
|
259
278
|
end
|
data/lib/ct_table_for/engine.rb
CHANGED
@@ -1,18 +1,18 @@
|
|
1
1
|
module CtTableFor
|
2
|
-
class
|
3
|
-
mattr_accessor :table_for_default_class
|
4
|
-
mattr_accessor :table_for_wrapper_default_class
|
5
|
-
mattr_accessor :table_for_default_action_base_class
|
6
|
-
mattr_accessor :table_for_action_class
|
7
|
-
mattr_accessor :table_for_breakpoint
|
8
|
-
mattr_accessor :table_for_icon_font_base_class
|
9
|
-
mattr_accessor :table_for_action_icons
|
10
|
-
mattr_accessor :table_for_numeric_percentage_precision
|
11
|
-
mattr_accessor :table_for_cell_for_image_image_class
|
12
|
-
mattr_accessor :table_for_truncate_length
|
13
|
-
mattr_accessor :table_for_truncate_separator
|
14
|
-
mattr_accessor :table_for_truncate_omission
|
15
|
-
mattr_accessor :table_for_td_default_prefix_class
|
2
|
+
class Config
|
3
|
+
self.mattr_accessor :table_for_default_class
|
4
|
+
self.mattr_accessor :table_for_wrapper_default_class
|
5
|
+
self.mattr_accessor :table_for_default_action_base_class
|
6
|
+
self.mattr_accessor :table_for_action_class
|
7
|
+
self.mattr_accessor :table_for_breakpoint
|
8
|
+
self.mattr_accessor :table_for_icon_font_base_class
|
9
|
+
self.mattr_accessor :table_for_action_icons
|
10
|
+
self.mattr_accessor :table_for_numeric_percentage_precision
|
11
|
+
self.mattr_accessor :table_for_cell_for_image_image_class
|
12
|
+
self.mattr_accessor :table_for_truncate_length
|
13
|
+
self.mattr_accessor :table_for_truncate_separator
|
14
|
+
self.mattr_accessor :table_for_truncate_omission
|
15
|
+
self.mattr_accessor :table_for_td_default_prefix_class
|
16
16
|
|
17
17
|
self.table_for_wrapper_default_class = "table-responsive"
|
18
18
|
self.table_for_default_class = "table table-striped table-bordered table-condensed table-hover"
|
@@ -29,9 +29,13 @@ module CtTableFor
|
|
29
29
|
self.table_for_td_default_prefix_class = "td-item"
|
30
30
|
end
|
31
31
|
|
32
|
+
def self.config
|
33
|
+
@config||= Config.new
|
34
|
+
end
|
35
|
+
|
32
36
|
# this function maps the vars from your app into your engine
|
33
37
|
def self.setup(&block)
|
34
|
-
yield
|
38
|
+
yield config
|
35
39
|
end
|
36
40
|
|
37
41
|
class Engine < ::Rails::Engine
|
data/lib/ct_table_for/version.rb
CHANGED
metadata
CHANGED
@@ -1,16 +1,17 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: ct_table_for
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 1.2.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Agustí B.R.
|
8
8
|
- Isaac Massot
|
9
9
|
- Marc Reniu
|
10
|
+
- Oliver Valls
|
10
11
|
autorequire:
|
11
12
|
bindir: bin
|
12
13
|
cert_chain: []
|
13
|
-
date:
|
14
|
+
date: 2021-10-22 00:00:00.000000000 Z
|
14
15
|
dependencies:
|
15
16
|
- !ruby/object:Gem::Dependency
|
16
17
|
name: rails
|
@@ -18,19 +19,17 @@ dependencies:
|
|
18
19
|
requirements:
|
19
20
|
- - ">="
|
20
21
|
- !ruby/object:Gem::Version
|
21
|
-
version: '
|
22
|
+
version: '6.1'
|
22
23
|
type: :runtime
|
23
24
|
prerelease: false
|
24
25
|
version_requirements: !ruby/object:Gem::Requirement
|
25
26
|
requirements:
|
26
27
|
- - ">="
|
27
28
|
- !ruby/object:Gem::Version
|
28
|
-
version: '
|
29
|
+
version: '6.1'
|
29
30
|
description: table_for is a rails table builder given an ActiveRecord
|
30
31
|
email:
|
31
|
-
-
|
32
|
-
- issac.mg@coditramuntana.com
|
33
|
-
- marc.rs@coditramuntana.com
|
32
|
+
- info@coditramuntana.com
|
34
33
|
executables: []
|
35
34
|
extensions: []
|
36
35
|
extra_rdoc_files: []
|
@@ -67,7 +66,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
67
66
|
- !ruby/object:Gem::Version
|
68
67
|
version: '0'
|
69
68
|
requirements: []
|
70
|
-
rubygems_version: 3.
|
69
|
+
rubygems_version: 3.1.2
|
71
70
|
signing_key:
|
72
71
|
specification_version: 4
|
73
72
|
summary: Rails table builder that makes it easy to do responsive tables ActiveRecord
|