infotable 1.7.0 → 1.7.1
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: c6f63015561d1df46e4b122f9b606090fb612a5b9d1ee44f0b9dca99b35296cf
|
|
4
|
+
data.tar.gz: 6efc93c800d85156207f25969c09ab23987d2d744d5228aad3523e6a2c72c846
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 41163562db80c33a9e3dc0e50f8e44e29c9dc0115b59a9678b646e9e3369d5f4a8fbdea8bf05f15a1e8be5c7a3b1e016b7976e5da0f2a84b59570559a5087019
|
|
7
|
+
data.tar.gz: 33690003b317f43328b21f9c92c2e46415c095032d888d8f0f6d07da2d0683e9da897d09bcbbd84b7e837996a321b96d2fa65a82857e1ff032b895362b209b77
|
data/README.md
CHANGED
|
@@ -602,6 +602,8 @@ column :actions,
|
|
|
602
602
|
|
|
603
603
|
`method:` and `confirm:` use Turbo (`data-turbo-method`, `data-turbo-confirm`). Labels are HTML-escaped.
|
|
604
604
|
|
|
605
|
+
Rows render inside the table's own `<turbo-frame>`, so every action link gets `data-turbo-frame="_top"` and navigates the whole page (a plain link would end in Turbo's "Content missing"). To load an action into another frame (a modal, a side panel), pass it: `{ label: "Edit", url: ..., data: { turbo_frame: "modal" } }`.
|
|
606
|
+
|
|
605
607
|
#### 6. Link Formatter (`:link`)
|
|
606
608
|
|
|
607
609
|
```ruby
|
|
@@ -616,7 +618,7 @@ column :name,
|
|
|
616
618
|
formatter_options: { url: ->(record) { user_path(record) } } # Proc (run in the view), Symbol or String
|
|
617
619
|
```
|
|
618
620
|
|
|
619
|
-
Only relative URLs, `http(s)`, `mailto` and `tel` are linked (`javascript:` and friends render as plain text). Options: `url`, `label`, `external` (`target="_blank"` + `rel="noopener noreferrer"`), `class
|
|
621
|
+
Only relative URLs, `http(s)`, `mailto` and `tel` are linked (`javascript:` and friends render as plain text). Options: `url`, `label`, `external` (`target="_blank"` + `rel="noopener noreferrer"`), `class`, `data` (data-* attributes). Like action links, the link navigates the whole page (`data-turbo-frame="_top"`) unless `data: { turbo_frame: "..." }` names another frame.
|
|
620
622
|
|
|
621
623
|
#### 7. Avatar Formatter (`:avatar`)
|
|
622
624
|
|
|
@@ -59,9 +59,10 @@ module Infotable
|
|
|
59
59
|
)
|
|
60
60
|
end
|
|
61
61
|
|
|
62
|
-
# Turbo-compatible: non-GET verbs use data-turbo-method, confirm uses data-turbo-confirm
|
|
62
|
+
# Turbo-compatible: non-GET verbs use data-turbo-method, confirm uses data-turbo-confirm.
|
|
63
|
+
# Actions navigate the whole page (data-turbo-frame="_top") unless data: { turbo_frame: } says otherwise.
|
|
63
64
|
def link_data(data, method, confirm)
|
|
64
|
-
data = data
|
|
65
|
+
data = top_frame_data(data)
|
|
65
66
|
data[:turbo_method] = method unless method.to_sym == :get
|
|
66
67
|
data[:turbo_confirm] = confirm if confirm
|
|
67
68
|
data
|
|
@@ -42,6 +42,15 @@ module Infotable
|
|
|
42
42
|
def html_safe(str)
|
|
43
43
|
str.to_s.html_safe
|
|
44
44
|
end
|
|
45
|
+
|
|
46
|
+
# Cells render inside the table's own <turbo-frame>, so a plain link would load its target into
|
|
47
|
+
# that frame ("Content missing"). Default to the whole page; a given turbo_frame (any key
|
|
48
|
+
# spelling: :turbo_frame, "turbo_frame", "turbo-frame") wins, e.g. a modal frame.
|
|
49
|
+
def top_frame_data(data)
|
|
50
|
+
data = (data || {}).to_h.transform_keys { |key| key.to_s.tr("-", "_").to_sym }
|
|
51
|
+
data[:turbo_frame] = "_top" if data[:turbo_frame].blank?
|
|
52
|
+
data
|
|
53
|
+
end
|
|
45
54
|
end
|
|
46
55
|
end
|
|
47
56
|
end
|
|
@@ -5,7 +5,8 @@ module Infotable
|
|
|
5
5
|
# url: ->(record) { user_path(record) }, # Proc (run in the view), Symbol (helper method) or String
|
|
6
6
|
# label: ->(record) { record.email }, # optional, defaults to the cell value
|
|
7
7
|
# external: true, # target=_blank rel="noopener noreferrer"
|
|
8
|
-
# class: "..."
|
|
8
|
+
# class: "...", # replaces the default classes
|
|
9
|
+
# data: { turbo_frame: "modal" } # data-* attributes; links target the whole page (_top) by default
|
|
9
10
|
# }
|
|
10
11
|
# Without url: the value itself is the URL (handy for website columns); mailto:/tel: work too.
|
|
11
12
|
class LinkFormatter < BaseFormatter
|
|
@@ -19,7 +20,7 @@ module Infotable
|
|
|
19
20
|
url = options.key?(:url) ? resolve(options[:url], record) : value
|
|
20
21
|
return label.to_s unless self.class.safe_url?(url)
|
|
21
22
|
|
|
22
|
-
attributes = { href: url.to_s, class: options[:class] || DEFAULT_CLASSES }
|
|
23
|
+
attributes = { href: url.to_s, class: options[:class] || DEFAULT_CLASSES, data: top_frame_data(options[:data]) }
|
|
23
24
|
attributes.merge!(target: "_blank", rel: "noopener noreferrer") if options[:external]
|
|
24
25
|
|
|
25
26
|
link_to(label.to_s, url.to_s, attributes)
|
data/lib/infotable/version.rb
CHANGED