Project

General

Profile

Feature #42510 » 0001-WIP-Stimulus-demo.patch

Marius BĂLTEANU, 2025-04-03 23:30

View differences:

Gemfile
gem 'rubyzip', '~> 2.4.0'
gem 'propshaft', '~> 1.1.0'
gem 'rack', '>= 3.1.3'
gem 'stimulus-rails'
gem "importmap-rails"
# Ruby Standard Gems
gem 'csv', '~> 3.2.8'
app/helpers/application_helper.rb
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 <<
......
def copy_object_url_link(url)
link_to_function(
sprite_icon('copy-link', l(:button_copy_link)), 'copyTextToClipboard(this);',
sprite_icon('copy-link', l(:button_copy_link)), {},
class: 'icon icon-copy-link',
data: {'clipboard-text' => url}
data: {
'clipboard-value': url,
controller: "clipboard",
action: "clipboard#copy",
'clipboard-target': "source",
}
)
end
app/javascript/application.js
import "controllers"
app/javascript/controllers/application.js
import { Application } from "@hotwired/stimulus"
const application = Application.start()
// Configure Stimulus development experience
application.debug = false
window.Stimulus = application
export { application }
app/javascript/controllers/clipboard_controller.js
import { Controller } from "@hotwired/stimulus"
export default class extends Controller {
static targets = [ "source" ]
copy() {
navigator.clipboard.writeText(this.sourceTarget.dataset.clipboardValue).then(() => this.close())
}
close() {
const drdn = this.sourceTarget.closest('.drdn.expanded')
if (drdn) {
drdn.classList.remove("expanded");
}
}
}
app/javascript/controllers/index.js
// Import and register all your controllers from the importmap under controllers/*
import { application } from "controllers/application"
// Eager load all controllers defined in the import map under controllers/**/*_controller
import { eagerLoadControllersFrom } from "@hotwired/stimulus-loading"
eagerLoadControllersFrom("controllers", application)
app/views/layouts/base.html.erb
<%= 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_auto_complete(@project) %>
bin/importmap
#!/usr/bin/env ruby
require_relative "../config/application"
require "importmap/commands"
config/importmap.rb
# Pin npm packages by running ./bin/importmap
pin "application", preload: true
pin "@hotwired/stimulus", to: "stimulus.min.js"
pin "@hotwired/stimulus-loading", to: "stimulus-loading.js"
pin_all_from "app/javascript/controllers", under: "controllers"
(1-1/2)