trying to get JS and cssbundling to work

This commit is contained in:
Christoph Haas 2025-04-09 22:47:05 +02:00
parent e4af4c21ae
commit 7cd9c68a10
8 changed files with 155 additions and 44 deletions

12
Gemfile
View file

@ -9,13 +9,13 @@ gem 'sqlite3', '>= 2.1'
# Use the Puma web server [https://github.com/puma/puma]
gem 'puma', '>= 5.0'
# Bundle and transpile JavaScript [https://github.com/rails/jsbundling-rails]
gem 'jsbundling-rails'
# gem 'jsbundling-rails'
# Hotwire's SPA-like page accelerator [https://turbo.hotwired.dev]
# gem "turbo-rails"
# Hotwire's modest JavaScript framework [https://stimulus.hotwired.dev]
# gem "stimulus-rails"
# Bundle and process CSS [https://github.com/rails/cssbundling-rails]
gem 'cssbundling-rails'
# gem 'cssbundling-rails'
# Build JSON APIs with ease [https://github.com/rails/jbuilder]
gem 'jbuilder'
@ -26,9 +26,9 @@ gem 'jbuilder'
gem 'shrine', '~> 3.0'
# Use the database-backed adapters for Rails.cache, Active Job, and Action Cable
gem 'solid_cable'
gem 'solid_cache'
gem 'solid_queue'
# gem 'solid_cable'
# gem 'solid_cache'
# gem 'solid_queue'
# To create variants (different sizes) of screenshot images
gem 'fastimage'
@ -167,3 +167,5 @@ gem 'rails-healthcheck'
# (Dokku) uses environment variables to specify the database connection string
# https://github.com/bkeepers/dotenv
gem 'dotenv'
gem "cssbundling-rails", "~> 1.4"

View file

@ -131,8 +131,6 @@ GEM
email_validator (2.2.4)
activemodel
erubi (1.13.1)
et-orbi (1.2.11)
tzinfo
factory_bot (6.5.1)
activesupport (>= 6.1.0)
factory_bot_rails (6.4.4)
@ -158,9 +156,6 @@ GEM
font-awesome-rails (4.7.0.9)
railties (>= 3.2, < 9.0)
formatador (1.1.0)
fugit (1.11.1)
et-orbi (~> 1, >= 1.2.11)
raabro (~> 1.4)
globalid (1.2.1)
activesupport (>= 6.1)
gravtastic (3.2.6)
@ -196,8 +191,6 @@ GEM
jbuilder (2.13.0)
actionview (>= 5.0.0)
activesupport (>= 5.0.0)
jsbundling-rails (1.3.1)
railties (>= 6.0.0)
json (2.10.2)
json-jwt (1.16.7)
activesupport (>= 4.2)
@ -337,7 +330,6 @@ GEM
public_suffix (6.0.1)
puma (6.6.0)
nio4r (~> 2.0)
raabro (1.4.0)
racc (1.8.1)
rack (3.1.12)
rack-oauth2 (2.2.1)
@ -471,22 +463,6 @@ GEM
actionpack (>= 3.1)
railties (>= 3.1)
slim (>= 3.0, < 6.0, != 5.0.0)
solid_cable (3.0.7)
actioncable (>= 7.2)
activejob (>= 7.2)
activerecord (>= 7.2)
railties (>= 7.2)
solid_cache (1.0.7)
activejob (>= 7.2)
activerecord (>= 7.2)
railties (>= 7.2)
solid_queue (1.1.4)
activejob (>= 7.1)
activerecord (>= 7.1)
concurrent-ruby (>= 1.3.1)
fugit (~> 1.11.0)
railties (>= 7.1)
thor (~> 1.3.1)
sorbet-runtime (0.5.11934)
sqlite3 (2.6.0-aarch64-linux-gnu)
sqlite3 (2.6.0-aarch64-linux-musl)
@ -569,7 +545,7 @@ DEPENDENCIES
bzip2-ffi
cancancan
capybara
cssbundling-rails
cssbundling-rails (~> 1.4)
debug
devise
dotenv
@ -581,7 +557,6 @@ DEPENDENCIES
guard-rails
image_processing
jbuilder
jsbundling-rails
kamal
listen (~> 3.5)
mini_magick
@ -604,9 +579,6 @@ DEPENDENCIES
selenium-webdriver
shrine (~> 3.0)
slim-rails
solid_cable
solid_cache
solid_queue
sqlite3 (>= 2.1)
thruster
web-console

View file

@ -1,3 +1,2 @@
web: env RUBY_DEBUG_OPEN=true bin/rails server
js: yarn build --watch
css: bun run build:css --watch

View file

@ -0,0 +1,131 @@
// Entry point for the build script in your package.json
// import "@hotwired/turbo-rails";
// import "jquery";
// import "foundation-sites";
// import 'foundation-sites/dist/css/foundation.min.css'; // CSS
// import "./controllers";
// // Entry point for the build script in your package.json
// import "./jquery/dist/jquery.min.js";
// import $ from './node_modules/jquery/dist/jquery.min.js';
// import jQuery from "../../jquery/dist/jquery.min.js"; // Direct file path
// window.$ = window.jQuery = jQuery; // Expose globally (if needed)
// import "./foundation-sites/dist/js/foundation.min";
// import jquery from "jquery";
// window.jQuery = jquery;
// window.$ = jquery;
$(function () {
$(document).foundation();
});
// Load reviews on package's details page
// load_reviews = function() {
// // Display message while loading reviews
// // $('#reviews').html("<i>Loading reviews...</i>");
// // Hide the DIV so that in can be faded in later
// $('#reviews').hide();
// // The URL is specified in the #reviews's DIV data attribute
// var url = $('#reviews').attr('data-package-reviews-url');
// $('#reviews').load(url, null,
// // Fade in the reviews as soon as the DIV is loaded and filled
// function(){
// $(this).fadeIn('slow')
// }
// );
// };
// Initialize the upload form.
function upload_form_init() {
// Disable the submit button if Javascript is supported.
// Upload will start right after selecting images.
$('#file-submit').hide();
// Install event handler to notice when files were selected.
$('#file').on('change', upload_form_files_selected);
};
function upload_form_files_selected() {
no_files = this.files.length;
if (no_files > 0) {
$('#file-label').html(no_files+" files selected - uploading…"); // change label
$('#file-select-button').attr('disabled','disabled'); // disable select button
$('#file-form').trigger('submit'); // start upload
}
};
// Handle Ctrl-V to paste an image directly
function upload_paste_handler(event)
{
console.log("paste!");
var items = (event.clipboardData || event.originalEvent.clipboardData).items;
// /*Make Sure Only One File is Copied*/
// if (items.length != 1) {
// return;
// }
for (var i = 0 ; i < items.length ; i++)
{
var item = items[i];
console.log(item);
console.log("item size="+item.size);
if (!item.type.startsWith('image/'))
{
console.log("Skipping file with type "+item.type);
continue
}
console.log(item.type);
var file = item.getAsFile();
console.log(file);
upload_file_with_ajax(file);
}
}
function upload_file_with_ajax(file)
{
if (file==null)
{
console.log("File was null. Strange.");
display_error('Maybe the image was too large.');
return;
}
var formData = new FormData();
formData.append('file', file);
$.ajax(ajax_upload_url,
{
type: 'POST',
contentType: false,
processData: false,
data: formData,
//dataType: 'json',
error: function(xhr, txt, err)
{
console.log("AJAX file upload returned error: "+txt+" / "+err);
response = JSON.parse(xhr.responseText);
display_error(response);
},
success: function(res)
{
console.log("AJAX file upload was ok");
// Go back to details page to show the new upload
window.location.replace(after_upload_url);
}
});
}
function display_error(msg)
{
$('#messages').html(
'<div class="callout alert alert-callout-subtle radius">Sorry, pasting did not work. ' + msg + '</div>')
}

View file

@ -12,8 +12,14 @@ html
/ = stylesheet_link_tag :app, "data-turbo-track": "reload"
/ = javascript_include_tag "application", "data-turbo-track": "reload", type: "module"
/ = stylesheet_link_tag "foundation", media: "all"
= stylesheet_link_tag "application", media: "all"
= javascript_include_tag "application", "data-turbo-track": "reload", type: "module"
/ = javascript_include_tag "jquery/dist/jquery.min.js"
/ = javascript_include_tag "foundation-sites/dist/js/foundation.min"
= javascript_include_tag "jquery-3.7.1.min.js", "data-turbo-track": "reload", type: "module"
= javascript_include_tag "foundation", "data-turbo-track": "reload", type: "module"
= javascript_include_tag "debshots", "data-turbo-track": "reload", type: "module"
/ = javascript_include_tag "application", "data-turbo-track": "reload", type: "module"
= csrf_meta_tags

View file

@ -47,11 +47,11 @@ Rails.application.configure do
config.active_support.report_deprecations = false
# Replace the default in-process memory cache store with a durable alternative.
config.cache_store = :solid_cache_store
# config.cache_store = :solid_cache_store
# Replace the default in-process and non-durable queuing backend for Active Job.
config.active_job.queue_adapter = :solid_queue
config.solid_queue.connects_to = { database: { writing: :queue } }
# config.active_job.queue_adapter = :solid_queue
# config.solid_queue.connects_to = { database: { writing: :queue } }
config.action_mailer.smtp_settings = {
address: ENV['SMTP_SERVER'],
port: 25,

View file

@ -1,7 +1,8 @@
# Be sure to restart your server when you modify this file.
# Version of your assets, change this if you want to expire all your assets.
Rails.application.config.assets.version = "1.0"
Rails.application.config.assets.version = '1.0'
# Add additional assets to the asset load path.
# Rails.application.config.assets.paths << Emoji.images_path
# Rails.application.config.assets.paths << Rails.root.join('node_modules')

View file

@ -24,18 +24,18 @@
# Any libraries that use a connection pool or another resource pool should
# be configured to provide at least as many connections as the number of
# threads. This includes Active Record's `pool` parameter in `database.yml`.
threads_count = ENV.fetch("RAILS_MAX_THREADS", 3)
threads_count = ENV.fetch('RAILS_MAX_THREADS', 3)
threads threads_count, threads_count
# Specifies the `port` that Puma will listen on to receive requests; default is 3000.
port ENV.fetch("PORT", 3000)
port ENV.fetch('PORT', 3000)
# Allow puma to be restarted by `bin/rails restart` command.
plugin :tmp_restart
# Run the Solid Queue supervisor inside of Puma for single-server deployments
plugin :solid_queue if ENV["SOLID_QUEUE_IN_PUMA"]
# plugin :solid_queue if ENV["SOLID_QUEUE_IN_PUMA"]
# Specify the PID file. Defaults to tmp/pids/server.pid in development.
# In other environments, only set the PID file if requested.
pidfile ENV["PIDFILE"] if ENV["PIDFILE"]
pidfile ENV['PIDFILE'] if ENV['PIDFILE']