Skip to content

Commit

Permalink
Migrate to sassc gem
Browse files Browse the repository at this point in the history
  • Loading branch information
pathawks committed Jul 21, 2018
1 parent 5f7ca51 commit 46a91b1
Show file tree
Hide file tree
Showing 6 changed files with 10 additions and 9 deletions.
2 changes: 1 addition & 1 deletion jekyll-sass-converter.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ Gem::Specification.new do |spec|

spec.required_ruby_version = ">= 2.3.0"

spec.add_runtime_dependency "sass", "~> 3.4"
spec.add_runtime_dependency "sassc", "~> 1.12"

spec.add_development_dependency "bundler", "~> 1.15"
spec.add_development_dependency "jekyll", "~> 3.0"
Expand Down
2 changes: 1 addition & 1 deletion lib/jekyll-sass-converter/version.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# frozen_string_literal: true

module JekyllSassConverter
VERSION = "1.5.2"
VERSION = "2.0.0"
end
2 changes: 1 addition & 1 deletion lib/jekyll/converters/sass.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# frozen_string_literal: true

require "sass"
require "sassc"
require "jekyll/utils"
require "jekyll/converters/scss"

Expand Down
9 changes: 5 additions & 4 deletions lib/jekyll/converters/scss.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# frozen_string_literal: true

require "sass"
require "sassc"
require "jekyll/utils"

module Jekyll
Expand Down Expand Up @@ -116,11 +116,12 @@ def sass_configs
end

def convert(content)
output = ::Sass.compile(content, sass_configs)
output = ::SassC::Engine.new(content.dup, sass_configs).render
replacement = add_charset? ? '@charset "UTF-8";' : ""
output.sub(BYTE_ORDER_MARK, replacement)
rescue ::Sass::SyntaxError => e
raise SyntaxError, "#{e} on line #{e.sass_line}"
rescue ::SassC::SyntaxError => e
line = e.instance_variable_get(:@line)
raise SyntaxError, "#{e} on line #{line}"
end

private
Expand Down
2 changes: 1 addition & 1 deletion spec/sass_converter_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ def converter(overrides = {})
end

it "includes the syntax error line in the syntax error message" do
error_message = "Invalid CSS after \"$font-stack\": expected expression (e.g. 1px, bold), was \";\" on line 1"
error_message = %r!\AInvalid CSS after "f": expected 1 selector or at-rule. was "font-family: \$font-"\s+on line 1 of stdin!
expect do
converter.convert(invalid_content)
end.to raise_error(Jekyll::Converters::Scss::SyntaxError, error_message)
Expand Down
2 changes: 1 addition & 1 deletion spec/scss_converter_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ def converter(overrides = {})
end

it "includes the syntax error line in the syntax error message" do
error_message = 'Invalid CSS after "body ": expected selector or at-rule, was "{" on line 2'
error_message = %r!\AError: Invalid CSS after "body": expected 1 selector or at-rule, was "{"\s+on line 2!
expect do
converter.convert(invalid_content)
end.to raise_error(Jekyll::Converters::Scss::SyntaxError, error_message)
Expand Down

0 comments on commit 46a91b1

Please sign in to comment.