overlastic 0.11.0 → 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: 43db3c1020ad55f7f3e3583c87619fb3cd108ae75c24aee4d00047981faa6fa5
4
- data.tar.gz: cda4c45a9ba38585749bfdd34f1d457628e6f4efeb4af30ea257a501fcf653a2
3
+ metadata.gz: b9564bcaf740459d550f4e7f0195cf4f1b1a4eb1da38dac702d71e6fcc1d972d
4
+ data.tar.gz: 1c5f9f6ef8eb8cac4beff8406e8d743332e3390961bb56f55d93204fdfc5ec7b
5
5
  SHA512:
6
- metadata.gz: 6991e4bf107dcb88b60623d8dc6ba7b7cbabc42b26a33d834196bb6d85f276fe2df13ce61c7f2bfe8f02537ab2bb9e1b1bc87d0ba3f05fea06890d9ee862ab62
7
- data.tar.gz: 75195d9d488ddba1253fa5406f0b89d50836070cb68327f3c046a4bb5828eafe40af165b8b1e2741de5eb3659bb0f751f761ada2d39f250596e3ade4d1cf32d1
6
+ metadata.gz: 4c571017098b4cdecdfd8de6f8a28d9a2a8a4caaafdb31f656d3e6d83dc75d7efd09eb3f8d32002527607fe1e93c4304be123e34f7477f1cba0da9502d6adae2
7
+ data.tar.gz: fbd47da78e6fa186bcc6c55b8c58f24f07ae3db642191d3e004a91346919eaaece39f4727519db12e5b2f606af9d86a7470673a6a0285aec2248003eee5043d9
data/README.md CHANGED
@@ -13,7 +13,7 @@
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>
@@ -40,13 +40,13 @@ module Overlastic::Concerns::OverlayHandling
40
40
  if block_given? || options[:html]
41
41
  stream_response = turbo_stream.replace_overlay(overlay_name, html: render_to_string(*args, **options, &block))
42
42
  else
43
- 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))
44
44
  end
45
45
  elsif request.variant.overlay?
46
46
  if initiator || error || target != "_top"
47
47
  options[:layout] = false
48
48
 
49
- 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))
50
50
  else
51
51
  request.headers["Overlay-Name"] = nil
52
52
  request.variant.delete :overlay
@@ -65,6 +65,20 @@ module Overlastic::Concerns::OverlayHandling
65
65
  end
66
66
  end
67
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
+
68
82
  # Based on https://github.com/hotwired/turbo-rails/pull/367
69
83
  # by seanpdoyle
70
84
  def redirect_to(options = {}, response_options = {})
@@ -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.11.0"
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.11.0
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: 2023-10-10 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.4.10
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