overlastic 0.10.2 → 0.12.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: b1b527b482e60b28f554d457008dec266231ba993c12caf57d9b33047dc20abb
4
- data.tar.gz: 0de5982c64a49f698aae70960470a260a4b0c85b76a611a00a4ebe89a852e87e
3
+ metadata.gz: b9564bcaf740459d550f4e7f0195cf4f1b1a4eb1da38dac702d71e6fcc1d972d
4
+ data.tar.gz: 1c5f9f6ef8eb8cac4beff8406e8d743332e3390961bb56f55d93204fdfc5ec7b
5
5
  SHA512:
6
- metadata.gz: 9d97e99a7b509f0698173bc319ccbbd4cd98634e8149316666623590f0376b35eb2ab6f5ef8f22a9b221574f9778cac1a4697ea0294a3aa53d661a3428578fe9
7
- data.tar.gz: 44d9dfca19da499f86ffbfb91a152f0210c54973d9f986819bd5bd6a3ea52a1b32ab3500f7a8770d20a5d6b0a527c224d122e810a2296c377fd96176cf59abc4
6
+ metadata.gz: 4c571017098b4cdecdfd8de6f8a28d9a2a8a4caaafdb31f656d3e6d83dc75d7efd09eb3f8d32002527607fe1e93c4304be123e34f7477f1cba0da9502d6adae2
7
+ data.tar.gz: fbd47da78e6fa186bcc6c55b8c58f24f07ae3db642191d3e004a91346919eaaece39f4727519db12e5b2f606af9d86a7470673a6a0285aec2248003eee5043d9
data/README.md CHANGED
@@ -9,11 +9,11 @@
9
9
  <h3 align="center">Fantastically easy overlays using <a href="https://hotwired.dev/" target="_blank">Hotwire</a>.</h3>
10
10
 
11
11
  <p align="center">
12
- <img alt="Build" src="https://img.shields.io/github/workflow/status/martinzamuner/overlastic/CI">
12
+ <img alt="Build" src="https://img.shields.io/github/actions/workflow/status/martinzamuner/overlastic/ci.yml?branch=main">
13
13
  <img alt="Gem" src="https://img.shields.io/gem/v/overlastic">
14
14
  <img alt="rails version" src="https://img.shields.io/badge/rails-%3E%3D%206.1.0-informational">
15
15
  <img alt="turbo-rails version" src="https://img.shields.io/badge/turbo--rails-%3E%3D%201.3.0-informational">
16
- <img alt="License" src="https://img.shields.io/github/license/martinzamuner/overlastic">
16
+ <img alt="License" src="https://img.shields.io/badge/license-MIT-green">
17
17
  </p>
18
18
 
19
19
  Load any page inside an overlay (dialog modal, slide-out pane, or whatever else floats your boat). As easy as replacing `link_to` with `link_to_dialog`.
@@ -247,7 +247,15 @@ end
247
247
 
248
248
  ## UI customization
249
249
 
250
- Overlastic comes with default views for both the dialog and pane overlays. They are intended to provide an easy way to try the gem. For real-world usage you're expected to implement your own UI elements, or use something like [Bootstrap](https://getbootstrap.com) or [TailwindCSS Stimulus Components](https://github.com/excid3/tailwindcss-stimulus-components).
250
+ Overlastic comes with default partials for both the dialog and pane overlays. They are intended to provide an easy way to try the gem. For real-world usage you're expected to implement your own UI elements, or use something like [Bootstrap](https://getbootstrap.com) or [TailwindCSS Stimulus Components](https://github.com/excid3/tailwindcss-stimulus-components).
251
+
252
+ Keep in mind that the overlay partials will be used as layouts for the rendered content. You can access the content of your `overlay_args` as well as allowing `content_for` slots with something like:
253
+
254
+ ```erb
255
+ <% title = local_assigns[:title] || content_for(:overlay_title) %>
256
+
257
+ <h1><%= title %></h1>
258
+ ```
251
259
 
252
260
  <details>
253
261
  <summary>Default overlays</summary><br>
@@ -4,28 +4,6 @@ module Overlastic::Concerns::OverlayHandling
4
4
  included do
5
5
  before_action :add_overlay_variant
6
6
 
7
- private
8
-
9
- def add_overlay_variant
10
- request.variant = :overlay if helpers.current_overlay_name.present?
11
- end
12
-
13
- def close_overlay(key = :last, **options)
14
- overlay_name = helpers.overlay_name_from(key) || :overlay1
15
-
16
- # In case a Turbo Stream is appended which renders new overlay links, they should be generated
17
- # relative to the foremost overlay still open after closing the requested overlays.
18
- request.headers["Overlay-Name"] = :"overlay#{helpers.overlay_number_from(overlay_name) - 1}"
19
-
20
- options.filter { |key, _| key.in? self.class._flash_types }.each { |key, value| flash.now[key] = value }
21
-
22
- if block_given?
23
- render overlay: overlay_name, html: helpers.overlastic_tag(id: overlay_name), append_turbo_stream: yield
24
- else
25
- render overlay: overlay_name, html: helpers.overlastic_tag(id: overlay_name)
26
- end
27
- end
28
-
29
7
  def render(*args, **options, &block)
30
8
  # Force render of overlays without an initiator
31
9
  request.headers["Overlay-Target"] ||= options.delete(:overlay_target)
@@ -62,13 +40,13 @@ module Overlastic::Concerns::OverlayHandling
62
40
  if block_given? || options[:html]
63
41
  stream_response = turbo_stream.replace_overlay(overlay_name, html: render_to_string(*args, **options, &block))
64
42
  else
65
- stream_response = turbo_stream.replace_overlay(overlay_name, html: helpers.render_overlay { render_to_string(*args, **options, &block) })
43
+ stream_response = turbo_stream.replace_overlay(overlay_name, html: render_overlay(*args, **options, &block))
66
44
  end
67
45
  elsif request.variant.overlay?
68
46
  if initiator || error || target != "_top"
69
47
  options[:layout] = false
70
48
 
71
- stream_response = turbo_stream.replace_overlay(overlay_name, html: helpers.render_overlay { render_to_string(*args, **options, &block) })
49
+ stream_response = turbo_stream.replace_overlay(overlay_name, html: render_overlay(*args, **options, &block))
72
50
  else
73
51
  request.headers["Overlay-Name"] = nil
74
52
  request.variant.delete :overlay
@@ -87,6 +65,20 @@ module Overlastic::Concerns::OverlayHandling
87
65
  end
88
66
  end
89
67
 
68
+ def render_overlay(*args, **options, &block)
69
+ type = request.headers["Overlay-Type"] || Overlastic.configuration.default_overlay
70
+ overlay_args = JSON.parse(Base64.urlsafe_decode64(request.headers["Overlay-Args"])) rescue {}
71
+ normalize_partial_name = ->(path) { path.sub(%r{[^/]+\z}) { |last| last.start_with?('_') ? last : "_#{last}" } }
72
+
73
+ options[:locals] ||= {}
74
+ options[:locals].merge! overlay_args.to_h.symbolize_keys
75
+ options[:layout] = proc { Overlastic.configuration.public_send(:"#{type}_overlay_view_path").yield_self(&normalize_partial_name) }
76
+
77
+ helpers.overlastic_tag do
78
+ helpers.concat render_to_string(*args, **options, &block)
79
+ end
80
+ end
81
+
90
82
  # Based on https://github.com/hotwired/turbo-rails/pull/367
91
83
  # by seanpdoyle
92
84
  def redirect_to(options = {}, response_options = {})
@@ -113,5 +105,27 @@ module Overlastic::Concerns::OverlayHandling
113
105
  super
114
106
  end
115
107
  end
108
+
109
+ private
110
+
111
+ def add_overlay_variant
112
+ request.variant = :overlay if helpers.current_overlay_name.present?
113
+ end
114
+
115
+ def close_overlay(key = :last, **options)
116
+ overlay_name = helpers.overlay_name_from(key) || :overlay1
117
+
118
+ # In case a Turbo Stream is appended which renders new overlay links, they should be generated
119
+ # relative to the foremost overlay still open after closing the requested overlays.
120
+ request.headers["Overlay-Name"] = :"overlay#{helpers.overlay_number_from(overlay_name) - 1}"
121
+
122
+ options.filter { |key, _| key.in? self.class._flash_types }.each { |key, value| flash.now[key] = value }
123
+
124
+ if block_given?
125
+ render overlay: overlay_name, html: helpers.overlastic_tag(id: overlay_name), append_turbo_stream: yield
126
+ else
127
+ render overlay: overlay_name, html: helpers.overlastic_tag(id: overlay_name)
128
+ end
129
+ end
116
130
  end
117
131
  end
@@ -43,16 +43,4 @@ module Overlastic::OverlaysHelper
43
43
  def valid_overlay_name?(name)
44
44
  overlay_number_from(name).positive?
45
45
  end
46
-
47
- def render_overlay(locals = {}, &block)
48
- string = capture(&block)
49
- type = request.headers["Overlay-Type"] || Overlastic.configuration.default_overlay
50
- args_header = request.headers["Overlay-Args"]
51
- overlay_args = JSON.parse(Base64.urlsafe_decode64(request.headers["Overlay-Args"])) if args_header.present?
52
- locals.merge! overlay_args.to_h.symbolize_keys
53
-
54
- overlastic_tag do
55
- concat render(Overlastic.configuration.public_send(:"#{type}_overlay_view_path"), locals) { string }
56
- end
57
- end
58
46
  end
@@ -1,4 +1,4 @@
1
- <% title ||= "" %>
1
+ <% title = local_assigns[:title] || content_for(:overlay_title) %>
2
2
 
3
3
  <div class="overlay" style="height:100vh;background-color:rgba(107, 114, 128, 0.5);justify-content:center;align-items:center;width: 100vw;display:flex;z-index:50;left:0px;top:0px;position:fixed;box-sizing:border-box;border-width:0px;border-style:solid;border-color:rgb(229, 231, 235);">
4
4
  <div style="width: 50%;justify-content:center;align-items:center;flex-direction:column;max-width:672px;height:662.398px;display:flex;box-sizing:border-box;border-width:0px;border-style:solid;border-color:rgb(229, 231, 235);">
@@ -1,4 +1,4 @@
1
- <% title ||= "" %>
1
+ <% title = local_assigns[:title] || content_for(:overlay_title) %>
2
2
 
3
3
  <div class="overlay fixed top-0 left-0 z-50 flex justify-center w-screen h-screen-safe items-center bg-gray-500 bg-opacity-50">
4
4
  <div class="w-11/12 sm:w-5/6 lg:w-1/2 max-w-2xl h-[90vh] flex flex-col justify-center items-center">
@@ -1,3 +1,3 @@
1
1
  module Overlastic
2
- VERSION = "0.10.2"
2
+ VERSION = "0.12.0"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: overlastic
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.10.2
4
+ version: 0.12.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Martin Zamuner
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2022-11-04 00:00:00.000000000 Z
11
+ date: 2026-02-23 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: actionpack
@@ -104,7 +104,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
104
104
  - !ruby/object:Gem::Version
105
105
  version: '0'
106
106
  requirements: []
107
- rubygems_version: 3.2.22
107
+ rubygems_version: 3.5.16
108
108
  signing_key:
109
109
  specification_version: 4
110
110
  summary: Fantastically easy overlays using Hotwire. Bring your dialog modals and slide-out