Skip to content

Commit

Permalink
sass -> sassc
Browse files Browse the repository at this point in the history
Fixes #1156
  • Loading branch information
glebm committed Dec 14, 2018
1 parent 3db610a commit a1c5ec5
Show file tree
Hide file tree
Showing 16 changed files with 69 additions and 57 deletions.
2 changes: 1 addition & 1 deletion Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,5 @@ gemspec
gem 'compass', require: false

group :development do
gem 'byebug', platforms: [:mri_21, :mri_22], require: false
gem 'byebug', platform: :mri, require: false
end
18 changes: 10 additions & 8 deletions Rakefile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
lib_path = File.join(File.dirname(__FILE__), 'lib')
lib_path = File.join(__dir__, 'lib')
$:.unshift(lib_path) unless $:.include?(lib_path)

load './tasks/bower.rake'
Expand Down Expand Up @@ -42,11 +42,12 @@ end

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

Expand All @@ -64,7 +65,8 @@ end

desc 'Compile bootstrap-sass to tmp/ (or first arg)'
task :compile, :css_path do |t, args|
require 'sass'
require 'sassc'
require 'bootstrap-sass'
require 'term/ansicolor'

path = 'assets/stylesheets'
Expand All @@ -74,8 +76,8 @@ task :compile, :css_path do |t, args|
%w(_bootstrap bootstrap/_theme).each do |file|
save_path = "#{css_path}/#{file.sub(/(^|\/)?_+/, '\1').sub('/', '-')}.css"
puts Term::ANSIColor.cyan(" #{save_path}") + '...'
engine = Sass::Engine.for_file("#{path}/#{file}.scss", syntax: :scss, load_paths: [path])
css = engine.render
engine = SassC::Engine.new(File.read("#{path}/#{file}.scss"), syntax: :scss, load_paths: [path])
css = engine.render
File.open(save_path, 'w') { |f| f.write css }
end
end
Expand Down
4 changes: 2 additions & 2 deletions assets/stylesheets/bootstrap/_theme.scss
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@
// Load core variables and mixins
// --------------------------------------------------

@import "variables";
@import "mixins";
@import "bootstrap/variables";
@import "bootstrap/mixins";


//
Expand Down
8 changes: 4 additions & 4 deletions bootstrap-sass.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,14 @@ Gem::Specification.new do |s|
s.homepage = 'https://github.com/twbs/bootstrap-sass'
s.license = 'MIT'

s.add_runtime_dependency 'sass', '>= 3.3.4'
s.add_runtime_dependency 'sassc', '>= 1.12.1'
s.add_runtime_dependency 'autoprefixer-rails', '>= 5.2.1'

# Testing dependencies
s.add_development_dependency 'minitest', '~> 5.8'
s.add_development_dependency 'minitest-reporters', '~> 1.1'
s.add_development_dependency 'minitest', '~> 5.11'
s.add_development_dependency 'minitest-reporters', '~> 1.3'
# Integration testing
s.add_development_dependency 'capybara', '>= 2.5.0'
s.add_development_dependency 'capybara', '~> 3.6'
s.add_development_dependency 'poltergeist'
# Dummy Rails app dependencies
s.add_development_dependency 'actionpack', '>= 4.1.5'
Expand Down
16 changes: 5 additions & 11 deletions lib/bootstrap-sass.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,12 @@ def load!
register_lotus
elsif sprockets?
register_sprockets
elsif defined?(::Sass) && ::Sass.respond_to?(:load_paths)
# The deprecated `sass` gem:
::Sass.load_paths << stylesheets_path
# bootstrap requires minimum precision of 8, see https://github.com/twbs/bootstrap-sass/issues/409
::Sass::Script::Number.precision = [8, ::Sass::Script::Number.precision].max
end

configure_sass
end

# Paths
Expand Down Expand Up @@ -56,15 +59,6 @@ def lotus?

private

def configure_sass
require 'sass'

::Sass.load_paths << stylesheets_path

# bootstrap requires minimum precision of 8, see https://github.com/twbs/bootstrap-sass/issues/409
::Sass::Script::Number.precision = [8, ::Sass::Script::Number.precision].max
end

def register_compass_extension
::Compass::Frameworks.register(
'bootstrap',
Expand Down
2 changes: 2 additions & 0 deletions tasks/converter/less_conversion.rb
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,8 @@ def process_stylesheet_assets
file = replace_all file, /(\s*)\.navbar-(right|left)\s*\{\s*@extend\s*\.pull-(right|left);\s*/, "\\1.navbar-\\2 {\\1 float: \\2 !important;\\1"
when 'tables.less'
file = replace_all file, /(@include\s*table-row-variant\()(\w+)/, "\\1'\\2'"
when 'theme.less'
file = replace_all file, /@import "/, '\0bootstrap/'
when 'thumbnails.less', 'labels.less', 'badges.less', 'buttons.less'
file = extract_nested_rule file, 'a&'
when 'glyphicons.less'
Expand Down
4 changes: 2 additions & 2 deletions tasks/converter/network.rb
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ def read_cached_files(path, files)
if File.directory?(full_path)
files.each do |name|
path = "#{full_path}/#{name}"
contents[name] = File.read(path, mode: 'rb') if File.exists?(path)
contents[name] = File.read(path, mode: 'rb') if File.exist?(path)
end
end
contents
Expand All @@ -51,7 +51,7 @@ def get_file(url)
uri = URI(url)
cache_path = "./#@cache_path#{uri.path}#{uri.query.tr('?&=', '-') if uri.query}"
FileUtils.mkdir_p File.dirname(cache_path)
if File.exists?(cache_path)
if File.exist?(cache_path)
log_http_get_file url, true
File.read(cache_path, mode: 'rb')
else
Expand Down
4 changes: 2 additions & 2 deletions test/compilation_test.rb
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
require 'test_helper'
require 'fileutils'
require 'sass'
require 'sassc'

class CompilationTest < Minitest::Test
def test_compilation
path = 'assets/stylesheets'
%w(_bootstrap bootstrap/_theme).each do |file|
FileUtils.rm_rf('.sass-cache', secure: true)
engine = Sass::Engine.for_file("#{path}/#{file}.scss", syntax: :scss, load_paths: [path])
engine = SassC::Engine.new(File.read("#{path}/#{file}.scss"), syntax: :scss, load_paths: [path])
FileUtils.mkdir_p("tmp/#{File.dirname(file)}")
File.open("tmp/#{file}.css", 'w') { |f|
f.write engine.render
Expand Down
2 changes: 1 addition & 1 deletion test/dummy_rails/config/boot.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# Set up gems listed in the Gemfile.
ENV['BUNDLE_GEMFILE'] ||= File.expand_path('../../../../Gemfile', __FILE__)

require 'bundler/setup' if File.exists?(ENV['BUNDLE_GEMFILE'])
require 'bundler/setup' if File.exist?(ENV['BUNDLE_GEMFILE'])
$LOAD_PATH.unshift File.expand_path('../../../../lib', __FILE__)
2 changes: 1 addition & 1 deletion test/dummy_sass_only/Gemfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
source 'https://rubygems.org'

gem 'sass', '~> 3.3'
gem 'sassc', '>= 1.12.1'
gem 'bootstrap-sass', path: '../..'
21 changes: 14 additions & 7 deletions test/dummy_sass_only/compile.rb
Original file line number Diff line number Diff line change
@@ -1,13 +1,20 @@
require 'sass'
# frozen_string_literal: true

require 'sassc'
require 'bootstrap-sass'
require 'fileutils'

scss_path = File.expand_path('./import_all.sass', File.dirname(__FILE__))
css = Sass.compile File.read(scss_path), syntax: 'sass'
load_path = ARGV[0]
out_path = ARGV[1]

output = SassC::Engine.new(
File.read(File.expand_path('./import_all.scss', __dir__)),
syntax: :scss, load_paths: [load_path]
).render

if ARGV[0]
FileUtils.mkdir_p File.dirname(ARGV[0])
File.open(ARGV[0], 'w') { |f| f.write css }
if out_path
FileUtils.mkdir_p(File.dirname(out_path))
File.write(out_path, output)
else
puts css
puts output
end
2 changes: 0 additions & 2 deletions test/dummy_sass_only/import_all.sass

This file was deleted.

2 changes: 2 additions & 0 deletions test/dummy_sass_only/import_all.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
@import 'bootstrap';
@import 'bootstrap/theme';
16 changes: 9 additions & 7 deletions test/sass_test.rb
Original file line number Diff line number Diff line change
@@ -1,23 +1,25 @@
# frozen_string_literal: true

require 'test_helper'
require 'shellwords'
require 'fileutils'

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

def test_font_helper
assert_match %r(url\(['"]?.*eot['"]?\)), @css
assert_match %r{url\(['"]?.*eot['"]?\)}, @css
end

def setup
Dir.chdir DUMMY_PATH do
%x[rm -rf .sass-cache/]
%x[bundle]
end
FileUtils.rm_rf(File.join(DUMMY_PATH, '.sass-cache'), secure: true)
css_path = File.join GEM_PATH, 'tmp/bootstrap-sass-only.css'
command = "bundle exec ruby compile.rb #{Shellwords.escape css_path}"
success = Dir.chdir DUMMY_PATH do
silence_stdout_if !ENV['VERBOSE'] do
system(command)
Bundler.with_original_env do
system('bundle') && system('bundle', 'exec', 'ruby', 'compile.rb',
Bootstrap.stylesheets_path, css_path)
end
end
end
assert success, 'Sass-only compilation failed'
Expand Down
20 changes: 12 additions & 8 deletions test/sprockets_rails_test.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

require 'test_helper'
require 'fileutils'
require 'find'
Expand All @@ -6,22 +8,24 @@
class SprocketsRailsTest < Minitest::Test

def test_sprockets_digest_asset_refs
root = 'test/dummy_rails'
command = "bundle exec rake assets:precompile GEMFILE=#{GEM_PATH}/Gemfile RAILS_ENV=production"
root = 'test/dummy_rails'
compiled = Dir.chdir root do
silence_stderr_if !ENV['VERBOSE'] do
system(command)
Bundler.with_original_env do
system({ 'BUNDLE_GEMFILE' => File.join(GEM_PATH, 'Gemfile'),
'RAILS_ENV' => 'production' },
'bundle exec rake assets:precompile')
end
end
end
assert compiled, 'Could not precompile assets'
Dir.glob(File.join(root, 'public', 'assets', 'app*.{css,js}')) do |path|
File.open(path, 'r') do |f|
f.read.scan /url\("?[^"]+\.(?:jpg|png|eot|woff2?|ttf|svg)[^"]*"?\)/ do |m|
assert_match /-[0-9a-f]{12,}\./, m
end
File.read(path)
.scan(/url\("?[^"]+\.(?:jpg|png|eot|woff2?|ttf|svg)[^"]*"?\)/) do |m|
assert_match(/-[0-9a-f]{12,}\./, m)
end
end
ensure
FileUtils.rm_rf %W(#{root}/public/assets/ #{root}/tmp/cache/), secure: true
FileUtils.rm_rf %W[#{root}/public/assets/ #{root}/tmp/cache/], secure: true
end
end
3 changes: 2 additions & 1 deletion test/test_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
require_relative File.join('.', file)
end

GEM_PATH = File.expand_path('../', File.dirname(__FILE__))
GEM_PATH = File.expand_path('../', __dir__)

#= Capybara + Poltergeist
require 'capybara/poltergeist'
Expand All @@ -26,6 +26,7 @@
end

Capybara.configure do |config|
config.server = :webrick
config.app_host = 'http://localhost:7000'
config.default_driver = :poltergeist
config.javascript_driver = :poltergeist
Expand Down

0 comments on commit a1c5ec5

Please sign in to comment.