katalyst-tables 2.4.0 → 2.5.0
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:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 73c920aef2dfd59566ab635a3b7f573a6bb6cc6b16548e9e198c23d021d571dd
|
4
|
+
data.tar.gz: 2b2f8000946bda4871efe3ea052b29ff87fdb43cd1eaf1861fd5cdcb0cd52411
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: fe91356719cc1f290f90245cc22742c6d6a328818b42c95412baa10f8affe3a2d1e48e7733d439ec185c48bea7c4bc40f8eff9e986375200d37a3a020a063c75
|
7
|
+
data.tar.gz: c4a65aac6559e0afb91cfde6f6efc4a4f1d06c1e4679fff3e903c94272b3c8f6f51005bd009013fbca60be7d08eb45edc3fba3e5926da15d28c78da449fa736a
|
data/CHANGELOG.md
CHANGED
@@ -1,5 +1,15 @@
|
|
1
1
|
## [Unreleased]
|
2
2
|
|
3
|
+
## [2.5.0]
|
4
|
+
|
5
|
+
- Breaking change: use Rails' object lookup path to find row partials
|
6
|
+
Previously: Nested::ResourceController would have looked for Nested::Model in
|
7
|
+
the controller directory:
|
8
|
+
app/views/nested/resources/_nested_model.html+row.erb
|
9
|
+
After this change, uses Rails' polymorphic partials logic and looks in the
|
10
|
+
model views directory:
|
11
|
+
app/views/nested/models/_model.html+row.erb
|
12
|
+
|
3
13
|
## [2.4.0]
|
4
14
|
|
5
15
|
- Internal refactor of filters to make it easier to add custom extensions
|
@@ -20,27 +20,24 @@ module Katalyst
|
|
20
20
|
private
|
21
21
|
|
22
22
|
def row_proc
|
23
|
-
@row_proc
|
23
|
+
if @row_proc
|
24
|
+
@row_proc
|
25
|
+
elsif @__vc_render_in_block
|
26
|
+
@row_proc = @__vc_render_in_block
|
27
|
+
else
|
28
|
+
@row_proc = Proc.new do |row, object|
|
29
|
+
row_renderer.render_row(row, object, view_context)
|
30
|
+
end
|
31
|
+
end
|
24
32
|
end
|
25
33
|
|
26
|
-
def
|
27
|
-
@
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
# Collection::Base overwrites param_key for form_with compatibility
|
34
|
-
items.model_name.param_key.to_s
|
35
|
-
end
|
36
|
-
|
37
|
-
def template_name
|
38
|
-
# Collection::Base overwrites param_key for form_with compatibility
|
39
|
-
items.model_name.param_key.to_sym
|
40
|
-
end
|
41
|
-
|
42
|
-
def items
|
43
|
-
collection.respond_to?(:items) ? collection.items : collection
|
34
|
+
def row_renderer
|
35
|
+
@row_renderer ||= RowRenderer.new(@lookup_context,
|
36
|
+
collection: collection,
|
37
|
+
as: @as,
|
38
|
+
partial: @partial,
|
39
|
+
variants: [:row],
|
40
|
+
formats: [:html])
|
44
41
|
end
|
45
42
|
end
|
46
43
|
end
|
@@ -0,0 +1,57 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Katalyst
|
4
|
+
module Tables
|
5
|
+
class RowRenderer < ActionView::PartialRenderer # :nodoc:
|
6
|
+
include ObjectRendering
|
7
|
+
|
8
|
+
def initialize(lookup_context, collection:, partial:, **options)
|
9
|
+
super(lookup_context, options)
|
10
|
+
|
11
|
+
@collection = collection
|
12
|
+
@partial = partial
|
13
|
+
end
|
14
|
+
|
15
|
+
def render_row(row, object, view_context)
|
16
|
+
@row = row
|
17
|
+
@object = object
|
18
|
+
|
19
|
+
if @partial.blank?
|
20
|
+
example = example_for(@collection)
|
21
|
+
@partial = partial_path(example, view_context) if example.present?
|
22
|
+
end
|
23
|
+
|
24
|
+
# if we still cannot find an example return an empty table (no header row)
|
25
|
+
return "" if @partial.blank?
|
26
|
+
|
27
|
+
@local_name ||= local_variable(@partial)
|
28
|
+
render(@partial, view_context, nil)
|
29
|
+
end
|
30
|
+
|
31
|
+
private
|
32
|
+
|
33
|
+
def example_for(collection)
|
34
|
+
if collection.respond_to?(:items)
|
35
|
+
example_for(collection.items)
|
36
|
+
elsif collection.respond_to?(:any?) && collection.any?
|
37
|
+
collection.first
|
38
|
+
elsif collection.respond_to?(:model)
|
39
|
+
collection.model.new
|
40
|
+
end
|
41
|
+
# if none of the above strategies match, return nil
|
42
|
+
rescue ArgumentError
|
43
|
+
nil # if we could not construct an example without passing arguments, return nil
|
44
|
+
end
|
45
|
+
|
46
|
+
def template_keys(path)
|
47
|
+
super + [@local_name, :row]
|
48
|
+
end
|
49
|
+
|
50
|
+
def render_partial_template(view, locals, template, layout, block)
|
51
|
+
locals[@local_name || template.variable] = @object
|
52
|
+
locals[:row] = @row
|
53
|
+
super(view, locals, template, layout, block)
|
54
|
+
end
|
55
|
+
end
|
56
|
+
end
|
57
|
+
end
|
@@ -30,7 +30,7 @@ module Katalyst
|
|
30
30
|
# - `header`: whether to render the header row (defaults to true, supports options)
|
31
31
|
# - `caption`: whether to render the caption (defaults to true, supports options)
|
32
32
|
# - `object_name`: the name of the object to use for partial rendering (defaults to collection.model_name.i18n_key)
|
33
|
-
# - `partial`: the name of the partial to use for rendering each row (defaults to
|
33
|
+
# - `partial`: the name of the partial to use for rendering each row (defaults to to_partial_path on the object)
|
34
34
|
# - `as`: the name of the local variable to use for rendering each row (defaults to collection.model_name.param_key)
|
35
35
|
# In addition to these options, standard HTML attributes can be passed which will be added to the table tag.
|
36
36
|
def initialize(collection:,
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: katalyst-tables
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 2.
|
4
|
+
version: 2.5.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Katalyst Interactive
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2024-01-
|
11
|
+
date: 2024-01-30 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: katalyst-html-attributes
|
@@ -57,6 +57,7 @@ files:
|
|
57
57
|
- app/components/concerns/katalyst/tables/configurable_component.rb
|
58
58
|
- app/components/concerns/katalyst/tables/has_table_content.rb
|
59
59
|
- app/components/concerns/katalyst/tables/orderable.rb
|
60
|
+
- app/components/concerns/katalyst/tables/row_renderer.rb
|
60
61
|
- app/components/concerns/katalyst/tables/sortable.rb
|
61
62
|
- app/components/concerns/katalyst/tables/turbo_replaceable.rb
|
62
63
|
- app/components/katalyst/table_component.html.erb
|
@@ -115,7 +116,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
115
116
|
- !ruby/object:Gem::Version
|
116
117
|
version: '0'
|
117
118
|
requirements: []
|
118
|
-
rubygems_version: 3.4.
|
119
|
+
rubygems_version: 3.4.19
|
119
120
|
signing_key:
|
120
121
|
specification_version: 4
|
121
122
|
summary: HTML table generator for Rails views
|