Skip to content

Commit

Permalink
Merge pull request #65 from schneems/schneems/sprockets4
Browse files Browse the repository at this point in the history
Sprockets 4 Compatibility
  • Loading branch information
bolandrm authored Jul 7, 2016
2 parents 6a00d20 + d69fda1 commit a7e1b5f
Show file tree
Hide file tree
Showing 6 changed files with 41 additions and 19 deletions.
1 change: 1 addition & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ script: "bundle exec rake test"
gemfile:
- gemfiles/sprockets_2_12.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
Expand Down
1 change: 1 addition & 0 deletions Rakefile
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ task :test do
$LOAD_PATH.unshift('lib', 'test')
Dir.glob('./test/**/*_test.rb') { |f| require f }
end
task :default => [:test]

namespace :tests do
gemfiles = %w[
Expand Down
6 changes: 6 additions & 0 deletions gemfiles/sprockets_4_0.gemfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
source 'https://rubygems.org'

gem "sprockets", "~> 4.0.x"

# Specify your gem's dependencies in sassc-rails.gemspec
gemspec path: "../"
11 changes: 9 additions & 2 deletions lib/sassc/rails/railtie.rb
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,15 @@ class Railtie < ::Rails::Railtie
self.sass_config = app.config.sass
end

env.register_engine '.sass', SassC::Rails::SassTemplate
env.register_engine '.scss', SassC::Rails::ScssTemplate
if env.respond_to?(:register_transformer)
env.register_transformer 'text/sass', 'text/css', SassC::Rails::SassTemplate.new #->() { puts "yoyoyoy" }
env.register_transformer 'text/scss', 'text/css', SassC::Rails::ScssTemplate.new #->() { puts "yoyoyoy" }
end

if env.respond_to?(:register_engine)
env.register_engine '.sass', SassC::Rails::SassTemplate
env.register_engine '.scss', SassC::Rails::ScssTemplate
end
end
end

Expand Down
11 changes: 9 additions & 2 deletions lib/sassc/rails/template.rb
Original file line number Diff line number Diff line change
@@ -1,9 +1,16 @@
require "sprockets/version"
require "sprockets/sass_template"

begin
require 'sprockets/sass_processor'
rescue LoadError
require "sprockets/sass_template"
end

require "sprockets/utils"

module SassC::Rails
class SassTemplate < Sprockets::SassTemplate

class SassTemplate < defined?(Sprockets::SassProcessor) ? Sprockets::SassProcessor : Sprockets::SassTemplate
module Sprockets3
def call(input)
context = input[:environment].context_class.new(input)
Expand Down
30 changes: 15 additions & 15 deletions test/sassc_rails_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ def initialize_prod!
def test_setup_works
initialize_dev!

asset = render_asset("application.scss")
asset = render_asset("application.css")

assert_equal <<-CSS, asset
.hello {
Expand All @@ -67,7 +67,7 @@ def test_raises_sassc_syntax_error
initialize!

assert_raises(SassC::SyntaxError) do
render_asset("syntax_error.scss")
render_asset("syntax_error.css")
end
end

Expand All @@ -76,7 +76,7 @@ def test_all_sass_asset_paths_work

initialize!

css_output = render_asset("helpers_test.scss")
css_output = render_asset("helpers_test.css")

assert_match %r{asset-path:\s*"/assets/rails.png"}, css_output, 'asset-path:\s*"/assets/rails.png"'
assert_match %r{asset-url:\s*url\(/assets/rails.png\)}, css_output, 'asset-url:\s*url\(/assets/rails.png\)'
Expand All @@ -87,7 +87,7 @@ def test_all_sass_asset_paths_work
def test_sass_asset_paths_work
initialize!

css_output = render_asset("helpers_test.scss")
css_output = render_asset("helpers_test.css")

assert_match %r{video-path:\s*"/videos/rails.mp4"}, css_output, 'video-path:\s*"/videos/rails.mp4"'
assert_match %r{video-url:\s*url\(/videos/rails.mp4\)}, css_output, 'video-url:\s*url\(/videos/rails.mp4\)'
Expand Down Expand Up @@ -118,7 +118,7 @@ def test_sass_asset_paths_work
def test_sass_imports_work_correctly
initialize!

css_output = render_asset("imports_test.scss")
css_output = render_asset("imports_test.css")
assert_match /main/, css_output
assert_match /top-level/, css_output
assert_match /partial-sass/, css_output
Expand Down Expand Up @@ -162,7 +162,7 @@ def test_line_comments_active_in_dev
@app.config.sass.line_comments = true
initialize_dev!

css_output = render_asset("css_scss_handler.css.scss")
css_output = render_asset("css_scss_handler.css")
assert_match %r{/* line 1}, css_output
assert_match %r{.+/sassc-rails/test/dummy/app/assets/stylesheets/css_scss_handler.css.scss}, css_output
end
Expand All @@ -176,7 +176,7 @@ def test_context_is_being_passed_to_erb_render

def test_special_characters_compile
initialize!
css_output = render_asset("special_characters.scss")
css_output = render_asset("special_characters.css")
end

def test_css_compressor_config_item_is_honored_if_not_development_mode
Expand Down Expand Up @@ -204,7 +204,7 @@ def test_css_compressor_is_defined_in_prod_mode
def test_compression_works
initialize_prod!

asset = render_asset("application.scss")
asset = render_asset("application.css")
assert_equal <<-CSS, asset
.hello{color:#FFF}
CSS
Expand All @@ -213,7 +213,7 @@ def test_compression_works
def test_compression_works
initialize_prod!

asset = render_asset("application.scss")
asset = render_asset("application.css")
assert_equal <<-CSS, asset
.hello{color:#FFF}
CSS
Expand All @@ -226,14 +226,14 @@ def test_sassc_compression_is_used

initialize_prod!

render_asset("application.scss")
render_asset("application.css")
end

def test_allows_for_inclusion_of_inline_source_maps
@app.config.sass.inline_source_maps = true
initialize_dev!

asset = render_asset("application.scss")
asset = render_asset("application.css")
assert_match /.hello/, asset
assert_match /sourceMappingURL/, asset
end
Expand Down Expand Up @@ -278,14 +278,14 @@ def test_globbed_imports_work_when_globbed_file_is_changed
file.puts '.new-file-test { color: #000; }'
end

css_output = render_asset("glob_test.scss")
css_output = render_asset("glob_test.css")
assert_match /new-file-test/, css_output

File.open(new_file, 'w') do |file|
file.puts '.changed-file-test { color: #000; }'
end

new_css_output = render_asset("glob_test.scss")
new_css_output = render_asset("glob_test.css")
assert_match /changed-file-test/, new_css_output
refute_equal css_output, new_css_output
ensure
Expand All @@ -297,15 +297,15 @@ def test_globbed_imports_work_when_globbed_file_is_added
begin
initialize!

css_output = render_asset("glob_test.scss")
css_output = render_asset("glob_test.css")
refute_match /changed-file-test/, css_output
new_file = File.join(File.dirname(__FILE__), 'dummy', 'app', 'assets', 'stylesheets', 'globbed', 'new_glob.scss')

File.open(new_file, 'w') do |file|
file.puts '.changed-file-test { color: #000; }'
end

new_css_output = render_asset("glob_test.scss")
new_css_output = render_asset("glob_test.css")
assert_match /changed-file-test/, new_css_output
refute_equal css_output, new_css_output
ensure
Expand Down

0 comments on commit a7e1b5f

Please sign in to comment.