Skip to content

Commit f5ab1cb

Browse files
authored
Merge pull request sass#109 from sass/rmb/drop_sass
drop ruby sass requirement
2 parents bfca465 + c314d1c commit f5ab1cb

15 files changed

+84
-114
lines changed

.travis.yml

+5-6
Original file line numberDiff line numberDiff line change
@@ -5,17 +5,16 @@ bundler_args: "--binstubs --standalone --without documentation --path ../bundle"
55
script: "bundle exec rake test"
66

77
gemfile:
8-
- gemfiles/sprockets_2_12.gemfile
8+
- gemfiles/sprockets-rails_3_0.gemfile
9+
- gemfiles/sprockets-rails_2_3.gemfile
910
- gemfiles/sprockets_3_0.gemfile
1011
- gemfiles/sprockets_4_0.gemfile
11-
- gemfiles/sprockets-rails_3_0.gemfile
1212
- gemfiles/rails_4_2.gemfile
13-
- gemfiles/rails_4_1.gemfile
14-
- gemfiles/rails_4_0.gemfile
13+
- gemfiles/rails_5_2.gemfile
1514

1615
rvm:
17-
- 2.2.2
18-
- 2.3.0
16+
- 2.4.4
17+
- 2.5.1
1918

2019
notifications:
2120
email: false

README.md

+3
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,9 @@ is maintained by [Ryan Boland](https://ryanboland.com) and [awesome contributors
8585

8686
## Changelog
8787

88+
- **2.0.0**
89+
- [Drop support for Sprockets 2](https://github.com/sass/sassc-rails/pull/109)
90+
- [Remove dependency on Ruby Sass](https://github.com/sass/sassc-rails/pull/109)
8891
- **1.3.0**
8992
- [Silence Sprockets deprecation warnings](https://github.com/sass/sassc-rails/pull/76)
9093
- [Sprockets 4 compatibility](https://github.com/sass/sassc-rails/pull/65)

Rakefile

+2-4
Original file line numberDiff line numberDiff line change
@@ -10,12 +10,10 @@ namespace :tests do
1010
gemfiles = %w[
1111
sprockets-rails_3_0
1212
sprockets-rails_2_3
13-
sprockets_2_12
1413
sprockets_3_0
14+
sprockets_4_0
1515
rails_4_2
16-
rails_4_1
17-
rails_4_0
18-
with_sass_rails
16+
rails_5_2
1917
]
2018

2119
gemfiles.each do |gemfile|

gemfiles/rails_4_1.gemfile

-6
This file was deleted.
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
source 'https://rubygems.org'
22

3-
gem "rails", "~> 4.0.0"
3+
gem "rails", "~> 5.2.1"
44

55
# Specify your gem's dependencies in sassc-rails.gemspec
66
gemspec path: "../"

gemfiles/sprockets-rails_2_3.gemfile

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
source 'https://rubygems.org'
22

3-
gem "sprockets-rails", "~> 2.3.0"
3+
gem "sprockets-rails", "~> 2.3.3"
44

55
# Specify your gem's dependencies in sassc-rails.gemspec
66
gemspec path: "../"

gemfiles/sprockets_2_12.gemfile

-6
This file was deleted.

gemfiles/with_sass_rails.gemfile

-6
This file was deleted.

lib/sassc-rails.rb

-6
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,4 @@
11
# frozen_string_literal: true
22

3-
begin
4-
require "sass-rails"
5-
Rails::Railtie.subclasses.delete Sass::Rails::Railtie
6-
rescue LoadError
7-
end
8-
93
require_relative "sassc/rails"
104

lib/sassc/rails/compressor.rb

+11
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,19 @@
11
# frozen_string_literal: true
22

33
require 'sprockets/sass_compressor'
4+
require 'securerandom'
45

56
class Sprockets::SassCompressor
7+
def initialize(options = {})
8+
@options = {
9+
syntax: :scss,
10+
cache: false,
11+
read_cache: false,
12+
style: :compressed
13+
}.merge(options).freeze
14+
@cache_key = SecureRandom.uuid
15+
end
16+
617
def call(*args)
718
input = if defined?(data)
819
data # sprockets 2.x

lib/sassc/rails/template.rb

+56-69
Original file line numberDiff line numberDiff line change
@@ -1,73 +1,46 @@
11
# frozen_string_literal: true
22

33
require "sprockets/version"
4-
5-
begin
6-
require 'sprockets/sass_processor'
7-
rescue LoadError
8-
require "sprockets/sass_template"
9-
end
10-
4+
require 'sprockets/sass_processor'
115
require "sprockets/utils"
126

137
module SassC::Rails
14-
15-
class SassTemplate < defined?(Sprockets::SassProcessor) ? Sprockets::SassProcessor : Sprockets::SassTemplate
16-
module Sprockets3
17-
def call(input)
18-
context = input[:environment].context_class.new(input)
19-
20-
options = {
21-
filename: input[:filename],
22-
line_comments: line_comments?,
23-
syntax: self.class.syntax,
24-
load_paths: input[:environment].paths,
25-
importer: SassC::Rails::Importer,
26-
sprockets: {
27-
context: context,
28-
environment: input[:environment],
29-
dependencies: context.metadata[:dependency_paths]
30-
}
31-
}.merge(config_options) { |*args| safe_merge(*args) }
32-
33-
engine = ::SassC::Engine.new(input[:data], options)
34-
35-
css = Sprockets::Utils.module_include(::SassC::Script::Functions, @functions) do
36-
engine.render
37-
end
38-
39-
context.metadata.merge(data: css)
8+
class SassTemplate < Sprockets::SassProcessor
9+
def initialize(options = {}, &block)
10+
@cache_version = options[:cache_version]
11+
@cache_key = "#{self.class.name}:#{VERSION}:#{SassC::VERSION}:#{@cache_version}".freeze
12+
#@importer_class = options[:importer] || Sass::Importers::Filesystem
13+
@sass_config = options[:sass_config] || {}
14+
@functions = Module.new do
15+
include Functions
16+
include options[:functions] if options[:functions]
17+
class_eval(&block) if block_given?
4018
end
4119
end
4220

43-
module Sprockets2
44-
def self.included(base)
45-
base.class_eval do
46-
self.default_mime_type = "text/css"
47-
end
21+
def call(input)
22+
context = input[:environment].context_class.new(input)
23+
24+
options = {
25+
filename: input[:filename],
26+
line_comments: line_comments?,
27+
syntax: self.class.syntax,
28+
load_paths: input[:environment].paths,
29+
importer: SassC::Rails::Importer,
30+
sprockets: {
31+
context: context,
32+
environment: input[:environment],
33+
dependencies: context.metadata[:dependency_paths]
34+
}
35+
}.merge(config_options) { |*args| safe_merge(*args) }
36+
37+
engine = ::SassC::Engine.new(input[:data], options)
38+
39+
css = Sprockets::Utils.module_include(::SassC::Script::Functions, @functions) do
40+
engine.render
4841
end
4942

50-
def evaluate(context, locals, &block)
51-
options = {
52-
filename: eval_file,
53-
line_comments: line_comments?,
54-
syntax: syntax,
55-
load_paths: context.environment.paths,
56-
importer: SassC::Rails::Importer,
57-
sprockets: {
58-
context: context,
59-
environment: context.environment
60-
}
61-
}.merge(config_options, &method(:safe_merge))
62-
63-
::SassC::Engine.new(data, options).render
64-
end
65-
end
66-
67-
if Sprockets::VERSION > "3.0.0"
68-
include Sprockets3
69-
else
70-
include Sprockets2
43+
context.metadata.merge(data: css)
7144
end
7245

7346
def config_options
@@ -106,20 +79,34 @@ def safe_merge(key, left, right)
10679
right
10780
end
10881
end
109-
end
11082

111-
class ScssTemplate < SassTemplate
112-
unless Sprockets::VERSION > "3.0.0"
113-
self.default_mime_type = 'text/css'
114-
end
83+
# The methods in the Functions module were copied here from sprockets in order to
84+
# override the Value class names (e.g. ::SassC::Script::Value::String)
85+
module Functions
86+
def asset_path(path, options = {})
87+
path = path.value
11588

116-
# Sprockets 3
117-
def self.syntax
118-
:scss
89+
path, _, query, fragment = URI.split(path)[5..8]
90+
path = sprockets_context.asset_path(path, options)
91+
query = "?#{query}" if query
92+
fragment = "##{fragment}" if fragment
93+
94+
::SassC::Script::Value::String.new("#{path}#{query}#{fragment}", :string)
95+
end
96+
97+
def asset_url(path, options = {})
98+
::SassC::Script::Value::String.new("url(#{asset_path(path, options).value})")
99+
end
100+
101+
def asset_data_url(path)
102+
url = sprockets_context.asset_data_uri(path.value)
103+
::SassC::Script::Value::String.new("url(" + url + ")")
104+
end
119105
end
106+
end
120107

121-
# Sprockets 2
122-
def syntax
108+
class ScssTemplate < SassTemplate
109+
def self.syntax
123110
:scss
124111
end
125112
end

lib/sassc/rails/version.rb

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,6 @@
22

33
module SassC
44
module Rails
5-
VERSION = "1.3.0"
5+
VERSION = "2.0.0"
66
end
77
end

sassc-rails.gemspec

+2-6
Original file line numberDiff line numberDiff line change
@@ -23,14 +23,10 @@ Gem::Specification.new do |spec|
2323
spec.add_development_dependency "rake", "~> 10.0"
2424
spec.add_development_dependency 'mocha'
2525

26-
# Unfortunately we require sass for now, so that we can
27-
# reuse portions of the Sprockets template
28-
spec.add_dependency 'sass'
29-
spec.add_dependency "sassc", "~> 1.9"
30-
26+
spec.add_dependency "sassc", ">= 2.0"
3127
spec.add_dependency "tilt"
3228

3329
spec.add_dependency 'railties', '>= 4.0.0'
34-
spec.add_dependency 'sprockets', '> 2.11'
30+
spec.add_dependency 'sprockets', '> 3.0'
3531
spec.add_dependency 'sprockets-rails'
3632
end

test/sassc_rails_test.rb

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
require "test_helper"
44

5-
class SassRailsTest < MiniTest::Unit::TestCase
5+
class SassRailsTest < MiniTest::Test
66
attr_reader :app
77

88
def setup

test/test_helper.rb

+1-1
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
require 'rails'
1111
require 'bundler/setup'
1212
require "minitest/autorun"
13-
require 'mocha/mini_test'
13+
require 'mocha/minitest'
1414

1515
Bundler.require
1616

0 commit comments

Comments
 (0)