From 9a90e46b78ad2c17c780d4de765395fe7a7f1f0d Mon Sep 17 00:00:00 2001 From: Gaetan Craig-Riou Date: Fri, 16 Jan 2026 15:12:01 +1100 Subject: [PATCH] Move mail css back to be managed by wepack It wil allow us to remove dependency on `rails-sass`, and `sass` which are not maintained anymore. More or less revert this PR: https://github.com/openfoodfoundation/openfoodnetwork/pull/12743 --- app/assets/stylesheets/mail.scss | 1 - app/assets/stylesheets/mail/all.scss | 3 --- app/helpers/application_helper.rb | 15 +++++++++++++++ app/views/layouts/mailer.html.haml | 2 +- app/views/spree/admin/orders/invoice.html.haml | 2 +- app/views/spree/admin/orders/invoice2.html.haml | 2 +- app/views/spree/admin/orders/invoice4.html.haml | 4 ++-- app/webpacker/css/mail/all.scss | 3 +++ .../stylesheets => webpacker/css}/mail/email.scss | 0 .../css}/mail/payments_list.scss | 0 app/webpacker/packs/mail.scss | 1 + config/initializers/assets.rb | 1 - 12 files changed, 24 insertions(+), 10 deletions(-) delete mode 100644 app/assets/stylesheets/mail.scss delete mode 100644 app/assets/stylesheets/mail/all.scss create mode 100644 app/webpacker/css/mail/all.scss rename app/{assets/stylesheets => webpacker/css}/mail/email.scss (100%) rename app/{assets/stylesheets => webpacker/css}/mail/payments_list.scss (100%) create mode 100644 app/webpacker/packs/mail.scss diff --git a/app/assets/stylesheets/mail.scss b/app/assets/stylesheets/mail.scss deleted file mode 100644 index e35654c0d2..0000000000 --- a/app/assets/stylesheets/mail.scss +++ /dev/null @@ -1 +0,0 @@ -@import './mail/all.scss'; diff --git a/app/assets/stylesheets/mail/all.scss b/app/assets/stylesheets/mail/all.scss deleted file mode 100644 index fa8445d726..0000000000 --- a/app/assets/stylesheets/mail/all.scss +++ /dev/null @@ -1,3 +0,0 @@ -@import '../../../webpacker/css/admin/globals/palette.scss'; -@import 'email'; -@import 'payments_list'; diff --git a/app/helpers/application_helper.rb b/app/helpers/application_helper.rb index 4da992b8ef..fc242cf18c 100644 --- a/app/helpers/application_helper.rb +++ b/app/helpers/application_helper.rb @@ -76,4 +76,19 @@ module ApplicationHelper def cache_key_with_locale(key, locale) Array.wrap(key) + ["v2", locale.to_s, I18nDigests.for_locale(locale)] end + + def pdf_stylesheet_pack_tag(source) + # With shakapacker dev server running, the wicked_pdf_stylesheet_pack_tag will produce a + # relative path, because we don't have `config.action_controller.asset_host`. Relative path + # can't be resolved by `wkhtmltopdf`. So we pass the wepacker dev server host and port to + # the shakapacker helper, so it generates the correct url. + # For more info: https://stackoverflow.com/questions/58490299/how-to-include-css-stylesheet-into-wicked-pdf/60541688#60541688 + if running_in_development? + options = { media: "all", + host: "#{Shakapacker.dev_server.host}:#{Shakapacker.dev_server.port}" } + stylesheet_pack_tag(source, **options) + else + wicked_pdf_stylesheet_pack_tag(source) + end + end end diff --git a/app/views/layouts/mailer.html.haml b/app/views/layouts/mailer.html.haml index 2a74b48ad9..0a6981a08f 100644 --- a/app/views/layouts/mailer.html.haml +++ b/app/views/layouts/mailer.html.haml @@ -5,7 +5,7 @@ %meta{:content => "text/html; charset=UTF-8", "http-equiv" => "Content-Type"}/ %title = Spree::Config[:site_name] - = stylesheet_link_tag 'mail', media: "screen" + = stylesheet_pack_tag "mail", media: "screen" %body{:bgcolor => "#FFFFFF" } - unless @hide_ofn_navigation %table.head-wrap diff --git a/app/views/spree/admin/orders/invoice.html.haml b/app/views/spree/admin/orders/invoice.html.haml index a72e7c1fff..d1dbc32264 100644 --- a/app/views/spree/admin/orders/invoice.html.haml +++ b/app/views/spree/admin/orders/invoice.html.haml @@ -1,4 +1,4 @@ -= wicked_pdf_stylesheet_link_tag "mail" += pdf_stylesheet_pack_tag "mail" %table{:width => "100%"} %tbody diff --git a/app/views/spree/admin/orders/invoice2.html.haml b/app/views/spree/admin/orders/invoice2.html.haml index 935e370d7a..c55a1f6637 100644 --- a/app/views/spree/admin/orders/invoice2.html.haml +++ b/app/views/spree/admin/orders/invoice2.html.haml @@ -1,4 +1,4 @@ -= wicked_pdf_stylesheet_link_tag "mail" += pdf_stylesheet_pack_tag "mail" %table{:width => "100%"} %tbody diff --git a/app/views/spree/admin/orders/invoice4.html.haml b/app/views/spree/admin/orders/invoice4.html.haml index 6a5c22ac8b..6e92e589d5 100644 --- a/app/views/spree/admin/orders/invoice4.html.haml +++ b/app/views/spree/admin/orders/invoice4.html.haml @@ -1,4 +1,4 @@ -= wicked_pdf_stylesheet_link_tag "mail" += pdf_stylesheet_pack_tag "mail" %table{:width => "100%"} %tbody @@ -102,4 +102,4 @@ = render partial: 'spree/admin/orders/_invoice/order_note' .text-center - = link_to_platform_terms \ No newline at end of file + = link_to_platform_terms diff --git a/app/webpacker/css/mail/all.scss b/app/webpacker/css/mail/all.scss new file mode 100644 index 0000000000..087d2d1310 --- /dev/null +++ b/app/webpacker/css/mail/all.scss @@ -0,0 +1,3 @@ +@import '../admin/globals/palette.scss'; +@import 'email'; +@import 'payments_list'; diff --git a/app/assets/stylesheets/mail/email.scss b/app/webpacker/css/mail/email.scss similarity index 100% rename from app/assets/stylesheets/mail/email.scss rename to app/webpacker/css/mail/email.scss diff --git a/app/assets/stylesheets/mail/payments_list.scss b/app/webpacker/css/mail/payments_list.scss similarity index 100% rename from app/assets/stylesheets/mail/payments_list.scss rename to app/webpacker/css/mail/payments_list.scss diff --git a/app/webpacker/packs/mail.scss b/app/webpacker/packs/mail.scss new file mode 100644 index 0000000000..d4f981e355 --- /dev/null +++ b/app/webpacker/packs/mail.scss @@ -0,0 +1 @@ +@import "../css/mail/all.scss"; diff --git a/config/initializers/assets.rb b/config/initializers/assets.rb index 37ea1edf62..d6d7a932d6 100644 --- a/config/initializers/assets.rb +++ b/config/initializers/assets.rb @@ -19,6 +19,5 @@ Rails.application.config.assets.precompile += [ 'web/all.js', 'darkswarm/all.js', 'shared/*', - 'mail.scss', '*.jpg', '*.jpeg', '*.png', '*.gif' '*.svg', ]