From 22d4e2aa9005305c727b9bc110af928d8eb78a6d Mon Sep 17 00:00:00 2001 From: Parker Moore Date: Sun, 12 Jan 2014 14:58:17 -0800 Subject: [PATCH] Consolidate into one master 'Sass' converter. --- lib/jekyll/converters/sass.rb | 32 +++++++++++++++++++++++++++++--- lib/jekyll/converters/scss.rb | 18 ------------------ test/test_sass.rb | 18 ++++++++++++++++++ test/test_scss.rb | 21 --------------------- 4 files changed, 47 insertions(+), 42 deletions(-) delete mode 100644 lib/jekyll/converters/scss.rb delete mode 100644 test/test_scss.rb diff --git a/lib/jekyll/converters/sass.rb b/lib/jekyll/converters/sass.rb index 6cb2ff67..177b62e6 100644 --- a/lib/jekyll/converters/sass.rb +++ b/lib/jekyll/converters/sass.rb @@ -4,7 +4,7 @@ module Jekyll priority :low def matches(ext) - ext =~ /^\.sass$/i + ext =~ /^\.s(a|c)ss$/i end def output_ext(ext) @@ -12,11 +12,37 @@ module Jekyll end def sass_build_configuration_options(overrides) - (@config["sass"] || {}).deep_merge(overrides) + (@config["sass"] || {}).deep_merge(overrides).symbolize_keys + end + + def syntax_type_of_content(content) + if content.include?(";") || content.include?("{") + :scss + else + :sass + end + end + + def sass_dir + @config["source"]["sass"]["sass_dir"] || "_sass" + end + + def sass_dir_relative_to_site_source + File.join( + @config["source"], + File.expand_path("/", sass_dir) + ) end def convert(content) - ::Sass.compile(content, sass_build_configuration_options({"syntax" => :sass})) + syntax = syntax_type_of_content(content) + configs = sass_build_configuration_options({ + "syntax" => syntax_type_of_content(content), + "cache" => false, + "filesystem_importer" => NilClass, + "load_paths" => sass_dir_relative_to_site_source + }) + ::Sass.compile(content, configs) end end end diff --git a/lib/jekyll/converters/scss.rb b/lib/jekyll/converters/scss.rb deleted file mode 100644 index 27a4e85f..00000000 --- a/lib/jekyll/converters/scss.rb +++ /dev/null @@ -1,18 +0,0 @@ -module Jekyll - class Scss < Converter - safe true - priority :low - - def matches(ext) - ext =~ /^\.scss$/i - end - - def output_ext(ext) - ".css" - end - - def convert(content) - ::Sass.compile(content, :syntax => :scss) - end - end -end diff --git a/test/test_sass.rb b/test/test_sass.rb index 0fa44d21..aa57f874 100644 --- a/test/test_sass.rb +++ b/test/test_sass.rb @@ -11,6 +11,24 @@ body SASS @output = <<-CSS body {\n font-family: Helvetica, sans-serif;\n font-color: fuschia; } +CSS + end + should "produce CSS" do + assert_equal @output, Jekyll::Sass.new.convert(@content) + end + end + + context "converting SCSS" do + setup do + @content = <<-SCSS +$font-stack: Helvetica, sans-serif; +body { + font-family: $font-stack; + font-color: fuschia; +} +SCSS + @output = <<-CSS +body {\n font-family: Helvetica, sans-serif;\n font-color: fuschia; } CSS end should "produce CSS" do diff --git a/test/test_scss.rb b/test/test_scss.rb deleted file mode 100644 index dbc40d83..00000000 --- a/test/test_scss.rb +++ /dev/null @@ -1,21 +0,0 @@ -require 'helper' - -class TestSass < Test::Unit::TestCase - context "converting SCSS" do - setup do - @content = <<-SCSS -$font-stack: Helvetica, sans-serif; -body { - font-family: $font-stack; - font-color: fuschia; -} -SCSS - @output = <<-CSS -body {\n font-family: Helvetica, sans-serif;\n font-color: fuschia; } -CSS - end - should "produce CSS" do - assert_equal @output, Jekyll::Scss.new.convert(@content) - end - end -end