Build Sass configuration options.

This commit is contained in:
Parker Moore 2014-01-12 15:28:53 -08:00
parent 22d4e2aa90
commit 4784d1de18
2 changed files with 84 additions and 24 deletions

View File

@ -11,8 +11,12 @@ module Jekyll
".css" ".css"
end end
def user_sass_configs
@config["sass"] || {}
end
def sass_build_configuration_options(overrides) def sass_build_configuration_options(overrides)
(@config["sass"] || {}).deep_merge(overrides).symbolize_keys user_sass_configs.deep_merge(overrides).symbolize_keys
end end
def syntax_type_of_content(content) def syntax_type_of_content(content)
@ -24,25 +28,26 @@ module Jekyll
end end
def sass_dir def sass_dir
@config["source"]["sass"]["sass_dir"] || "_sass" user_sass_configs["sass_dir"] || "_sass"
end end
def sass_dir_relative_to_site_source def sass_dir_relative_to_site_source
File.join( File.join(
@config["source"], @config["source"],
File.expand_path("/", sass_dir) File.expand_path(sass_dir, "/")
) )
end end
def convert(content) def sass_configs(content = "")
syntax = syntax_type_of_content(content) sass_build_configuration_options({
configs = sass_build_configuration_options({
"syntax" => syntax_type_of_content(content), "syntax" => syntax_type_of_content(content),
"cache" => false, "cache" => false,
"filesystem_importer" => NilClass, "load_paths" => [sass_dir_relative_to_site_source]
"load_paths" => sass_dir_relative_to_site_source
}) })
::Sass.compile(content, configs) end
def convert(content)
::Sass.compile(content, sass_configs(content))
end end
end end
end end

View File

@ -1,38 +1,93 @@
require 'helper' require 'helper'
class TestSass < Test::Unit::TestCase class TestSass < Test::Unit::TestCase
context "converting sass" do def site_configuration(overrides = {})
setup do Jekyll::Configuration::DEFAULTS.deep_merge(overrides).deep_merge({
@content = <<-SASS "source" => source_dir,
"destination" => dest_dir
})
end
def converter(overrides = {})
Jekyll::Sass.new(site_configuration({"sass" => overrides}))
end
def sass_content
<<-SASS
$font-stack: Helvetica, sans-serif $font-stack: Helvetica, sans-serif
body body
font-family: $font-stack font-family: $font-stack
font-color: fuschia font-color: fuschia
SASS 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 end
context "converting SCSS" do def scss_content
setup do <<-SCSS
@content = <<-SCSS
$font-stack: Helvetica, sans-serif; $font-stack: Helvetica, sans-serif;
body { body {
font-family: $font-stack; font-family: $font-stack;
font-color: fuschia; font-color: fuschia;
} }
SCSS SCSS
@output = <<-CSS end
def css_output
<<-CSS
body {\n font-family: Helvetica, sans-serif;\n font-color: fuschia; } body {\n font-family: Helvetica, sans-serif;\n font-color: fuschia; }
CSS CSS
end end
context "matching file extensions" do
should "match .scss files" do
assert converter.matches(".scss")
end
should "match .sass files" do
assert converter.matches(".sass")
end
end
context "determining the output file extension" do
should "output .css file extension" do
assert_equal ".css", converter.output_ext(".sass")
end
end
context "when building configurations" do
should "not allow caching" do
assert_equal false, converter.sass_configs[:cache]
end
should "set the load paths to the _sass dir relative to site source" do
assert_equal [source_dir("_sass")], converter.sass_configs[:load_paths]
end
should "allow the user to specify a different sass dir" do
assert_equal [source_dir("_scss")], converter({"sass_dir" => "_scss"}).sass_configs[:load_paths]
end
should "set syntax :scss when SCSS content" do
assert_equal :scss, converter.sass_configs(scss_content)[:syntax]
end
should "set syntax :sass when Sass content" do
assert_equal :sass, converter.sass_configs(sass_content)[:syntax]
end
should "default to :sass syntax when content is empty" do
assert_equal :sass, converter.sass_configs[:syntax]
end
end
context "converting sass" do
should "produce CSS" do should "produce CSS" do
assert_equal @output, Jekyll::Sass.new.convert(@content) assert_equal css_output, converter.convert(sass_content)
end
end
context "converting SCSS" do
should "produce CSS" do
assert_equal css_output, converter.convert(scss_content)
end end
end end
end end