bootstrap5-rails-extensions 0.1.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 +7 -0
- data/.gitignore +15 -0
- data/Gemfile +7 -0
- data/Gemfile.lock +221 -0
- data/LICENSE.txt +21 -0
- data/README.md +192 -0
- data/Rakefile +6 -0
- data/app/helpers/bootstrap5_rails_extensions/card_helper.rb +143 -0
- data/app/helpers/bootstrap5_rails_extensions/modal_helper.rb +227 -0
- data/app/helpers/bootstrap5_rails_extensions/offcanvas_helper.rb +67 -0
- data/app/helpers/bootstrap5_rails_extensions/table_helper.rb +93 -0
- data/app/helpers/bootstrap5_rails_extensions/toast_helper.rb +33 -0
- data/app/javascript/bootstrap5_rails_extensions/modal_controller.js +88 -0
- data/app/javascript/bootstrap5_rails_extensions/offcanvas_controller.js +62 -0
- data/app/javascript/bootstrap5_rails_extensions/toast_controller.js +31 -0
- data/app/views/bootstrap5_rails_extensions/_modal.html.erb +6 -0
- data/app/views/bootstrap5_rails_extensions/_offcanvas.html.erb +15 -0
- data/app/views/bootstrap5_rails_extensions/_toast.html.erb +15 -0
- data/bin/console +12 -0
- data/bin/setup +8 -0
- data/bootstrap5_rails_extensions.gemspec +46 -0
- data/lib/bootstrap5/rails/extensions.rb +3 -0
- data/lib/bootstrap5_rails_extensions/engine.rb +32 -0
- data/lib/bootstrap5_rails_extensions/turbo_stream_toast.rb +42 -0
- data/lib/bootstrap5_rails_extensions/version.rb +5 -0
- data/lib/bootstrap5_rails_extensions.rb +5 -0
- metadata +83 -0
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require_relative "lib/bootstrap5_rails_extensions/version"
|
|
4
|
+
|
|
5
|
+
Gem::Specification.new do |spec|
|
|
6
|
+
spec.name = "bootstrap5-rails-extensions"
|
|
7
|
+
spec.version = Bootstrap5RailsExtensions::VERSION
|
|
8
|
+
spec.authors = ["Dreaw Inc."]
|
|
9
|
+
spec.email = ["kodani@dreaw.jp"]
|
|
10
|
+
|
|
11
|
+
spec.summary = "Bootstrap 5 extensions for Rails (Stimulus/Turbo friendly)"
|
|
12
|
+
spec.description = "Rails Engine offering Bootstrap 5 extensions. Includes a render_modal helper and a shared modal partial, designed to work smoothly with Stimulus and Turbo."
|
|
13
|
+
spec.homepage = "https://dreaw.jp"
|
|
14
|
+
spec.license = "MIT"
|
|
15
|
+
spec.required_ruby_version = ">= 3.1.0"
|
|
16
|
+
|
|
17
|
+
spec.metadata["homepage_uri"] = spec.homepage
|
|
18
|
+
spec.metadata["source_code_uri"] = spec.homepage
|
|
19
|
+
spec.metadata["rubygems_mfa_required"] = "true"
|
|
20
|
+
|
|
21
|
+
tracked_files = IO.popen(%w[git ls-files -z], chdir: __dir__, err: IO::NULL) do |ls|
|
|
22
|
+
ls.readlines("\x0", chomp: true)
|
|
23
|
+
end
|
|
24
|
+
|
|
25
|
+
spec.files = if tracked_files&.any?
|
|
26
|
+
tracked_files.reject do |path|
|
|
27
|
+
path.start_with?("AGENTS.md", "CLAUDE.md", "pkg/")
|
|
28
|
+
end.select do |path|
|
|
29
|
+
File.file?(File.expand_path(path, __dir__))
|
|
30
|
+
end
|
|
31
|
+
else
|
|
32
|
+
Dir.chdir(__dir__) do
|
|
33
|
+
Dir[
|
|
34
|
+
"{app,config,lib,bin}/**/*",
|
|
35
|
+
"README.md",
|
|
36
|
+
"LICENSE.txt",
|
|
37
|
+
"Rakefile",
|
|
38
|
+
"Gemfile"
|
|
39
|
+
].select { |path| File.file?(path) }
|
|
40
|
+
end
|
|
41
|
+
end
|
|
42
|
+
|
|
43
|
+
spec.require_paths = ["lib"]
|
|
44
|
+
|
|
45
|
+
spec.add_dependency "rails", ">= 8.0"
|
|
46
|
+
end
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
module Bootstrap5RailsExtensions
|
|
2
|
+
class Engine < ::Rails::Engine
|
|
3
|
+
isolate_namespace Bootstrap5RailsExtensions
|
|
4
|
+
|
|
5
|
+
initializer "bootstrap5_rails_extensions.helper" do
|
|
6
|
+
ActiveSupport.on_load(:action_view) do
|
|
7
|
+
require_relative "../../app/helpers/bootstrap5_rails_extensions/modal_helper"
|
|
8
|
+
require_relative "../../app/helpers/bootstrap5_rails_extensions/card_helper"
|
|
9
|
+
require_relative "../../app/helpers/bootstrap5_rails_extensions/offcanvas_helper"
|
|
10
|
+
require_relative "../../app/helpers/bootstrap5_rails_extensions/toast_helper"
|
|
11
|
+
require_relative "../../app/helpers/bootstrap5_rails_extensions/table_helper"
|
|
12
|
+
include Bootstrap5RailsExtensions::ModalHelper
|
|
13
|
+
include Bootstrap5RailsExtensions::CardHelper
|
|
14
|
+
include Bootstrap5RailsExtensions::OffcanvasHelper
|
|
15
|
+
include Bootstrap5RailsExtensions::ToastHelper
|
|
16
|
+
include Bootstrap5RailsExtensions::TableHelper
|
|
17
|
+
# turbo_stream.toast(...) を追加
|
|
18
|
+
begin
|
|
19
|
+
require "turbo/streams/tag_builder"
|
|
20
|
+
rescue LoadError
|
|
21
|
+
end
|
|
22
|
+
if defined?(Turbo::Streams::TagBuilder)
|
|
23
|
+
require_relative "turbo_stream_toast"
|
|
24
|
+
Turbo::Streams::TagBuilder.include Bootstrap5RailsExtensions::TurboStreamToast
|
|
25
|
+
end
|
|
26
|
+
end
|
|
27
|
+
ActiveSupport.on_load(:action_controller_base) do
|
|
28
|
+
include Bootstrap5RailsExtensions::ToastHelper
|
|
29
|
+
end
|
|
30
|
+
end
|
|
31
|
+
end
|
|
32
|
+
end
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
module Bootstrap5RailsExtensions
|
|
2
|
+
# Turbo::Streams::TagBuilder へ toast(level, text, ...) を追加する拡張
|
|
3
|
+
#
|
|
4
|
+
# 使い方(コントローラ/ビュー共通):
|
|
5
|
+
# render turbo_stream: turbo_stream.toast(:notice, "保存しました")
|
|
6
|
+
# render turbo_stream: [ turbo_stream.replace(@record), turbo_stream.toast(:alert, "エラー", autohide: false) ]
|
|
7
|
+
module TurboStreamToast
|
|
8
|
+
# トーストを右上コンテナに積む
|
|
9
|
+
# level: :notice | :alert | :error | :warning | :info
|
|
10
|
+
def toast(level, message_or_record, target: "toast-root", autohide: true, delay: 4000)
|
|
11
|
+
color = case level.to_sym
|
|
12
|
+
when :notice then :success
|
|
13
|
+
when :alert, :error then :danger
|
|
14
|
+
when :warning then :warning
|
|
15
|
+
when :info then :info
|
|
16
|
+
else :secondary
|
|
17
|
+
end
|
|
18
|
+
text = normalize_toast_text(message_or_record)
|
|
19
|
+
html = @view_context.render(partial: "bootstrap5_rails_extensions/toast",
|
|
20
|
+
locals: { msg: { text: text, color: color }, autohide: autohide, delay: delay })
|
|
21
|
+
append(target, html)
|
|
22
|
+
end
|
|
23
|
+
|
|
24
|
+
private
|
|
25
|
+
|
|
26
|
+
def normalize_toast_text(value)
|
|
27
|
+
return value if value.is_a?(ActiveSupport::SafeBuffer)
|
|
28
|
+
return value if value.is_a?(String) || value.nil?
|
|
29
|
+
|
|
30
|
+
if value.respond_to?(:errors)
|
|
31
|
+
errors = value.errors
|
|
32
|
+
if errors.respond_to?(:any?) && errors.any?
|
|
33
|
+
items = errors.full_messages.map { |message| @view_context.content_tag(:li, message) }
|
|
34
|
+
return @view_context.content_tag(:ul, @view_context.safe_join(items), class: "mb-0 ps-4")
|
|
35
|
+
end
|
|
36
|
+
end
|
|
37
|
+
|
|
38
|
+
value
|
|
39
|
+
end
|
|
40
|
+
end
|
|
41
|
+
end
|
|
42
|
+
|
metadata
ADDED
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
|
2
|
+
name: bootstrap5-rails-extensions
|
|
3
|
+
version: !ruby/object:Gem::Version
|
|
4
|
+
version: 0.1.0
|
|
5
|
+
platform: ruby
|
|
6
|
+
authors:
|
|
7
|
+
- Dreaw Inc.
|
|
8
|
+
bindir: bin
|
|
9
|
+
cert_chain: []
|
|
10
|
+
date: 1980-01-02 00:00:00.000000000 Z
|
|
11
|
+
dependencies:
|
|
12
|
+
- !ruby/object:Gem::Dependency
|
|
13
|
+
name: rails
|
|
14
|
+
requirement: !ruby/object:Gem::Requirement
|
|
15
|
+
requirements:
|
|
16
|
+
- - ">="
|
|
17
|
+
- !ruby/object:Gem::Version
|
|
18
|
+
version: '8.0'
|
|
19
|
+
type: :runtime
|
|
20
|
+
prerelease: false
|
|
21
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
22
|
+
requirements:
|
|
23
|
+
- - ">="
|
|
24
|
+
- !ruby/object:Gem::Version
|
|
25
|
+
version: '8.0'
|
|
26
|
+
description: Rails Engine offering Bootstrap 5 extensions. Includes a render_modal
|
|
27
|
+
helper and a shared modal partial, designed to work smoothly with Stimulus and Turbo.
|
|
28
|
+
email:
|
|
29
|
+
- kodani@dreaw.jp
|
|
30
|
+
executables: []
|
|
31
|
+
extensions: []
|
|
32
|
+
extra_rdoc_files: []
|
|
33
|
+
files:
|
|
34
|
+
- ".gitignore"
|
|
35
|
+
- Gemfile
|
|
36
|
+
- Gemfile.lock
|
|
37
|
+
- LICENSE.txt
|
|
38
|
+
- README.md
|
|
39
|
+
- Rakefile
|
|
40
|
+
- app/helpers/bootstrap5_rails_extensions/card_helper.rb
|
|
41
|
+
- app/helpers/bootstrap5_rails_extensions/modal_helper.rb
|
|
42
|
+
- app/helpers/bootstrap5_rails_extensions/offcanvas_helper.rb
|
|
43
|
+
- app/helpers/bootstrap5_rails_extensions/table_helper.rb
|
|
44
|
+
- app/helpers/bootstrap5_rails_extensions/toast_helper.rb
|
|
45
|
+
- app/javascript/bootstrap5_rails_extensions/modal_controller.js
|
|
46
|
+
- app/javascript/bootstrap5_rails_extensions/offcanvas_controller.js
|
|
47
|
+
- app/javascript/bootstrap5_rails_extensions/toast_controller.js
|
|
48
|
+
- app/views/bootstrap5_rails_extensions/_modal.html.erb
|
|
49
|
+
- app/views/bootstrap5_rails_extensions/_offcanvas.html.erb
|
|
50
|
+
- app/views/bootstrap5_rails_extensions/_toast.html.erb
|
|
51
|
+
- bin/console
|
|
52
|
+
- bin/setup
|
|
53
|
+
- bootstrap5_rails_extensions.gemspec
|
|
54
|
+
- lib/bootstrap5/rails/extensions.rb
|
|
55
|
+
- lib/bootstrap5_rails_extensions.rb
|
|
56
|
+
- lib/bootstrap5_rails_extensions/engine.rb
|
|
57
|
+
- lib/bootstrap5_rails_extensions/turbo_stream_toast.rb
|
|
58
|
+
- lib/bootstrap5_rails_extensions/version.rb
|
|
59
|
+
homepage: https://dreaw.jp
|
|
60
|
+
licenses:
|
|
61
|
+
- MIT
|
|
62
|
+
metadata:
|
|
63
|
+
homepage_uri: https://dreaw.jp
|
|
64
|
+
source_code_uri: https://dreaw.jp
|
|
65
|
+
rubygems_mfa_required: 'true'
|
|
66
|
+
rdoc_options: []
|
|
67
|
+
require_paths:
|
|
68
|
+
- lib
|
|
69
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
|
70
|
+
requirements:
|
|
71
|
+
- - ">="
|
|
72
|
+
- !ruby/object:Gem::Version
|
|
73
|
+
version: 3.1.0
|
|
74
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
|
75
|
+
requirements:
|
|
76
|
+
- - ">="
|
|
77
|
+
- !ruby/object:Gem::Version
|
|
78
|
+
version: '0'
|
|
79
|
+
requirements: []
|
|
80
|
+
rubygems_version: 3.6.7
|
|
81
|
+
specification_version: 4
|
|
82
|
+
summary: Bootstrap 5 extensions for Rails (Stimulus/Turbo friendly)
|
|
83
|
+
test_files: []
|