Skip to content

Commit a1c5ec5

Browse files
committed
sass -> sassc
Fixes twbs#1156
1 parent 3db610a commit a1c5ec5

File tree

16 files changed

+69
-57
lines changed

16 files changed

+69
-57
lines changed

Gemfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,5 +6,5 @@ gemspec
66
gem 'compass', require: false
77

88
group :development do
9-
gem 'byebug', platforms: [:mri_21, :mri_22], require: false
9+
gem 'byebug', platform: :mri, require: false
1010
end

Rakefile

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
lib_path = File.join(File.dirname(__FILE__), 'lib')
1+
lib_path = File.join(__dir__, 'lib')
22
$:.unshift(lib_path) unless $:.include?(lib_path)
33

44
load './tasks/bower.rake'
@@ -42,11 +42,12 @@ end
4242

4343
desc 'Dumps output to a CSS file for testing'
4444
task :debug do
45-
require 'sass'
45+
require 'sassc'
46+
require 'bootstrap-sass'
4647
path = Bootstrap.stylesheets_path
47-
%w(bootstrap).each do |file|
48-
engine = Sass::Engine.for_file("#{path}/#{file}.scss", syntax: :scss, load_paths: [path])
49-
File.open("./#{file}.css", 'w') { |f| f.write(engine.render) }
48+
%w(_bootstrap).each do |file|
49+
engine = SassC::Engine.new(File.read("#{path}/#{file}.scss"), syntax: :scss, load_paths: [path])
50+
File.open("tmp/#{file}.css", 'w') { |f| f.write(engine.render) }
5051
end
5152
end
5253

@@ -64,7 +65,8 @@ end
6465

6566
desc 'Compile bootstrap-sass to tmp/ (or first arg)'
6667
task :compile, :css_path do |t, args|
67-
require 'sass'
68+
require 'sassc'
69+
require 'bootstrap-sass'
6870
require 'term/ansicolor'
6971

7072
path = 'assets/stylesheets'
@@ -74,8 +76,8 @@ task :compile, :css_path do |t, args|
7476
%w(_bootstrap bootstrap/_theme).each do |file|
7577
save_path = "#{css_path}/#{file.sub(/(^|\/)?_+/, '\1').sub('/', '-')}.css"
7678
puts Term::ANSIColor.cyan(" #{save_path}") + '...'
77-
engine = Sass::Engine.for_file("#{path}/#{file}.scss", syntax: :scss, load_paths: [path])
78-
css = engine.render
79+
engine = SassC::Engine.new(File.read("#{path}/#{file}.scss"), syntax: :scss, load_paths: [path])
80+
css = engine.render
7981
File.open(save_path, 'w') { |f| f.write css }
8082
end
8183
end

assets/stylesheets/bootstrap/_theme.scss

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,8 @@
88
// Load core variables and mixins
99
// --------------------------------------------------
1010

11-
@import "variables";
12-
@import "mixins";
11+
@import "bootstrap/variables";
12+
@import "bootstrap/mixins";
1313

1414

1515
//

bootstrap-sass.gemspec

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,14 +11,14 @@ Gem::Specification.new do |s|
1111
s.homepage = 'https://github.com/twbs/bootstrap-sass'
1212
s.license = 'MIT'
1313

14-
s.add_runtime_dependency 'sass', '>= 3.3.4'
14+
s.add_runtime_dependency 'sassc', '>= 1.12.1'
1515
s.add_runtime_dependency 'autoprefixer-rails', '>= 5.2.1'
1616

1717
# Testing dependencies
18-
s.add_development_dependency 'minitest', '~> 5.8'
19-
s.add_development_dependency 'minitest-reporters', '~> 1.1'
18+
s.add_development_dependency 'minitest', '~> 5.11'
19+
s.add_development_dependency 'minitest-reporters', '~> 1.3'
2020
# Integration testing
21-
s.add_development_dependency 'capybara', '>= 2.5.0'
21+
s.add_development_dependency 'capybara', '~> 3.6'
2222
s.add_development_dependency 'poltergeist'
2323
# Dummy Rails app dependencies
2424
s.add_development_dependency 'actionpack', '>= 4.1.5'

lib/bootstrap-sass.rb

Lines changed: 5 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,12 @@ def load!
1111
register_lotus
1212
elsif sprockets?
1313
register_sprockets
14+
elsif defined?(::Sass) && ::Sass.respond_to?(:load_paths)
15+
# The deprecated `sass` gem:
16+
::Sass.load_paths << stylesheets_path
17+
# bootstrap requires minimum precision of 8, see https://github.com/twbs/bootstrap-sass/issues/409
18+
::Sass::Script::Number.precision = [8, ::Sass::Script::Number.precision].max
1419
end
15-
16-
configure_sass
1720
end
1821

1922
# Paths
@@ -56,15 +59,6 @@ def lotus?
5659

5760
private
5861

59-
def configure_sass
60-
require 'sass'
61-
62-
::Sass.load_paths << stylesheets_path
63-
64-
# bootstrap requires minimum precision of 8, see https://github.com/twbs/bootstrap-sass/issues/409
65-
::Sass::Script::Number.precision = [8, ::Sass::Script::Number.precision].max
66-
end
67-
6862
def register_compass_extension
6963
::Compass::Frameworks.register(
7064
'bootstrap',

tasks/converter/less_conversion.rb

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -124,6 +124,8 @@ def process_stylesheet_assets
124124
file = replace_all file, /(\s*)\.navbar-(right|left)\s*\{\s*@extend\s*\.pull-(right|left);\s*/, "\\1.navbar-\\2 {\\1 float: \\2 !important;\\1"
125125
when 'tables.less'
126126
file = replace_all file, /(@include\s*table-row-variant\()(\w+)/, "\\1'\\2'"
127+
when 'theme.less'
128+
file = replace_all file, /@import "/, '\0bootstrap/'
127129
when 'thumbnails.less', 'labels.less', 'badges.less', 'buttons.less'
128130
file = extract_nested_rule file, 'a&'
129131
when 'glyphicons.less'

tasks/converter/network.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ def read_cached_files(path, files)
3232
if File.directory?(full_path)
3333
files.each do |name|
3434
path = "#{full_path}/#{name}"
35-
contents[name] = File.read(path, mode: 'rb') if File.exists?(path)
35+
contents[name] = File.read(path, mode: 'rb') if File.exist?(path)
3636
end
3737
end
3838
contents
@@ -51,7 +51,7 @@ def get_file(url)
5151
uri = URI(url)
5252
cache_path = "./#@cache_path#{uri.path}#{uri.query.tr('?&=', '-') if uri.query}"
5353
FileUtils.mkdir_p File.dirname(cache_path)
54-
if File.exists?(cache_path)
54+
if File.exist?(cache_path)
5555
log_http_get_file url, true
5656
File.read(cache_path, mode: 'rb')
5757
else

test/compilation_test.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
require 'test_helper'
22
require 'fileutils'
3-
require 'sass'
3+
require 'sassc'
44

55
class CompilationTest < Minitest::Test
66
def test_compilation
77
path = 'assets/stylesheets'
88
%w(_bootstrap bootstrap/_theme).each do |file|
99
FileUtils.rm_rf('.sass-cache', secure: true)
10-
engine = Sass::Engine.for_file("#{path}/#{file}.scss", syntax: :scss, load_paths: [path])
10+
engine = SassC::Engine.new(File.read("#{path}/#{file}.scss"), syntax: :scss, load_paths: [path])
1111
FileUtils.mkdir_p("tmp/#{File.dirname(file)}")
1212
File.open("tmp/#{file}.css", 'w') { |f|
1313
f.write engine.render

test/dummy_rails/config/boot.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
# Set up gems listed in the Gemfile.
22
ENV['BUNDLE_GEMFILE'] ||= File.expand_path('../../../../Gemfile', __FILE__)
33

4-
require 'bundler/setup' if File.exists?(ENV['BUNDLE_GEMFILE'])
4+
require 'bundler/setup' if File.exist?(ENV['BUNDLE_GEMFILE'])
55
$LOAD_PATH.unshift File.expand_path('../../../../lib', __FILE__)

test/dummy_sass_only/Gemfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
source 'https://rubygems.org'
22

3-
gem 'sass', '~> 3.3'
3+
gem 'sassc', '>= 1.12.1'
44
gem 'bootstrap-sass', path: '../..'

test/dummy_sass_only/compile.rb

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,20 @@
1-
require 'sass'
1+
# frozen_string_literal: true
2+
3+
require 'sassc'
24
require 'bootstrap-sass'
35
require 'fileutils'
46

5-
scss_path = File.expand_path('./import_all.sass', File.dirname(__FILE__))
6-
css = Sass.compile File.read(scss_path), syntax: 'sass'
7+
load_path = ARGV[0]
8+
out_path = ARGV[1]
9+
10+
output = SassC::Engine.new(
11+
File.read(File.expand_path('./import_all.scss', __dir__)),
12+
syntax: :scss, load_paths: [load_path]
13+
).render
714

8-
if ARGV[0]
9-
FileUtils.mkdir_p File.dirname(ARGV[0])
10-
File.open(ARGV[0], 'w') { |f| f.write css }
15+
if out_path
16+
FileUtils.mkdir_p(File.dirname(out_path))
17+
File.write(out_path, output)
1118
else
12-
puts css
19+
puts output
1320
end

test/dummy_sass_only/import_all.sass

Lines changed: 0 additions & 2 deletions
This file was deleted.

test/dummy_sass_only/import_all.scss

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
@import 'bootstrap';
2+
@import 'bootstrap/theme';

test/sass_test.rb

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,25 @@
1+
# frozen_string_literal: true
2+
13
require 'test_helper'
24
require 'shellwords'
5+
require 'fileutils'
36

47
class SassTest < Minitest::Test
58
DUMMY_PATH = 'test/dummy_sass_only'
69

710
def test_font_helper
8-
assert_match %r(url\(['"]?.*eot['"]?\)), @css
11+
assert_match %r{url\(['"]?.*eot['"]?\)}, @css
912
end
1013

1114
def setup
12-
Dir.chdir DUMMY_PATH do
13-
%x[rm -rf .sass-cache/]
14-
%x[bundle]
15-
end
15+
FileUtils.rm_rf(File.join(DUMMY_PATH, '.sass-cache'), secure: true)
1616
css_path = File.join GEM_PATH, 'tmp/bootstrap-sass-only.css'
17-
command = "bundle exec ruby compile.rb #{Shellwords.escape css_path}"
1817
success = Dir.chdir DUMMY_PATH do
1918
silence_stdout_if !ENV['VERBOSE'] do
20-
system(command)
19+
Bundler.with_original_env do
20+
system('bundle') && system('bundle', 'exec', 'ruby', 'compile.rb',
21+
Bootstrap.stylesheets_path, css_path)
22+
end
2123
end
2224
end
2325
assert success, 'Sass-only compilation failed'

test/sprockets_rails_test.rb

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
# frozen_string_literal: true
2+
13
require 'test_helper'
24
require 'fileutils'
35
require 'find'
@@ -6,22 +8,24 @@
68
class SprocketsRailsTest < Minitest::Test
79

810
def test_sprockets_digest_asset_refs
9-
root = 'test/dummy_rails'
10-
command = "bundle exec rake assets:precompile GEMFILE=#{GEM_PATH}/Gemfile RAILS_ENV=production"
11+
root = 'test/dummy_rails'
1112
compiled = Dir.chdir root do
1213
silence_stderr_if !ENV['VERBOSE'] do
13-
system(command)
14+
Bundler.with_original_env do
15+
system({ 'BUNDLE_GEMFILE' => File.join(GEM_PATH, 'Gemfile'),
16+
'RAILS_ENV' => 'production' },
17+
'bundle exec rake assets:precompile')
18+
end
1419
end
1520
end
1621
assert compiled, 'Could not precompile assets'
1722
Dir.glob(File.join(root, 'public', 'assets', 'app*.{css,js}')) do |path|
18-
File.open(path, 'r') do |f|
19-
f.read.scan /url\("?[^"]+\.(?:jpg|png|eot|woff2?|ttf|svg)[^"]*"?\)/ do |m|
20-
assert_match /-[0-9a-f]{12,}\./, m
21-
end
23+
File.read(path)
24+
.scan(/url\("?[^"]+\.(?:jpg|png|eot|woff2?|ttf|svg)[^"]*"?\)/) do |m|
25+
assert_match(/-[0-9a-f]{12,}\./, m)
2226
end
2327
end
2428
ensure
25-
FileUtils.rm_rf %W(#{root}/public/assets/ #{root}/tmp/cache/), secure: true
29+
FileUtils.rm_rf %W[#{root}/public/assets/ #{root}/tmp/cache/], secure: true
2630
end
2731
end

test/test_helper.rb

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
require_relative File.join('.', file)
1111
end
1212

13-
GEM_PATH = File.expand_path('../', File.dirname(__FILE__))
13+
GEM_PATH = File.expand_path('../', __dir__)
1414

1515
#= Capybara + Poltergeist
1616
require 'capybara/poltergeist'
@@ -26,6 +26,7 @@
2626
end
2727

2828
Capybara.configure do |config|
29+
config.server = :webrick
2930
config.app_host = 'http://localhost:7000'
3031
config.default_driver = :poltergeist
3132
config.javascript_driver = :poltergeist

0 commit comments

Comments
 (0)