Consolidate into one master 'Sass' converter.

This commit is contained in:
Parker Moore 2014-01-12 14:58:17 -08:00
parent daa0b76484
commit 22d4e2aa90
4 changed files with 47 additions and 42 deletions

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -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