Skip to content

Commit

Permalink
Allow Sass engines other than sassc-rails (#92)
Browse files Browse the repository at this point in the history
Co-authored-by: Jonathan Chan <[email protected]>
Co-authored-by: Gleb Mazovetskiy <[email protected]>
  • Loading branch information
3 people authored Jul 14, 2024
1 parent 4c81b48 commit a446fc6
Show file tree
Hide file tree
Showing 9 changed files with 48 additions and 29 deletions.
25 changes: 13 additions & 12 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,31 +9,32 @@ jobs:
strategy:
matrix:
include:
- ruby_version: '2.7'
gemfile: rails_7_0
- ruby_version: '3.3'
gemfile: rails_7_1
upload_coverage: true
- ruby_version: '2.5'
- ruby_version: '3.2'
gemfile: rails_7_1
# - ruby_version: '3.1'
# gemfile: rails_7_1
- ruby_version: '3.3'
gemfile: rails_7_0
- ruby_version: '3.3'
gemfile: rails_6_1
- ruby_version: '2.3'
gemfile: rails_5_0
- ruby_version: '2.3'
gemfile: rails_4_2
bundler: '1'
env:
CC_TEST_REPORTER_ID: ${{ secrets.CC_TEST_REPORTER_ID }}
CI: 1
BUNDLE_GEMFILE: ${{ github.workspace }}/spec/gemfiles/${{ matrix.gemfile }}.gemfile
steps:
- name: "Determine whether to upload coverage"
if: ${{ env.CC_TEST_REPORTER_ID && matrix.upload_coverage }}
run: echo COVERAGE=1 >> $GITHUB_ENV
- uses: actions/checkout@v3
- uses: actions/checkout@v4
- name: Set up Ruby ${{ matrix.ruby_version }} and ${{ matrix.gemfile }}.gemfile
uses: ruby/setup-ruby@v1
with:
ruby-version: ${{ matrix.ruby_version }}
bundler: ${{ matrix.bundler || 'Gemfile.lock' }}
bundler-cache: true
cache-version: 1000
- name: Run tests
if: ${{ !env.COVERAGE }}
run: bundle exec rspec --format d
Expand All @@ -47,11 +48,11 @@ jobs:
env:
BUNDLE_GEMFILE: ${{ github.workspace }}/spec/gemfiles/i18n-tasks.gemfile
steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4
- name: Set up Ruby and i18n-tasks.gemfile
uses: ruby/setup-ruby@v1
with:
ruby-version: 3.2
ruby-version: 3.3
bundler-cache: true
- name: Run i18n-tasks
run: bundle exec i18n-tasks health
4 changes: 4 additions & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
* Remove explicit dependency on `sassc-rails`. Allow the use of this gem with either:
`dartsass-sprockets`, `sassc-rails`, `dartsass-rails`, or `cssbundling-rails`
* Drop support for EOL ruby and rails versions (rails >6.1, ruby >3.1)

## v2.2.3

* Fixes Rails 7 compatibility.
Expand Down
8 changes: 7 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Rails Email Preview [![Build Status][badge-ci]][ci] [![Test Coverage][coverage-badge]][coverage] [![Code Climate][codeclimate-badge]][codeclimate] [![Gitter](https://badges.gitter.im/Join%20Chat.svg)](https://gitter.im/glebm/rails_email_preview?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge)

Preview email in the browser with this Rails engine. Compatible with Rails 4.2+.
Preview email in the browser with this Rails engine. Compatible with Rails 6.1+.

An email review:

Expand All @@ -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
Expand Down
20 changes: 19 additions & 1 deletion lib/rails_email_preview.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,25 @@
require 'rails_email_preview/delivery_handler'
require 'rails_email_preview/view_hooks'

require 'sassc-rails'
# 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("rails_email_preview 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'
Expand Down
3 changes: 1 addition & 2 deletions rails_email_preview.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,7 @@ Gem::Specification.new do |s|
s.metadata = { 'issue_tracker' => 'https://github.com/glebm/rails_email_preview' }
end

s.add_dependency 'rails', '>= 4.2'
s.add_dependency 'sassc-rails', '>= 2.0.0'
s.add_dependency 'rails', '>= 6.1'
s.add_dependency 'turbolinks'
s.add_dependency 'request_store'

Expand Down
3 changes: 3 additions & 0 deletions shared.gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -14,3 +14,6 @@ if ENV['COVERAGE']
gem 'simplecov', require: false
end
end

# For development/testing; when running as a library, you can pick your own sass compiler
gem 'dartsass-sprockets'
6 changes: 0 additions & 6 deletions spec/gemfiles/rails_4_2.gemfile

This file was deleted.

6 changes: 0 additions & 6 deletions spec/gemfiles/rails_5_0.gemfile

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,5 @@ source 'https://rubygems.org'
gemspec path: '../..'
eval_gemfile '../../shared.gemfile'

gem 'rails', '~> 5.2.1'
gem 'rails', '~> 7.1'

0 comments on commit a446fc6

Please sign in to comment.