diff options
author | Marius Balteanu <marius.balteanu@zitec.com> | 2025-04-21 05:48:38 +0000 |
---|---|---|
committer | Marius Balteanu <marius.balteanu@zitec.com> | 2025-04-21 05:48:38 +0000 |
commit | 3407711118a8f7ca0f01ad3f37cd46442693d675 (patch) | |
tree | f930b259c82f3d9017fbe9ba2361d39864b57938 | |
parent | 524a41eb6c64096d8dc89720fd366cbbc096e35f (diff) | |
download | redmine-3407711118a8f7ca0f01ad3f37cd46442693d675.tar.gz redmine-3407711118a8f7ca0f01ad3f37cd46442693d675.zip |
Introduces Stimulus as a Javascript framework (#42510):
* old @application.js@ from @app/assets/javascripts@ become @application-legacy.js@ in favour of @application.js@ provided by Stimulus
* adds @importmap@ gem to handle JavaScript modules using logical names that map to versioned/digested files
Stimulus will be used for new functionality and, over time, to migrate existing features from JQuery / JQuery UI.
git-svn-id: https://svn.redmine.org/redmine/trunk@23697 e93f8b46-1217-0410-a6f0-8f06a7374b81
-rw-r--r-- | Gemfile | 2 | ||||
-rw-r--r-- | app/assets/javascripts/application-legacy.js (renamed from app/assets/javascripts/application.js) | 0 | ||||
-rw-r--r-- | app/helpers/application_helper.rb | 2 | ||||
-rw-r--r-- | app/javascript/application.js | 1 | ||||
-rw-r--r-- | app/javascript/controllers/application.js | 8 | ||||
-rw-r--r-- | app/javascript/controllers/index.js | 3 | ||||
-rw-r--r-- | app/views/layouts/base.html.erb | 1 | ||||
-rw-r--r-- | bin/importmap | 4 | ||||
-rw-r--r-- | config/importmap.rb | 6 |
9 files changed, 26 insertions, 1 deletions
@@ -16,6 +16,8 @@ gem 'addressable' gem 'rubyzip', '~> 2.4.0' gem 'propshaft', '~> 1.1.0' gem 'rack', '>= 3.1.3' +gem "stimulus-rails", "~> 1.3" +gem "importmap-rails", "~> 2.0" # Ruby Standard Gems gem 'csv', '~> 3.3.2' diff --git a/app/assets/javascripts/application.js b/app/assets/javascripts/application-legacy.js index 265ac39c6..265ac39c6 100644 --- a/app/assets/javascripts/application.js +++ b/app/assets/javascripts/application-legacy.js diff --git a/app/helpers/application_helper.rb b/app/helpers/application_helper.rb index 7835bf235..847fb9fdd 100644 --- a/app/helpers/application_helper.rb +++ b/app/helpers/application_helper.rb @@ -1805,7 +1805,7 @@ module ApplicationHelper if Setting.wiki_tablesort_enabled? tags << javascript_include_tag('tablesort-5.2.1.min.js', 'tablesort-5.2.1.number.min.js') end - tags << javascript_include_tag('application', 'responsive') + tags << javascript_include_tag('application-legacy', 'responsive') unless User.current.pref.warn_on_leaving_unsaved == '0' warn_text = escape_javascript(l(:text_warn_on_leaving_unsaved)) tags << diff --git a/app/javascript/application.js b/app/javascript/application.js new file mode 100644 index 000000000..72ef077f8 --- /dev/null +++ b/app/javascript/application.js @@ -0,0 +1 @@ +import "controllers" diff --git a/app/javascript/controllers/application.js b/app/javascript/controllers/application.js new file mode 100644 index 000000000..f898b4e6b --- /dev/null +++ b/app/javascript/controllers/application.js @@ -0,0 +1,8 @@ +import { Application } from '@hotwired/stimulus' + +const application = Application.start() + +application.debug = false +window.Stimulus = application + +export { application } diff --git a/app/javascript/controllers/index.js b/app/javascript/controllers/index.js new file mode 100644 index 000000000..6ffb4e9ee --- /dev/null +++ b/app/javascript/controllers/index.js @@ -0,0 +1,3 @@ +import { application } from "controllers/application" +import { eagerLoadControllersFrom } from "@hotwired/stimulus-loading" +eagerLoadControllersFrom("controllers", application) diff --git a/app/views/layouts/base.html.erb b/app/views/layouts/base.html.erb index cd7e2e66f..e982f534c 100644 --- a/app/views/layouts/base.html.erb +++ b/app/views/layouts/base.html.erb @@ -10,6 +10,7 @@ <%= favicon %> <%= stylesheet_link_tag 'jquery/jquery-ui-1.13.2', 'tribute-5.1.3', 'application', 'responsive', :media => 'all' %> <%= stylesheet_link_tag 'rtl', :media => 'all' if l(:direction) == 'rtl' %> +<%= javascript_importmap_tags %> <%= javascript_heads %> <%= heads_for_theme %> <%= heads_for_i18n %> diff --git a/bin/importmap b/bin/importmap new file mode 100644 index 000000000..36502ab16 --- /dev/null +++ b/bin/importmap @@ -0,0 +1,4 @@ +#!/usr/bin/env ruby + +require_relative "../config/application" +require "importmap/commands" diff --git a/config/importmap.rb b/config/importmap.rb new file mode 100644 index 000000000..cded57738 --- /dev/null +++ b/config/importmap.rb @@ -0,0 +1,6 @@ +# Pin npm packages by running ./bin/importmap + +pin "application" +pin "@hotwired/stimulus", to: "stimulus.min.js" +pin "@hotwired/stimulus-loading", to: "stimulus-loading.js" +pin_all_from "app/javascript/controllers", under: "controllers" |