ultimate_turbo_modal 1.1.1 → 1.1.2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 1149adbc9b8dd940af463061bdfc46d09d1071531a0f08d73538a41c2d44ef52
4
- data.tar.gz: d5ce0192c54ff6f731758515a9ed60f839315759b70e9ceaba57ce2847ed298f
3
+ metadata.gz: af46e6d6c899d0fcf8054272b157d5e0f286e183e9c0b15c4e3b883df629d4f4
4
+ data.tar.gz: 91a99b9b60ea2892b2c030027d073218b4d751dd155a0bb84420bc6e60db628e
5
5
  SHA512:
6
- metadata.gz: 07b07aa40ab5c4000a6c06fa1d3ed410f7bebc3d44c46a670371e8e1044a168167cdd8a402865d26e3314b18c2e013b451a542c45a2a42e33d19cc8ce7b31f82
7
- data.tar.gz: 5dc24349c452b9c7c8a9280d4f8dd8a0c36dd89efb261b5aa8ae6715f3921aab0e15a128e704ce2eb21f0a94158ba621ca7760289efc1df17fa7180a1e2cbc1f
6
+ metadata.gz: ccff10a4c4fee7a554c58632d9850507be533877333b0b8caadf2966fbc5244719f828fdb4507674668129c6bfebee1e7cb3e7a7fae5fc1b8238eae8fb5ea637
7
+ data.tar.gz: d636a2425ce101e4339cec01573e6a29aea861f36328bf4e6a8cd3513ccfe9a5979b4fa424fa69320a809ff94f80f4e28d3f39bbc7f6f6d6426217191fe9ea4c
data/CHANGELOG.md CHANGED
@@ -1,4 +1,10 @@
1
- ## [Unreleased]
1
+ ## [1.1.2] - 2023-11-01
2
+
3
+ - Added configuration block
4
+
5
+ ## [1.1.2] - 2023-10-31
6
+
7
+ - Bug fix
2
8
 
3
9
  ## [1.1.0] - 2023-10-31
4
10
 
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- ultimate_turbo_modal (1.1.1)
4
+ ultimate_turbo_modal (1.1.2)
5
5
  phlex-rails (>= 1.0, < 2.0)
6
6
  rails (>= 7)
7
7
  stimulus-rails
data/README.md CHANGED
@@ -6,7 +6,7 @@ UTMR aims to be the be-all and end-all of Turbo Modals. I believe it is the best
6
6
 
7
7
  Under the hood, it uses [Stimulus](https://stimulus.hotwired.dev), [Turbo](https://turbo.hotwired.dev/), [el-transition](https://github.com/mmccall10/el-transition), and optionally [Idiomorph](https://github.com/bigskysoftware/idiomorph).
8
8
 
9
- It currently ships in a two flavors: Tailwind CSS, and regular, vanilla CSS. It is easy to create your own to suit your needs such as vanilla CSS or any other CSS framework you may prefer. See `lib/ultimate_turbo_modal/flavors/vanilla.rb` for an example code.
9
+ It currently ships in a two flavors: Tailwind CSS, and regular, vanilla CSS. It is easy to create your own variant to suit your needs. See `lib/ultimate_turbo_modal/flavors/vanilla.rb` for an example code.
10
10
 
11
11
 
12
12
  &nbsp;
@@ -34,7 +34,7 @@ It currently ships in a two flavors: Tailwind CSS, and regular, vanilla CSS. It
34
34
  &nbsp;
35
35
  ## Demo
36
36
 
37
- A demo application can be found at https://github.com/cmer/ultimate_turbo_modal-demo. A video demo can be seen here: [https://youtu.be/eG5uWTH74NA](https://youtu.be/eG5uWTH74NA)
37
+ A demo application can be found at https://github.com/cmer/ultimate_turbo_modal-demo. A video demo can be seen here: [https://youtu.be/BVRDXLN1I78](https://youtu.be/BVRDXLN1I78).
38
38
 
39
39
 
40
40
  &nbsp;
@@ -59,10 +59,15 @@ A demo application can be found at https://github.com/cmer/ultimate_turbo_modal-
59
59
  <%= turbo_frame_tag "modal" %>
60
60
  ``````
61
61
 
62
- 4. Set your desired flavor at `app/config/initializers/modal.rb`. The default is `:tailwind`.
62
+ 4. Set your desired flavor and default configuration at `app/config/initializers/ultimate_turbo_modal.rb`.
63
63
 
64
64
  ```ruby
65
- UltimateTurboModal.flavor = :tailwind # or :vanilla
65
+ UltimateTurboModal.configure do |config|
66
+ config.flavor = :tailwind
67
+ config.padding = true
68
+ config.advance = true
69
+ config.close_button = true
70
+ end
66
71
  ```
67
72
 
68
73
  5. Register the Stimulus controller in `app/javascript/controllers/index.js` adding the following lines at the end.
@@ -72,7 +77,33 @@ import setupUltimateTurboModal from "ultimate_turbo_modal";
72
77
  setupUltimateTurboModal(application);
73
78
  ```
74
79
 
75
- 6. Optionally (but recommended), configure UTMR to use Idiomorph. See below for details.
80
+ 6. If using the Tailwind flavor, add the following to `tailwind.config.js`:
81
+
82
+ ```
83
+ // For npm/yarn
84
+ const { getUltimateTurboModalPath } = require('ultimate_turbo_modal/gemPath');
85
+
86
+ // If using Importmaps, use the following instead:
87
+ // const { execSync } = require('child_process');
88
+ //
89
+ // function getUltimateTurboModalPath() {
90
+ // const path = execSync('bundle show ultimate_turbo_modal').toString().trim();
91
+ // return `${path}/**/*.{erb,html,rb}`;
92
+ //}
93
+ ```
94
+
95
+ and then in the `content` section, add `getUltimateTurboModalPath()` as follow:
96
+
97
+ ```
98
+ content: [
99
+ './public/*.html',
100
+ './app/helpers/**/*.rb',
101
+ './app/javascript/**/*.js',
102
+ './app/views/**/*.{erb,haml,html,slim,rb}',
103
+ getUltimateTurboModalPath()
104
+ ```
105
+
106
+ 7. Optionally (but recommended), configure UTMR to use Idiomorph. See below for details.
76
107
 
77
108
  &nbsp;
78
109
  &nbsp;
@@ -1,29 +1,28 @@
1
1
  class UltimateTurboModal::Base < Phlex::HTML
2
- INCLUDES = %w[
3
- Turbo::FramesHelper
4
- Turbo::StreamsHelper
5
- Phlex::Rails::Helpers::ContentTag
6
- Phlex::Rails::Helpers::Routes
7
- Phlex::Rails::Helpers::Tag
8
- ].freeze
9
-
10
2
  # @param padding [Boolean] Whether to add padding around the modal content
11
3
  # @param close_button [Boolean] Whether to show a close button.
12
4
  # @param advance [Boolean] Whether to update the browser history when opening and closing the modal
13
5
  # @param advance_url [String] Override the URL to use when advancing the history
14
6
  # @param request [ActionDispatch::Request] The current Rails request object
15
- def initialize(padding: true, close_button: true, advance: true, request: nil)
7
+ def initialize(
8
+ padding: UltimateTurboModal.configuration.padding,
9
+ close_button: UltimateTurboModal.configuration.close_button,
10
+ advance: UltimateTurboModal.configuration.advance,
11
+ request: nil
12
+ )
16
13
  @padding = padding
17
14
  @close_button = close_button
18
- @advance = advance
19
- @advance_url = advance if advance && advance.is_a?(String)
15
+ @advance = !!advance
16
+ @advance_url = advance if advance.present? && advance.is_a?(String)
20
17
  @request = request
21
18
 
22
- self.class.include Turbo::FramesHelper
23
- self.class.include Turbo::StreamsHelper
24
- self.class.include Phlex::Rails::Helpers::ContentTag
25
- self.class.include Phlex::Rails::Helpers::Routes
26
- self.class.include Phlex::Rails::Helpers::Tag
19
+ unless self.class.include?(Turbo::FramesHelper)
20
+ self.class.include Turbo::FramesHelper
21
+ self.class.include Turbo::StreamsHelper
22
+ self.class.include Phlex::Rails::Helpers::ContentTag
23
+ self.class.include Phlex::Rails::Helpers::Routes
24
+ self.class.include Phlex::Rails::Helpers::Tag
25
+ end
27
26
  end
28
27
 
29
28
  def template(&)
@@ -71,16 +70,6 @@ class UltimateTurboModal::Base < Phlex::HTML
71
70
  @advance_url || request.original_url
72
71
  end
73
72
 
74
- def method_missing(method, *, &block)
75
- INCLUDES.each { |mod| include_if_defined(mod) }
76
-
77
- if self.class.method_defined?(method)
78
- send(method, *, &block)
79
- else
80
- super
81
- end
82
- end
83
-
84
73
  def include_if_defined(mod_str)
85
74
  if defined?(mod.constantize) && !self.class.included_modules.include?(mod.constantize)
86
75
  self.class.include mod.constantize
@@ -0,0 +1,50 @@
1
+ module UltimateTurboModal
2
+ class << self
3
+ attr_accessor :configuration
4
+ end
5
+
6
+ def self.configure
7
+ self.configuration ||= Configuration.new
8
+ yield(configuration) if block_given?
9
+ end
10
+
11
+ delegate :flavor, :flavor=, :close_button, :close_button=,
12
+ :advance, :advance=, :padding, :padding=, to: :configuration
13
+
14
+ class Configuration
15
+ attr_reader :flavor, :close_button, :advance, :padding
16
+
17
+ def initialize
18
+ @flavor = :tailwind
19
+ @close_button = true
20
+ @advance = true
21
+ @padding = true
22
+ end
23
+
24
+ def flavor=(flavor)
25
+ raise ArgumentError.new("Flavor must be a symbol.") unless flavor.is_a?(Symbol) || flavor.is_a?(String)
26
+ @flavor = flavor.to_sym
27
+ end
28
+
29
+ def close_button=(close_button)
30
+ raise ArgumentError.new("Close button must be a boolean.") unless [true, false].include?(close_button)
31
+ @close_button = close_button
32
+ end
33
+
34
+ def advance=(advance)
35
+ raise ArgumentError.new("Advance must be a boolean.") unless [true, false].include?(advance)
36
+ @advance = advance
37
+ end
38
+
39
+ def padding=(padding)
40
+ if [true, false].include?(padding) || padding.is_a?(String)
41
+ @padding = padding
42
+ else
43
+ raise ArgumentError.new("Padding must be a boolean or a String.")
44
+ end
45
+ end
46
+ end
47
+ end
48
+
49
+ # Make sure the configuration object is set up when the gem is loaded.
50
+ UltimateTurboModal.configure
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module UltimateTurboModal
4
- VERSION = "1.1.1"
4
+ VERSION = "1.1.2"
5
5
  end
@@ -1,6 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  require_relative "ultimate_turbo_modal/version"
4
+ require "ultimate_turbo_modal/configuration"
4
5
  require "ultimate_turbo_modal/railtie"
5
6
  require "ultimate_turbo_modal/base"
6
7
  Dir[File.join(__dir__, "ultimate_turbo_modal/flavors", "*.rb")].sort.each do |file|
@@ -10,8 +11,6 @@ end
10
11
  module UltimateTurboModal
11
12
  extend self
12
13
 
13
- DEFAULT_FLAVOR = :tailwind
14
-
15
14
  def new(**)
16
15
  modal_class.new(**)
17
16
  end
@@ -20,13 +19,5 @@ module UltimateTurboModal
20
19
  "UltimateTurboModal::Flavors::#{flavor.to_s.classify}".constantize
21
20
  end
22
21
 
23
- def flavor=(flavor)
24
- @flavor = flavor
25
- end
26
-
27
- def flavor
28
- defined?(@flavor) ? @flavor&.to_sym : DEFAULT_FLAVOR
29
- end
30
-
31
22
  class Error < StandardError; end
32
23
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ultimate_turbo_modal
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.1.1
4
+ version: 1.1.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Carl Mercier
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2023-11-01 00:00:00.000000000 Z
11
+ date: 2023-11-02 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: phlex-rails
@@ -92,6 +92,7 @@ files:
92
92
  - Rakefile
93
93
  - lib/ultimate_turbo_modal.rb
94
94
  - lib/ultimate_turbo_modal/base.rb
95
+ - lib/ultimate_turbo_modal/configuration.rb
95
96
  - lib/ultimate_turbo_modal/flavors/tailwind.rb
96
97
  - lib/ultimate_turbo_modal/flavors/vanilla.rb
97
98
  - lib/ultimate_turbo_modal/helpers/controller_helper.rb