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: 3c804c0709c28b4e2c79db6916c2c671991ad8d9108379c699b19f8668d8ca9e
4
- data.tar.gz: cb85d05e8559e6339c7dca255793c296fbe7f239f4a13024e7886c9013c4a594
3
+ metadata.gz: c6f63015561d1df46e4b122f9b606090fb612a5b9d1ee44f0b9dca99b35296cf
4
+ data.tar.gz: 6efc93c800d85156207f25969c09ab23987d2d744d5228aad3523e6a2c72c846
5
5
  SHA512:
6
- metadata.gz: df3fb6ab7d5c1ea362fd2d7662e9bf226681b08beea293a3879dbbb68f8a9217bb8a68c2c6d74c6270e149c40ce04f801a3cfc6f12b1fd640eaa88fe88119621
7
- data.tar.gz: eb71742998892dbc5e08bf6cf35bad0ad014cd964b6656895333cb67ff9c90d0a8ebc1db733d7a4242b6c3650ba35bc89dccaa58e8efe699eb1c0d181cec11e9
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.dup
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: "..." # replaces the default classes
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)
@@ -1,3 +1,3 @@
1
1
  module Infotable
2
- VERSION = "1.7.0"
2
+ VERSION = "1.7.1"
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: infotable
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.7.0
4
+ version: 1.7.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jakub Cieślar