Skip to content

Commit

Permalink
Merge pull request #109 from sass/rmb/drop_sass
Browse files Browse the repository at this point in the history
drop ruby sass requirement
  • Loading branch information
bolandrm committed Oct 30, 2018
2 parents bfca465 + c314d1c commit f5ab1cb
Show file tree
Hide file tree
Showing 15 changed files with 84 additions and 114 deletions.
11 changes: 5 additions & 6 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
6 changes: 2 additions & 4 deletions Rakefile
Original file line number Diff line number Diff line change
Expand Up @@ -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|
Expand Down
6 changes: 0 additions & 6 deletions gemfiles/rails_4_1.gemfile

This file was deleted.

2 changes: 1 addition & 1 deletion gemfiles/rails_4_0.gemfile → gemfiles/rails_5_2.gemfile
Original file line number Diff line number Diff line change
@@ -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: "../"
2 changes: 1 addition & 1 deletion gemfiles/sprockets-rails_2_3.gemfile
Original file line number Diff line number Diff line change
@@ -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: "../"
6 changes: 0 additions & 6 deletions gemfiles/sprockets_2_12.gemfile

This file was deleted.

6 changes: 0 additions & 6 deletions gemfiles/with_sass_rails.gemfile

This file was deleted.

6 changes: 0 additions & 6 deletions lib/sassc-rails.rb
Original file line number Diff line number Diff line change
@@ -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"

11 changes: 11 additions & 0 deletions lib/sassc/rails/compressor.rb
Original file line number Diff line number Diff line change
@@ -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
Expand Down
125 changes: 56 additions & 69 deletions lib/sassc/rails/template.rb
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion lib/sassc/rails/version.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,6 @@

module SassC
module Rails
VERSION = "1.3.0"
VERSION = "2.0.0"
end
end
8 changes: 2 additions & 6 deletions sassc-rails.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -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
2 changes: 1 addition & 1 deletion test/sassc_rails_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

require "test_helper"

class SassRailsTest < MiniTest::Unit::TestCase
class SassRailsTest < MiniTest::Test
attr_reader :app

def setup
Expand Down
2 changes: 1 addition & 1 deletion test/test_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
require 'rails'
require 'bundler/setup'
require "minitest/autorun"
require 'mocha/mini_test'
require 'mocha/minitest'

Bundler.require

Expand Down

0 comments on commit f5ab1cb

Please sign in to comment.