Skip to content

Commit c13dc8f

Browse files
januszmglebm
authored andcommitted
Backport the support for either DartSass or SassC
1 parent 13e4101 commit c13dc8f

6 files changed

Lines changed: 55 additions & 7 deletions

File tree

README.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,12 @@ Add `bootstrap` to your Gemfile:
2020
gem 'bootstrap', '~> 4.6.2'
2121
```
2222

23+
This gem requires a Sass engine, so make sure you have **one** of these four gems in your Gemfile:
24+
- [`dartsass-sprockets`](https://github.com/tablecheck/dartsass-sprockets): Dart Sass engine, recommended but only works for Ruby 2.6+ and Rails 5+
25+
- [`dartsass-rails`](https://github.com/rails/dartsass-rails): Dart Sass engine, recommended for Rails projects that use Propshaft
26+
- [`cssbundling-rails`](https://github.com/rails/cssbundling-rails): External Sass engine
27+
- [`sassc-rails`](https://github.com/sass/sassc-rails): SassC engine, deprecated but compatible with Ruby 2.3+ and Rails 4
28+
2329
Ensure that `sprockets-rails` is at least v2.3.2.
2430

2531
`bundle install` and restart your server to make the files available through the pipeline.

Rakefile

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -45,16 +45,28 @@ end
4545

4646
desc 'Dumps output to a CSS file for testing'
4747
task :debug do
48-
require 'sassc'
48+
begin
49+
require 'sass-embedded'
50+
rescue LoadError
51+
begin
52+
require 'sassc'
53+
rescue LoadError
54+
raise LoadError.new("bootstrap-rubygem requires a Sass engine. Please add dartsass-sprockets or sassc-rails to your dependencies.")
55+
end
56+
end
4957
require './lib/bootstrap'
5058
require 'term/ansicolor'
5159
require 'autoprefixer-rails'
5260
path = Bootstrap.stylesheets_path
5361
%w(_bootstrap _bootstrap-reboot _bootstrap-grid).each do |file|
54-
engine = SassC::Engine.new(File.read("#{path}/#{file}.scss"), syntax: :scss, load_paths: [path])
55-
out = File.join('tmp', "#{file[1..-1]}.css")
56-
css = engine.render
62+
filename = "#{path}/#{file}.scss"
63+
css = if defined?(SassC::Engine)
64+
SassC::Engine.new(File.read(filename), filename: filename, syntax: :scss).render
65+
else
66+
Sass.compile(filename).css
67+
end
5768
css = AutoprefixerRails.process(css)
69+
out = File.join('tmp', "#{file[1..-1]}.css")
5870
File.write(out, css)
5971
$stderr.puts Term::ANSIColor.green "Compiled #{out}"
6072
end

bootstrap.gemspec

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,6 @@ Gem::Specification.new do |s|
1515
s.required_ruby_version = '>= 2.3.3'
1616

1717
s.add_runtime_dependency 'popper_js', '>= 1.16.1', '< 2'
18-
19-
s.add_runtime_dependency 'sassc-rails', '>= 2.0.0'
2018
s.add_runtime_dependency 'autoprefixer-rails', '>= 9.1.0'
2119

2220
# Testing dependencies

lib/bootstrap/engine.rb

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,23 @@
11
# frozen_string_literal: true
22

33
require 'autoprefixer-rails'
4-
require 'sassc-rails'
4+
begin
5+
require 'dartsass-sprockets'
6+
rescue LoadError
7+
begin
8+
require 'sassc-rails'
9+
rescue LoadError
10+
begin
11+
require 'dartsass-rails'
12+
rescue LoadError
13+
begin
14+
require 'cssbundling-rails'
15+
rescue LoadError
16+
raise LoadError.new("bootstrap-rubygem requires a Sass engine. Please add dartsass-sprockets, sassc-rails, dartsass-rails or cssbundling-rails to your dependencies.")
17+
end
18+
end
19+
end
20+
end
521

622
module Bootstrap
723
module Rails
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
source 'https://rubygems.org'
2+
3+
gem 'actionpack', '~> 7.0.4'
4+
gem 'activesupport', '~> 7.0.4'
5+
gem 'autoprefixer-rails', '>= 9.7.6'
6+
gem 'dartsass-sprockets', '~> 3.0'
7+
8+
gemspec path: '../../'
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
source 'https://rubygems.org'
2+
3+
gem 'actionpack', '~> 7.0.4'
4+
gem 'activesupport', '~> 7.0.4'
5+
gem 'autoprefixer-rails', '>= 9.7.6'
6+
gem 'sassc-rails', '~> 2.0'
7+
8+
gemspec path: '../../'

0 commit comments

Comments
 (0)