Skip to content

Commit

Permalink
Make sass-rails an wrapper for sassc-rails to allow a smooth upgrade …
Browse files Browse the repository at this point in the history
…path
  • Loading branch information
guilleiguaran committed Mar 16, 2019
1 parent ac38f1e commit 706526d
Show file tree
Hide file tree
Showing 247 changed files with 9 additions and 4,805 deletions.
65 changes: 0 additions & 65 deletions .travis.yml

This file was deleted.

6 changes: 0 additions & 6 deletions Gemfile
Expand Up @@ -2,9 +2,3 @@ source "https://rubygems.org"

# Specify your gem's dependencies in sass-rails.gemspec
gemspec

gem "rails", github: "rails/rails"
gem "arel", github: "rails/arel"
gem "rack", github: "rack/rack"
gem "sprockets", github: "rails/sprockets", branch: "master"
gem "sprockets-rails", github: "rails/sprockets-rails", branch: "master"
2 changes: 1 addition & 1 deletion MIT-LICENSE
@@ -1,4 +1,4 @@
Copyright (c) 2011-2016 Christopher Eppstein
Copyright (c) 2011-2019 Christopher Eppstein

Permission is hereby granted, free of charge, to any person obtaining
a copy of this software and associated documentation files (the
Expand Down
12 changes: 0 additions & 12 deletions Rakefile
@@ -1,14 +1,2 @@
require 'bundler'
Bundler::GemHelper.install_tasks

require 'rake/testtask'

Rake::TestTask.new(:test) do |t|
t.libs << 'lib'
t.libs << 'test'
t.pattern = 'test/**/*_test.rb'
t.verbose = false
end

desc 'Default: run unit tests.'
task default: :test
11 changes: 0 additions & 11 deletions gemfiles/Gemfile-rails-4-2

This file was deleted.

8 changes: 0 additions & 8 deletions gemfiles/Gemfile-rails-5-0

This file was deleted.

8 changes: 0 additions & 8 deletions gemfiles/Gemfile-rails-5-1

This file was deleted.

8 changes: 0 additions & 8 deletions gemfiles/Gemfile-rails-edge

This file was deleted.

13 changes: 0 additions & 13 deletions lib/rails/generators/sass/assets/assets_generator.rb

This file was deleted.

3 changes: 0 additions & 3 deletions lib/rails/generators/sass/assets/templates/stylesheet.sass

This file was deleted.

9 changes: 0 additions & 9 deletions lib/rails/generators/sass/scaffold/scaffold_generator.rb

This file was deleted.

15 changes: 0 additions & 15 deletions lib/rails/generators/sass_scaffold.rb

This file was deleted.

13 changes: 0 additions & 13 deletions lib/rails/generators/scss/assets/assets_generator.rb

This file was deleted.

3 changes: 0 additions & 3 deletions lib/rails/generators/scss/assets/templates/stylesheet.scss

This file was deleted.

10 changes: 0 additions & 10 deletions lib/rails/generators/scss/scaffold/scaffold_generator.rb

This file was deleted.

2 changes: 1 addition & 1 deletion lib/sass-rails.rb
@@ -1 +1 @@
require 'sass/rails'
require 'sassc/rails'
10 changes: 1 addition & 9 deletions lib/sass/rails.rb
@@ -1,9 +1 @@
module Sass
module Rails
autoload :Logger, 'sass/rails/logger'
end
end

require 'sass/rails/version'
require 'sass/rails/importer'
require 'sass/rails/railtie'
require 'sassc/rails'
159 changes: 1 addition & 158 deletions lib/sass/rails/importer.rb
@@ -1,158 +1 @@
require 'active_support/deprecation/reporting'
require 'sass/importers'
require 'sprockets/file_reader'
require 'sprockets/erb_processor'
require 'sprockets/processor_utils'

module Sass
module Rails
class SassImporter < Sass::Importers::Filesystem
module Globbing
GLOB = /(\A|\/)(\*|\*\*\/\*)\z/

def find_relative(name, base, options)
if options[:sprockets] && m = name.match(GLOB)
path = name.sub(m[0], "")
base = File.expand_path(path, File.dirname(base))
glob_imports(base, m[2], options)
else
super
end
end

def find(name, options)
# globs must be relative
return if name =~ GLOB
super
end

private
def glob_imports(base, glob, options)
contents = ""
context = options[:sprockets][:context]
each_globbed_file(base, glob, context) do |filename|
next if filename == options[:filename]
contents << "@import #{filename.inspect};\n"
end
return nil if contents == ""
Sass::Engine.new(contents, options.merge(
:filename => base,
:importer => self,
:syntax => :scss
))
end

def each_globbed_file(base, glob, context)
raise ArgumentError unless glob == "*" || glob == "**/*"

exts = extensions.keys.map { |ext| Regexp.escape(".#{ext}") }.join("|")
sass_re = Regexp.compile("(#{exts})$")

context.depend_on(base)

Dir["#{base}/#{glob}"].sort.each do |path|
if File.directory?(path)
context.depend_on(path)
elsif sass_re =~ path
yield path
end
end
end
end

module ERB
def extensions
{
'css.erb' => :scss_erb,
'scss.erb' => :scss_erb,
'sass.erb' => :sass_erb
}.merge(super)
end

def erb_extensions
{
:scss_erb => :scss,
:sass_erb => :sass
}
end

def find_relative(*args)
process_erb_engine(super)
end

def find(*args)
process_erb_engine(super)
end

private
def process_erb_engine(engine)
if engine && engine.options[:sprockets] && syntax = erb_extensions[engine.options[:syntax]]
context = engine.options[:sprockets][:context]

input = {
filename: engine.options[:filename],
environment: context.environment,
content_type: "text/#{syntax}",
metadata: {}
}

processors = [Sprockets::ERBProcessor, Sprockets::FileReader]

result = Sprockets::ProcessorUtils.call_processors(processors, input)

Sass::Engine.new(result[:data], engine.options.merge(:syntax => syntax))
else
engine
end
end
end

module Deprecated
def extensions
{
'css.scss' => :scss,
'css.sass' => :sass,
'css.scss.erb' => :scss_erb,
'css.sass.erb' => :sass_erb
}.merge(super)
end

def find_relative(*args)
deprecate_extra_css_extension(super)
end

def find(*args)
deprecate_extra_css_extension(super)
end

private
def deprecate_extra_css_extension(engine)
if engine && filename = engine.options[:filename]
if filename.end_with?('.css.scss')
msg = "Extra .css in SCSS file is unnecessary. Rename #{filename} to #{filename.sub('.css.scss', '.scss')}."
elsif filename.end_with?('.css.sass')
msg = "Extra .css in SASS file is unnecessary. Rename #{filename} to #{filename.sub('.css.sass', '.sass')}."
elsif filename.end_with?('.css.scss.erb')
msg = "Extra .css in SCSS/ERB file is unnecessary. Rename #{filename} to #{filename.sub('.css.scss.erb', '.scss.erb')}."
elsif filename.end_with?('.css.sass.erb')
msg = "Extra .css in SASS/ERB file is unnecessary. Rename #{filename} to #{filename.sub('.css.sass.erb', '.sass.erb')}."
end

ActiveSupport::Deprecation.warn(msg) if msg
end

engine
end
end

include ERB
include Deprecated
include Globbing

# Allow .css files to be @import'd
def extensions
{ 'css' => :scss }.merge(super)
end
end
end
end
require 'sassc/rails/importer'

0 comments on commit 706526d

Please sign in to comment.