Build Sass configuration options.
This commit is contained in:
parent
22d4e2aa90
commit
4784d1de18
|
@ -11,8 +11,12 @@ module Jekyll
|
|||
".css"
|
||||
end
|
||||
|
||||
def user_sass_configs
|
||||
@config["sass"] || {}
|
||||
end
|
||||
|
||||
def sass_build_configuration_options(overrides)
|
||||
(@config["sass"] || {}).deep_merge(overrides).symbolize_keys
|
||||
user_sass_configs.deep_merge(overrides).symbolize_keys
|
||||
end
|
||||
|
||||
def syntax_type_of_content(content)
|
||||
|
@ -24,25 +28,26 @@ module Jekyll
|
|||
end
|
||||
|
||||
def sass_dir
|
||||
@config["source"]["sass"]["sass_dir"] || "_sass"
|
||||
user_sass_configs["sass_dir"] || "_sass"
|
||||
end
|
||||
|
||||
def sass_dir_relative_to_site_source
|
||||
File.join(
|
||||
@config["source"],
|
||||
File.expand_path("/", sass_dir)
|
||||
File.expand_path(sass_dir, "/")
|
||||
)
|
||||
end
|
||||
|
||||
def convert(content)
|
||||
syntax = syntax_type_of_content(content)
|
||||
configs = sass_build_configuration_options({
|
||||
def sass_configs(content = "")
|
||||
sass_build_configuration_options({
|
||||
"syntax" => syntax_type_of_content(content),
|
||||
"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
|
||||
|
|
|
@ -1,38 +1,93 @@
|
|||
require 'helper'
|
||||
|
||||
class TestSass < Test::Unit::TestCase
|
||||
context "converting sass" do
|
||||
setup do
|
||||
@content = <<-SASS
|
||||
def site_configuration(overrides = {})
|
||||
Jekyll::Configuration::DEFAULTS.deep_merge(overrides).deep_merge({
|
||||
"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
|
||||
body
|
||||
font-family: $font-stack
|
||||
font-color: fuschia
|
||||
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
|
||||
def scss_content
|
||||
<<-SCSS
|
||||
$font-stack: Helvetica, sans-serif;
|
||||
body {
|
||||
font-family: $font-stack;
|
||||
font-color: fuschia;
|
||||
}
|
||||
SCSS
|
||||
@output = <<-CSS
|
||||
end
|
||||
|
||||
def css_output
|
||||
<<-CSS
|
||||
body {\n font-family: Helvetica, sans-serif;\n font-color: fuschia; }
|
||||
CSS
|
||||
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
|
||||
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
|
||||
|
|
Loading…
Reference in New Issue