From d6b11c4405c03c237f96c80f5bd5aa0bf13f0c9d Mon Sep 17 00:00:00 2001 From: Jonathan Chan Date: Sat, 13 Jul 2024 00:24:12 -0500 Subject: [PATCH] utilizing bootstrap gem pick your own sass library code --- Gemfile | 3 +++ README.md | 6 ++++++ lib/rails_email_preview.rb | 20 +++++++++++++++++++- rails_email_preview.gemspec | 1 - 4 files changed, 28 insertions(+), 2 deletions(-) diff --git a/Gemfile b/Gemfile index 2fe87ba..b5d9c88 100644 --- a/Gemfile +++ b/Gemfile @@ -5,4 +5,7 @@ gemspec gem 'rails' gem 'i18n-tasks' +# For development; when running as a library, you can pick your own sass compiler +gem 'dartsass-sprockets' + eval_gemfile './shared.gemfile' diff --git a/README.md b/README.md index a525880..531336b 100644 --- a/README.md +++ b/README.md @@ -20,6 +20,12 @@ Add [![Gem Version][gem-badge]][gem] to Gemfile: gem 'rails_email_preview', '~> 2.2.3' ``` +This gem requires a Sass engine, please ensure you have **one** of these gems in your Gemfile: +- [`dartsass-sprockets`](https://github.com/tablecheck/dartsass-sprockets): Dart Sass engine, recommended but only works for Ruby 2.6+ and Rails 5+ +- [`dartsass-rails`](https://github.com/rails/dartsass-rails): Dart Sass engine, recommended for Rails projects that use Propshaft +- [`cssbundling-rails`](https://github.com/rails/cssbundling-rails): External Sass engine +- [`sassc-rails`](https://github.com/sass/sassc-rails): SassC engine, deprecated but compatible with Ruby 2.3+ and Rails 4 + Add an initializer and the routes: ```console diff --git a/lib/rails_email_preview.rb b/lib/rails_email_preview.rb index 37c27de..6598d56 100644 --- a/lib/rails_email_preview.rb +++ b/lib/rails_email_preview.rb @@ -5,7 +5,25 @@ require 'rails_email_preview/delivery_handler' require 'rails_email_preview/view_hooks' -require 'dartsass-sprockets' +# sass engine loader +begin + require 'dartsass-sprockets' +rescue LoadError + begin + require 'sassc-rails' + rescue LoadError + begin + require 'dartsass-rails' + rescue LoadError + begin + require 'cssbundling-rails' + rescue LoadError + raise LoadError.new("bootstrap-rubygem requires a Sass engine. Please add dartsass-sprockets, sassc-rails, dartsass-rails or cssbundling-rails to your dependencies.") + end + end + end +end + require 'request_store' require 'turbolinks' require 'pathname' diff --git a/rails_email_preview.gemspec b/rails_email_preview.gemspec index c5047d7..572f9c2 100644 --- a/rails_email_preview.gemspec +++ b/rails_email_preview.gemspec @@ -18,7 +18,6 @@ Gem::Specification.new do |s| end s.add_dependency 'rails', '>= 4.2' - s.add_dependency 'dartsass-sprockets' s.add_dependency 'turbolinks' s.add_dependency 'request_store'