sass -> sassc

Fixes #1156
This commit is contained in:
Gleb Mazovetskiy 2018-08-21 22:34:39 +01:00
parent 3db610a768
commit a1c5ec516b
16 changed files with 69 additions and 57 deletions

View File

@ -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

View File

@ -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'
@ -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
@ -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'
@ -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

View File

@ -8,8 +8,8 @@
// Load core variables and mixins
// --------------------------------------------------
@import "variables";
@import "mixins";
@import "bootstrap/variables";
@import "bootstrap/mixins";
//

View File

@ -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'

View File

@ -11,9 +11,12 @@ module Bootstrap
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
@ -56,15 +59,6 @@ module Bootstrap
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',

View File

@ -124,6 +124,8 @@ class Converter
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'

View File

@ -32,7 +32,7 @@ class Converter
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
@ -51,7 +51,7 @@ class Converter
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

View File

@ -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

View File

@ -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__)

View File

@ -1,4 +1,4 @@
source 'https://rubygems.org'
gem 'sass', '~> 3.3'
gem 'sassc', '>= 1.12.1'
gem 'bootstrap-sass', path: '../..'

View File

@ -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]
if ARGV[0]
FileUtils.mkdir_p File.dirname(ARGV[0])
File.open(ARGV[0], 'w') { |f| f.write css }
output = SassC::Engine.new(
File.read(File.expand_path('./import_all.scss', __dir__)),
syntax: :scss, load_paths: [load_path]
).render
if out_path
FileUtils.mkdir_p(File.dirname(out_path))
File.write(out_path, output)
else
puts css
puts output
end

View File

@ -1,2 +0,0 @@
@import 'bootstrap'
@import 'bootstrap/theme'

View File

@ -0,0 +1,2 @@
@import 'bootstrap';
@import 'bootstrap/theme';

View File

@ -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'

View File

@ -1,3 +1,5 @@
# frozen_string_literal: true
require 'test_helper'
require 'fileutils'
require 'find'
@ -6,22 +8,24 @@ require 'shellwords'
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

View File

@ -10,7 +10,7 @@ Dir['test/support/**/*.rb'].each do |file|
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'
@ -26,6 +26,7 @@ Capybara.register_driver :poltergeist do |app|
end
Capybara.configure do |config|
config.server = :webrick
config.app_host = 'http://localhost:7000'
config.default_driver = :poltergeist
config.javascript_driver = :poltergeist