diff --git a/.travis.yml b/.travis.yml index 359022d..7b5eaa5 100644 --- a/.travis.yml +++ b/.travis.yml @@ -5,17 +5,16 @@ bundler_args: "--binstubs --standalone --without documentation --path ../bundle" script: "bundle exec rake test" gemfile: - - gemfiles/sprockets_2_12.gemfile + - gemfiles/sprockets-rails_3_0.gemfile + - gemfiles/sprockets-rails_2_3.gemfile - gemfiles/sprockets_3_0.gemfile - gemfiles/sprockets_4_0.gemfile - - gemfiles/sprockets-rails_3_0.gemfile - gemfiles/rails_4_2.gemfile - - gemfiles/rails_4_1.gemfile - - gemfiles/rails_4_0.gemfile + - gemfiles/rails_5_2.gemfile rvm: - - 2.2.2 - - 2.3.0 + - 2.4.4 + - 2.5.1 notifications: email: false diff --git a/README.md b/README.md index 003f8fc..528633f 100644 --- a/README.md +++ b/README.md @@ -85,6 +85,9 @@ is maintained by [Ryan Boland](https://ryanboland.com) and [awesome contributors ## Changelog +- **2.0.0** + - [Drop support for Sprockets 2](https://github.com/sass/sassc-rails/pull/109) + - [Remove dependency on Ruby Sass](https://github.com/sass/sassc-rails/pull/109) - **1.3.0** - [Silence Sprockets deprecation warnings](https://github.com/sass/sassc-rails/pull/76) - [Sprockets 4 compatibility](https://github.com/sass/sassc-rails/pull/65) diff --git a/Rakefile b/Rakefile index 066491c..bb58a69 100644 --- a/Rakefile +++ b/Rakefile @@ -10,12 +10,10 @@ namespace :tests do gemfiles = %w[ sprockets-rails_3_0 sprockets-rails_2_3 - sprockets_2_12 sprockets_3_0 + sprockets_4_0 rails_4_2 - rails_4_1 - rails_4_0 - with_sass_rails + rails_5_2 ] gemfiles.each do |gemfile| diff --git a/gemfiles/rails_4_1.gemfile b/gemfiles/rails_4_1.gemfile deleted file mode 100644 index 7d922bf..0000000 --- a/gemfiles/rails_4_1.gemfile +++ /dev/null @@ -1,6 +0,0 @@ -source 'https://rubygems.org' - -gem "rails", "~> 4.1.0" - -# Specify your gem's dependencies in sassc-rails.gemspec -gemspec path: "../" diff --git a/gemfiles/rails_4_0.gemfile b/gemfiles/rails_5_2.gemfile similarity index 81% rename from gemfiles/rails_4_0.gemfile rename to gemfiles/rails_5_2.gemfile index 13998f8..3682fc7 100644 --- a/gemfiles/rails_4_0.gemfile +++ b/gemfiles/rails_5_2.gemfile @@ -1,6 +1,6 @@ source 'https://rubygems.org' -gem "rails", "~> 4.0.0" +gem "rails", "~> 5.2.1" # Specify your gem's dependencies in sassc-rails.gemspec gemspec path: "../" diff --git a/gemfiles/sprockets-rails_2_3.gemfile b/gemfiles/sprockets-rails_2_3.gemfile index e6f0913..e378718 100644 --- a/gemfiles/sprockets-rails_2_3.gemfile +++ b/gemfiles/sprockets-rails_2_3.gemfile @@ -1,6 +1,6 @@ source 'https://rubygems.org' -gem "sprockets-rails", "~> 2.3.0" +gem "sprockets-rails", "~> 2.3.3" # Specify your gem's dependencies in sassc-rails.gemspec gemspec path: "../" diff --git a/gemfiles/sprockets_2_12.gemfile b/gemfiles/sprockets_2_12.gemfile deleted file mode 100644 index a713fd7..0000000 --- a/gemfiles/sprockets_2_12.gemfile +++ /dev/null @@ -1,6 +0,0 @@ -source 'https://rubygems.org' - -gem "sprockets", "~> 2.12.0" - -# Specify your gem's dependencies in sassc-rails.gemspec -gemspec path: "../" diff --git a/gemfiles/with_sass_rails.gemfile b/gemfiles/with_sass_rails.gemfile deleted file mode 100644 index 6687358..0000000 --- a/gemfiles/with_sass_rails.gemfile +++ /dev/null @@ -1,6 +0,0 @@ -source 'https://rubygems.org' - -gem "sass-rails" - -# Specify your gem's dependencies in sassc-rails.gemspec -gemspec path: "../" diff --git a/lib/sassc-rails.rb b/lib/sassc-rails.rb index 7df8adb..81dd485 100644 --- a/lib/sassc-rails.rb +++ b/lib/sassc-rails.rb @@ -1,10 +1,4 @@ # frozen_string_literal: true -begin - require "sass-rails" - Rails::Railtie.subclasses.delete Sass::Rails::Railtie -rescue LoadError -end - require_relative "sassc/rails" diff --git a/lib/sassc/rails/compressor.rb b/lib/sassc/rails/compressor.rb index 8e60fc1..a8e32fd 100644 --- a/lib/sassc/rails/compressor.rb +++ b/lib/sassc/rails/compressor.rb @@ -1,8 +1,19 @@ # frozen_string_literal: true require 'sprockets/sass_compressor' +require 'securerandom' class Sprockets::SassCompressor + def initialize(options = {}) + @options = { + syntax: :scss, + cache: false, + read_cache: false, + style: :compressed + }.merge(options).freeze + @cache_key = SecureRandom.uuid + end + def call(*args) input = if defined?(data) data # sprockets 2.x diff --git a/lib/sassc/rails/template.rb b/lib/sassc/rails/template.rb index a8294de..e5cf6c7 100644 --- a/lib/sassc/rails/template.rb +++ b/lib/sassc/rails/template.rb @@ -1,73 +1,46 @@ # frozen_string_literal: true require "sprockets/version" - -begin - require 'sprockets/sass_processor' -rescue LoadError - require "sprockets/sass_template" -end - +require 'sprockets/sass_processor' require "sprockets/utils" module SassC::Rails - - class SassTemplate < defined?(Sprockets::SassProcessor) ? Sprockets::SassProcessor : Sprockets::SassTemplate - module Sprockets3 - def call(input) - context = input[:environment].context_class.new(input) - - options = { - filename: input[:filename], - line_comments: line_comments?, - syntax: self.class.syntax, - load_paths: input[:environment].paths, - importer: SassC::Rails::Importer, - sprockets: { - context: context, - environment: input[:environment], - dependencies: context.metadata[:dependency_paths] - } - }.merge(config_options) { |*args| safe_merge(*args) } - - engine = ::SassC::Engine.new(input[:data], options) - - css = Sprockets::Utils.module_include(::SassC::Script::Functions, @functions) do - engine.render - end - - context.metadata.merge(data: css) + class SassTemplate < Sprockets::SassProcessor + def initialize(options = {}, &block) + @cache_version = options[:cache_version] + @cache_key = "#{self.class.name}:#{VERSION}:#{SassC::VERSION}:#{@cache_version}".freeze + #@importer_class = options[:importer] || Sass::Importers::Filesystem + @sass_config = options[:sass_config] || {} + @functions = Module.new do + include Functions + include options[:functions] if options[:functions] + class_eval(&block) if block_given? end end - module Sprockets2 - def self.included(base) - base.class_eval do - self.default_mime_type = "text/css" - end + def call(input) + context = input[:environment].context_class.new(input) + + options = { + filename: input[:filename], + line_comments: line_comments?, + syntax: self.class.syntax, + load_paths: input[:environment].paths, + importer: SassC::Rails::Importer, + sprockets: { + context: context, + environment: input[:environment], + dependencies: context.metadata[:dependency_paths] + } + }.merge(config_options) { |*args| safe_merge(*args) } + + engine = ::SassC::Engine.new(input[:data], options) + + css = Sprockets::Utils.module_include(::SassC::Script::Functions, @functions) do + engine.render end - def evaluate(context, locals, &block) - options = { - filename: eval_file, - line_comments: line_comments?, - syntax: syntax, - load_paths: context.environment.paths, - importer: SassC::Rails::Importer, - sprockets: { - context: context, - environment: context.environment - } - }.merge(config_options, &method(:safe_merge)) - - ::SassC::Engine.new(data, options).render - end - end - - if Sprockets::VERSION > "3.0.0" - include Sprockets3 - else - include Sprockets2 + context.metadata.merge(data: css) end def config_options @@ -106,20 +79,34 @@ def safe_merge(key, left, right) right end end - end - class ScssTemplate < SassTemplate - unless Sprockets::VERSION > "3.0.0" - self.default_mime_type = 'text/css' - end + # The methods in the Functions module were copied here from sprockets in order to + # override the Value class names (e.g. ::SassC::Script::Value::String) + module Functions + def asset_path(path, options = {}) + path = path.value - # Sprockets 3 - def self.syntax - :scss + path, _, query, fragment = URI.split(path)[5..8] + path = sprockets_context.asset_path(path, options) + query = "?#{query}" if query + fragment = "##{fragment}" if fragment + + ::SassC::Script::Value::String.new("#{path}#{query}#{fragment}", :string) + end + + def asset_url(path, options = {}) + ::SassC::Script::Value::String.new("url(#{asset_path(path, options).value})") + end + + def asset_data_url(path) + url = sprockets_context.asset_data_uri(path.value) + ::SassC::Script::Value::String.new("url(" + url + ")") + end end + end - # Sprockets 2 - def syntax + class ScssTemplate < SassTemplate + def self.syntax :scss end end diff --git a/lib/sassc/rails/version.rb b/lib/sassc/rails/version.rb index 65901d4..29ba7ed 100644 --- a/lib/sassc/rails/version.rb +++ b/lib/sassc/rails/version.rb @@ -2,6 +2,6 @@ module SassC module Rails - VERSION = "1.3.0" + VERSION = "2.0.0" end end diff --git a/sassc-rails.gemspec b/sassc-rails.gemspec index 40674e1..68ffc39 100644 --- a/sassc-rails.gemspec +++ b/sassc-rails.gemspec @@ -23,14 +23,10 @@ Gem::Specification.new do |spec| spec.add_development_dependency "rake", "~> 10.0" spec.add_development_dependency 'mocha' - # Unfortunately we require sass for now, so that we can - # reuse portions of the Sprockets template - spec.add_dependency 'sass' - spec.add_dependency "sassc", "~> 1.9" - + spec.add_dependency "sassc", ">= 2.0" spec.add_dependency "tilt" spec.add_dependency 'railties', '>= 4.0.0' - spec.add_dependency 'sprockets', '> 2.11' + spec.add_dependency 'sprockets', '> 3.0' spec.add_dependency 'sprockets-rails' end diff --git a/test/sassc_rails_test.rb b/test/sassc_rails_test.rb index 321fcd8..29265ce 100644 --- a/test/sassc_rails_test.rb +++ b/test/sassc_rails_test.rb @@ -2,7 +2,7 @@ require "test_helper" -class SassRailsTest < MiniTest::Unit::TestCase +class SassRailsTest < MiniTest::Test attr_reader :app def setup diff --git a/test/test_helper.rb b/test/test_helper.rb index 433b6a9..8b38c02 100644 --- a/test/test_helper.rb +++ b/test/test_helper.rb @@ -10,7 +10,7 @@ require 'rails' require 'bundler/setup' require "minitest/autorun" -require 'mocha/mini_test' +require 'mocha/minitest' Bundler.require