voidable-hotwire 0.7.2 → 0.8.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 +4 -4
- data/README.md +39 -4
- data/app/views/devise/confirmations/new.html.erb +16 -14
- data/app/views/devise/passwords/edit.html.erb +19 -17
- data/app/views/devise/passwords/new.html.erb +15 -13
- data/app/views/devise/registrations/edit.html.erb +35 -30
- data/app/views/devise/registrations/new.html.erb +21 -19
- data/app/views/devise/sessions/new.html.erb +25 -23
- data/app/views/devise/shared/_error_messages.html.erb +8 -6
- data/app/views/devise/unlocks/new.html.erb +16 -14
- data/config/importmap.rb +11 -2
- data/lib/generators/voidable/install/install_generator.rb +62 -18
- data/lib/generators/voidable/install/templates/_settings_menu.html.erb +31 -29
- data/lib/generators/voidable/install/templates/application_sidebar.html.erb.tt +12 -5
- data/lib/generators/voidable/install/templates/application_topbar.html.erb.tt +12 -5
- data/lib/generators/voidable/install/templates/sidebar.html.erb.tt +12 -5
- data/lib/generators/voidable/install/templates/topbar.html.erb.tt +12 -5
- data/lib/generators/voidable/install/templates/voidable-layout-sidebar.css +2 -11
- data/lib/generators/voidable/install/templates/voidable-layout-topbar.css +0 -5
- data/lib/generators/voidable/install/templates/voidable-layout.js +16 -10
- data/lib/templates/erb/scaffold/_form.html.erb.tt +13 -9
- data/lib/templates/erb/scaffold/index.html.erb.tt +45 -33
- data/lib/voidable/hotwire/cdn.rb +49 -0
- data/lib/voidable/hotwire/dev.rb +27 -0
- data/lib/voidable/hotwire/helpers.rb +40 -14
- data/lib/voidable/hotwire/version.rb +4 -1
- data/lib/voidable/hotwire.rb +2 -0
- metadata +3 -1
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
require_relative "version"
|
|
2
|
+
|
|
3
|
+
module Voidable
|
|
4
|
+
module Hotwire
|
|
5
|
+
# CDN URLs for the npm packages this gem pins. All Voidable packages are
|
|
6
|
+
# released together at one version, so the pins are derived from the gem's
|
|
7
|
+
# own VERSION and never typed by hand. config/importmap.rb, the install
|
|
8
|
+
# generator and the layout templates all read from here.
|
|
9
|
+
module CDN
|
|
10
|
+
BASE = "https://cdn.jsdelivr.net/npm".freeze
|
|
11
|
+
|
|
12
|
+
# An unreleased checkout (VERSION 0.0.0, e.g. a path or git dependency)
|
|
13
|
+
# follows the latest published packages instead of a version that was
|
|
14
|
+
# never published.
|
|
15
|
+
NPM_VERSION = (VERSION == "0.0.0" ? "latest" : VERSION).freeze
|
|
16
|
+
|
|
17
|
+
UI_URL = "#{BASE}/@voidable/ui@#{NPM_VERSION}/+esm".freeze
|
|
18
|
+
UI_HOTWIRE_URL = "#{BASE}/@voidable/ui-hotwire@#{NPM_VERSION}/dist/index.js".freeze
|
|
19
|
+
THEME_CSS_URL = "#{BASE}/@voidable/theme@#{NPM_VERSION}/dist/void.min.css".freeze
|
|
20
|
+
|
|
21
|
+
# The autoloader (@voidable/ui/autoloader) imports each component from a
|
|
22
|
+
# file next to it, so it is pinned as the raw dist file, not as a +esm
|
|
23
|
+
# bundle (jsDelivr would bundle a private copy of the shared base code
|
|
24
|
+
# into every component). Raw files import `lit` by bare name, so lit's
|
|
25
|
+
# three entry points are pinned too, to the same +esm URLs the +esm
|
|
26
|
+
# bundle of @voidable/ui itself uses.
|
|
27
|
+
# Development warnings (@voidable/ui/dev): one self-contained file with no
|
|
28
|
+
# imports, so the raw dist file works as a pin. Only ever imported in
|
|
29
|
+
# development (see Helpers#voidable_dev_tags). Pinned to the gem's own
|
|
30
|
+
# release only: an unreleased checkout has no published file to point at
|
|
31
|
+
# (the latest release may predate it), so it gets no pin, and
|
|
32
|
+
# voidable_dev_tags renders nothing until the app pins its own copy.
|
|
33
|
+
UI_DEV_URL = (VERSION == "0.0.0" ? nil : "#{BASE}/@voidable/ui@#{VERSION}/dist/dev.js").freeze
|
|
34
|
+
|
|
35
|
+
UI_AUTOLOADER_URL = "#{BASE}/@voidable/ui@#{NPM_VERSION}/dist/autoloader.js".freeze
|
|
36
|
+
LIT_URL = "#{BASE}/lit@3/+esm".freeze
|
|
37
|
+
LIT_DECORATORS_URL = "#{BASE}/lit@3/decorators.js/+esm".freeze
|
|
38
|
+
LIT_DIRECTIVES_LIVE_URL = "#{BASE}/lit@3/directives/live.js/+esm".freeze
|
|
39
|
+
|
|
40
|
+
# Import map entries for the autoloader setup, in pin order.
|
|
41
|
+
AUTOLOADER_PINS = {
|
|
42
|
+
"@voidable/ui/autoloader" => UI_AUTOLOADER_URL,
|
|
43
|
+
"lit" => LIT_URL,
|
|
44
|
+
"lit/decorators.js" => LIT_DECORATORS_URL,
|
|
45
|
+
"lit/directives/live.js" => LIT_DIRECTIVES_LIVE_URL
|
|
46
|
+
}.freeze
|
|
47
|
+
end
|
|
48
|
+
end
|
|
49
|
+
end
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
module Voidable
|
|
2
|
+
module Hotwire
|
|
3
|
+
# Development warnings: @voidable/ui/dev logs misused attributes, values and
|
|
4
|
+
# children to the browser console (see https://voidable.dev/getting-started/development-warnings/).
|
|
5
|
+
#
|
|
6
|
+
# On in the development environment only; the production page never loads
|
|
7
|
+
# the file. Set it in config/initializers/voidable.rb:
|
|
8
|
+
#
|
|
9
|
+
# Voidable::Hotwire.dev_warnings = false # off everywhere
|
|
10
|
+
# Voidable::Hotwire.dev_warnings = true # on, even outside development
|
|
11
|
+
# Voidable::Hotwire.dev_warnings = :throw # thrown errors, for system tests
|
|
12
|
+
class << self
|
|
13
|
+
attr_writer :dev_warnings
|
|
14
|
+
|
|
15
|
+
# false, true or :throw.
|
|
16
|
+
def dev_warnings
|
|
17
|
+
return @dev_warnings unless @dev_warnings.nil?
|
|
18
|
+
|
|
19
|
+
defined?(::Rails) && ::Rails.respond_to?(:env) && ::Rails.env.development? ? true : false
|
|
20
|
+
end
|
|
21
|
+
|
|
22
|
+
def dev_warnings?
|
|
23
|
+
!!dev_warnings
|
|
24
|
+
end
|
|
25
|
+
end
|
|
26
|
+
end
|
|
27
|
+
end
|
|
@@ -1,24 +1,50 @@
|
|
|
1
1
|
module Voidable
|
|
2
2
|
module Hotwire
|
|
3
3
|
module Helpers
|
|
4
|
-
# Generates data
|
|
4
|
+
# Generates the Stimulus `data-action` attribute that wires Voidable
|
|
5
|
+
# component events to a controller action. Stimulus handles custom events
|
|
6
|
+
# natively, so no bridging controller is required.
|
|
5
7
|
#
|
|
6
8
|
# void_attrs("void-click", "form#submit")
|
|
7
|
-
# # => {
|
|
8
|
-
# # action: "void-click->form#submit" }
|
|
9
|
+
# # => { data: { action: "void-click->form#submit" } }
|
|
9
10
|
#
|
|
11
|
+
# void_attrs(["void-click", "void-change"], "form#update")
|
|
12
|
+
# # => { data: { action: "void-click->form#update void-change->form#update" } }
|
|
13
|
+
#
|
|
14
|
+
# Without an action no attributes are generated.
|
|
10
15
|
def void_attrs(events, action = nil)
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
16
|
+
return { data: {} } unless action
|
|
17
|
+
|
|
18
|
+
{ data: { action: Array(events).map { |e| "#{e}->#{action}" }.join(" ") } }
|
|
19
|
+
end
|
|
20
|
+
|
|
21
|
+
# Loads the development warnings (@voidable/ui/dev) for importmap apps.
|
|
22
|
+
# Put it after `javascript_importmap_tags` in the layout head. It renders
|
|
23
|
+
# nothing unless Voidable::Hotwire.dev_warnings is on, which by default is
|
|
24
|
+
# the development environment only, so a production page never loads or
|
|
25
|
+
# mentions the file. With Vite the generated application.js imports it
|
|
26
|
+
# under `import.meta.env.DEV` instead and this helper is not needed.
|
|
27
|
+
#
|
|
28
|
+
# `Voidable::Hotwire.dev_warnings = :throw` turns warnings into thrown
|
|
29
|
+
# errors, for system tests that fail on console errors.
|
|
30
|
+
#
|
|
31
|
+
# It also renders nothing when the import map has no `@voidable/ui/dev`
|
|
32
|
+
# pin (an unreleased gem checkout pins none), rather than importing a
|
|
33
|
+
# name the browser cannot resolve.
|
|
34
|
+
def voidable_dev_tags
|
|
35
|
+
return "".html_safe unless Voidable::Hotwire.dev_warnings?
|
|
36
|
+
return "".html_safe unless voidable_dev_pinned?
|
|
37
|
+
|
|
38
|
+
config = Voidable::Hotwire.dev_warnings == :throw ? %(<script>window.VOIDABLE_DEV = { throw: true };</script>\n).html_safe : "".html_safe
|
|
39
|
+
config + javascript_import_module_tag("@voidable/ui/dev")
|
|
40
|
+
end
|
|
41
|
+
|
|
42
|
+
private
|
|
43
|
+
|
|
44
|
+
def voidable_dev_pinned?
|
|
45
|
+
return true unless defined?(Rails) && Rails.application.respond_to?(:importmap)
|
|
46
|
+
|
|
47
|
+
Rails.application.importmap.packages.key?("@voidable/ui/dev")
|
|
22
48
|
end
|
|
23
49
|
end
|
|
24
50
|
end
|
|
@@ -1,5 +1,8 @@
|
|
|
1
1
|
module Voidable
|
|
2
2
|
module Hotwire
|
|
3
|
-
|
|
3
|
+
# Every Voidable package shares one version number. The repository keeps
|
|
4
|
+
# 0.0.0 here; the release workflow stamps the released version into its
|
|
5
|
+
# checkout before `gem build` (scripts/release/stamp.mjs). Do not edit.
|
|
6
|
+
VERSION = "0.8.0"
|
|
4
7
|
end
|
|
5
8
|
end
|
data/lib/voidable/hotwire.rb
CHANGED
metadata
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: voidable-hotwire
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.
|
|
4
|
+
version: 0.8.0
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Kaz Walker
|
|
@@ -65,6 +65,8 @@ files:
|
|
|
65
65
|
- lib/templates/erb/scaffold/show.html.erb.tt
|
|
66
66
|
- lib/templates/rails/scaffold_controller/controller.rb.tt
|
|
67
67
|
- lib/voidable/hotwire.rb
|
|
68
|
+
- lib/voidable/hotwire/cdn.rb
|
|
69
|
+
- lib/voidable/hotwire/dev.rb
|
|
68
70
|
- lib/voidable/hotwire/engine.rb
|
|
69
71
|
- lib/voidable/hotwire/helpers.rb
|
|
70
72
|
- lib/voidable/hotwire/version.rb
|