stomp_base 0.2.0 → 0.2.1

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: 432af31faec38b086abee4fa9d32c0e1bd9ef3ccc15671a89f9e3edbf1fa5046
4
- data.tar.gz: 41c7d84e8ebb7db6dc7283af52a2a2b34f3eced03fc0d50adb941eb99eb9a623
3
+ metadata.gz: f766bad393da3ae69fa86a14e37ddd0757eb933c47b209b2ece04e2bc17ad7f0
4
+ data.tar.gz: cd1caea93843548baba429391a50b4cfac2852b0be1c5ff4534f38317df35c63
5
5
  SHA512:
6
- metadata.gz: bf0f56a08d45a7044bd93efa8eb6389687b1984d0c5993e2e00808481ddda350e79460849982b20d5fc866e7c8915a3a8117c1c6ab614ff22b3fe0cf4af751ba
7
- data.tar.gz: c01073b6cf496092b6fcda82ee5de049084d4f7ba79e542431147ed72a2a472bb507bad835dbe914ec4644955d4c10eb6bba0cc386eb7e05a123bd0abaf63e1b
6
+ metadata.gz: 4358c4e43a782e99b8c13d31ae7f00e3124b70a0db5ccb3c804cbebc68ac5b09960eaa22b6c388420e8dd9caeba08f0bc9d3390cc8b783ad4c7e43daf65558b9
7
+ data.tar.gz: 764692e137d6292629990b71f87a6e8952161a96fad790d0fe6ebbbdeae3e9133bfe7fe493e85d127956898f2c5aa30e5abd9a2ea7bb4208a4979b27131fb27e
data/CHANGELOG.md CHANGED
@@ -7,17 +7,29 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
7
7
 
8
8
  ## [Unreleased]
9
9
 
10
+ ## [0.2.1] - 2025-06-28
11
+
12
+ ### Added
13
+ - **API-only Rails Support**: Automatic compatibility for API-only Rails applications
14
+ - Auto-configure necessary middleware (session, cookies, flash, method override)
15
+ - Automatic session store configuration for API-only applications
16
+ - No manual middleware configuration required in host applications
17
+ - **Japanese Documentation**: Complete Japanese translation of README.md (README.ja.md)
18
+ - **Rails Demo API**: Complete API-only Rails demonstration application
19
+ - Sample models, migrations, and authentication specifications
20
+ - Proper bin/ directory with Rails binstubs
21
+ - Complete environment configurations
22
+
10
23
  ### Changed
11
- - **Test Structure**: Updated test helper file structure for better separation of concerns
12
- - Moved configuration tests to `spec/unit/configuration_spec.rb`
13
- - Updated `spec_helper.rb` for pure Ruby logic tests only
14
- - Deprecated main `spec/rails_helper.rb` with automatic redirection to appropriate helpers
15
- - Rails-based tests now use `spec/rails_demo/spec/rails_helper.rb`
16
- - **Configuration**: Fixed duplicate `disable_authentication` method in Configuration class
24
+ - **Settings Controller**: Improved settings save functionality with proper flash message handling
25
+ - **Application Controller**: Simplified to use Rails standard flash functionality
26
+ - **Routes**: Added POST route support for settings form submission
27
+ - **Documentation**: Added cross-language links between README files
17
28
 
18
29
  ### Fixed
19
- - Removed duplicate method definitions in `StompBase::Configuration`
20
- - Updated test helper references for consistency
30
+ - **RuboCop Issues**: Fixed RuboCop execution and code style issues
31
+ - **CSS Assets**: Resolved CSS asset loading issues in API-only Rails applications
32
+ - **Error Handling**: Improved error handling and logging for middleware setup
21
33
 
22
34
  ## [0.2.0] - 2025-05-28
23
35
 
@@ -71,5 +83,6 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
71
83
  - 🔧 Easy Integration: Simple gem installation and mounting process
72
84
  - 🔐 Built-in Authentication: Simple authentication options (Basic Auth, API keys, Custom)
73
85
 
86
+ [0.2.1]: https://github.com/snowwshiro/stomp_base/releases/tag/v0.2.1
74
87
  [0.2.0]: https://github.com/snowwshiro/stomp_base/releases/tag/v0.2.0
75
88
  [0.1.0]: https://github.com/snowwshiro/stomp_base/releases/tag/v0.1.0
data/README.md CHANGED
@@ -1,5 +1,7 @@
1
1
  # 🎛️ Stomp Base
2
2
 
3
+ [ja README](./README.ja.md)
4
+
3
5
  [![CI](https://github.com/snowwshiro/stomp_base/workflows/CI/badge.svg)](https://github.com/snowwshiro/stomp_base/actions/workflows/ci.yml)
4
6
  [![Code Quality](https://github.com/snowwshiro/stomp_base/workflows/Code%20Quality/badge.svg)](https://github.com/snowwshiro/stomp_base/actions/workflows/code-quality.yml)
5
7
  [![Coverage](https://github.com/snowwshiro/stomp_base/workflows/Coverage/badge.svg)](https://github.com/snowwshiro/stomp_base/actions/workflows/coverage.yml)
@@ -59,6 +61,30 @@ end
59
61
  2. **Install View Component** (automatically included as dependency):
60
62
  The gem includes View Component as a dependency, so no additional setup is required.
61
63
 
64
+ ### API-Only Rails Applications
65
+
66
+ StompBase automatically works with API-only Rails applications! The engine detects when the asset pipeline is not available and configures static asset serving automatically.
67
+
68
+ **No additional configuration needed** - StompBase will:
69
+ - Detect API-only mode (`config.api_only = true`)
70
+ - Automatically serve CSS assets via `ActionDispatch::Static` middleware
71
+ - Display helpful warnings if public file server is disabled
72
+
73
+ If you encounter styling issues in an API-only app, ensure public file server is enabled:
74
+
75
+ ```ruby
76
+ # config/application.rb or config/environments/development.rb
77
+ config.public_file_server.enabled = true
78
+ ```
79
+
80
+ Alternatively, you can enable ActionView and the asset pipeline:
81
+
82
+ ```ruby
83
+ # config/application.rb
84
+ require "action_view/railtie"
85
+ # Remove or comment out: config.api_only = true
86
+ ```
87
+
62
88
  ## Usage
63
89
 
64
90
  ### Accessing the Dashboard
@@ -2,6 +2,10 @@
2
2
 
3
3
  module StompBase
4
4
  class ApplicationController < ActionController::Base
5
+ # Include necessary modules for API-only compatibility
6
+ include ActionController::Cookies
7
+ include ActionController::Flash unless included_modules.include?(ActionController::Flash)
8
+
5
9
  include StompBase::I18nHelper
6
10
  include StompBase::Authentication
7
11
 
@@ -14,7 +14,7 @@ module StompBase
14
14
 
15
15
  update_theme_setting(params[:theme]) if params[:theme]
16
16
 
17
- redirect_back(fallback_location: stomp_base.root_path, notice: t("stomp_base.settings.settings_updated"))
17
+ safe_redirect_with_notice(t("stomp_base.settings.settings_updated"))
18
18
  end
19
19
 
20
20
  def update_locale
@@ -43,7 +43,7 @@ module StompBase
43
43
  respond_to do |format|
44
44
  format.json { render json: { status: "success", locale: locale } }
45
45
  format.html do
46
- redirect_back(fallback_location: stomp_base.root_path, notice: t("stomp_base.settings.settings_updated"))
46
+ safe_redirect_with_notice(t("stomp_base.settings.settings_updated"))
47
47
  end
48
48
  end
49
49
  end
@@ -55,7 +55,7 @@ module StompBase
55
55
  status: :unprocessable_entity
56
56
  end
57
57
  format.html do
58
- redirect_back(fallback_location: stomp_base.root_path, alert: t("stomp_base.settings.invalid_locale"))
58
+ safe_redirect_with_alert(t("stomp_base.settings.invalid_locale"))
59
59
  end
60
60
  end
61
61
  end
@@ -75,5 +75,15 @@ module StompBase
75
75
 
76
76
  session[:stomp_base_theme] = theme
77
77
  end
78
+
79
+ def safe_redirect_with_notice(message)
80
+ flash[:notice] = message
81
+ redirect_back(fallback_location: stomp_base.root_path)
82
+ end
83
+
84
+ def safe_redirect_with_alert(message)
85
+ flash[:alert] = message
86
+ redirect_back(fallback_location: stomp_base.root_path)
87
+ end
78
88
  end
79
89
  end
data/config/routes.rb CHANGED
@@ -8,7 +8,9 @@ StompBase::Engine.routes.draw do
8
8
 
9
9
  get "settings", to: "settings#index"
10
10
  patch "settings", to: "settings#update"
11
+ post "settings", to: "settings#update"
11
12
  patch "settings/locale", to: "settings#update_locale", as: "update_locale"
13
+ post "settings/locale", to: "settings#update_locale"
12
14
 
13
15
  # Console routes
14
16
  get "console", to: "console#index"
@@ -15,14 +15,16 @@ module StompBase
15
15
  g.helper true
16
16
  end
17
17
 
18
- # Add asset paths for Rails 8 compatibility
19
- if defined?(Rails.application.config.assets)
20
- config.assets.paths << root.join("app", "assets", "javascripts")
21
- config.assets.paths << root.join("app", "assets", "stylesheets")
22
- config.assets.paths << root.join("app", "javascript")
18
+ # Add asset paths for Rails compatibility (when asset pipeline is available)
19
+ config.after_initialize do |app|
20
+ if app.config.respond_to?(:assets)
21
+ app.config.assets.paths << root.join("app", "assets", "javascripts")
22
+ app.config.assets.paths << root.join("app", "assets", "stylesheets")
23
+ app.config.assets.paths << root.join("app", "javascript")
23
24
 
24
- # CSS precompilation (JavaScript is managed by importmap)
25
- config.assets.precompile += %w[stomp_base/application.css stomp_base/base.css]
25
+ # CSS precompilation (JavaScript is managed by importmap)
26
+ app.config.assets.precompile += %w[stomp_base/application.css stomp_base/base.css]
27
+ end
26
28
  end
27
29
 
28
30
  # I18n configuration
@@ -36,5 +38,102 @@ module StompBase
36
38
  I18n.default_locale = StompBase.locale
37
39
  end
38
40
  end
41
+
42
+ # Configure static asset serving for API-only Rails applications
43
+ initializer "stomp_base.static_assets" do |app|
44
+ if self.class.should_serve_static_assets?(app.config)
45
+ app.middleware.use(
46
+ ::ActionDispatch::Static,
47
+ "#{root}/app/assets",
48
+ headers: {
49
+ "Cache-Control" => "public, max-age=31536000"
50
+ }
51
+ )
52
+ end
53
+ end
54
+
55
+ # Configuration validation for StompBase compatibility
56
+ initializer "stomp_base.validate_configuration" do |app|
57
+ app.config.after_initialize do
58
+ if app.config.api_only && !app.config.respond_to?(:assets)
59
+ Rails.logger.info "StompBase: Detected API-only Rails application without asset pipeline"
60
+
61
+ if app.config.public_file_server.enabled
62
+ Rails.logger.info "StompBase: Configured static asset serving for API-only mode"
63
+ else
64
+ Rails.logger.warn <<~WARNING
65
+ ⚠️ StompBase Warning: Your API-only Rails application has public file server disabled.
66
+ StompBase requires CSS assets to be served for proper UI functionality.
67
+
68
+ To fix this, add to your config/application.rb or config/environments/#{Rails.env}.rb:
69
+ config.public_file_server.enabled = true
70
+
71
+ Or enable ActionView and asset pipeline by uncommenting in config/application.rb:
72
+ require "action_view/railtie"
73
+ WARNING
74
+ end
75
+ end
76
+ end
77
+ end
78
+
79
+ # Configure middleware for API-only Rails applications
80
+ initializer "stomp_base.api_middleware", before: :build_middleware_stack do |app|
81
+ if app.config.api_only
82
+ Rails.logger.info "StompBase: Configuring middleware for API-only Rails application"
83
+
84
+ # Add necessary middleware for StompBase compatibility
85
+ required_middleware = [
86
+ [Rack::MethodOverride, []],
87
+ [ActionDispatch::Cookies, []],
88
+ [ActionDispatch::Session::CookieStore, []],
89
+ [ActionDispatch::Flash, []]
90
+ ]
91
+
92
+ required_middleware.each do |middleware_class, args|
93
+ app.config.middleware.use middleware_class, *args
94
+ Rails.logger.debug { "StompBase: Added #{middleware_class} middleware" }
95
+ rescue ArgumentError => e
96
+ # Middleware might already be present
97
+ Rails.logger.debug { "StompBase: #{middleware_class} middleware already present or error: #{e.message}" }
98
+ end
99
+
100
+ Rails.logger.info "StompBase: Middleware configuration completed"
101
+ end
102
+ end
103
+
104
+ # Configure session store for API-only Rails applications
105
+ initializer "stomp_base.session_store" do |app|
106
+ if app.config.api_only && !Rails.application.config.session_store
107
+ app.config.session_store :cookie_store, key: "_#{Rails.application.class.module_parent_name.underscore}_session"
108
+ Rails.logger.info "StompBase: Configured cookie session store for API-only application"
109
+ end
110
+ end
111
+
112
+ # Check if we need to serve static assets (for API-only Rails apps)
113
+ def self.should_serve_static_assets?(app_config)
114
+ # Serve static assets if:
115
+ # 1. The asset pipeline is not available (API-only mode)
116
+ # 2. Public file server is enabled (default in development/test)
117
+ !app_config.respond_to?(:assets) && app_config.public_file_server.enabled
118
+ end
119
+
120
+ # Check for ActionView availability and provide guidance
121
+ initializer "stomp_base.actionview_check", after: :load_config_initializers do |app|
122
+ if app.config.api_only
123
+ if defined?(ActionView::Railtie) && Rails.application.config.railties_order.include?(ActionView::Railtie)
124
+ Rails.logger.info "StompBase: ActionView railtie detected - full UI functionality available"
125
+ else
126
+ Rails.logger.warn <<~WARNING
127
+ ⚠️ StompBase Notice: ActionView railtie is not loaded.
128
+ StompBase requires ActionView for rendering UI components.
129
+
130
+ To enable ActionView, uncomment this line in your config/application.rb:
131
+ require "action_view/railtie"
132
+
133
+ StompBase will attempt to function with limited capabilities.
134
+ WARNING
135
+ end
136
+ end
137
+ end
39
138
  end
40
139
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module StompBase
4
- VERSION = "0.2.0"
4
+ VERSION = "0.2.1"
5
5
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: stomp_base
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.0
4
+ version: 0.2.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - snowwshiro