Merge pull request #1114 from mojombo/backwards-compatibilize-exclude-include

Backwards-compatibilize 'exclude' and 'include' config tags
This commit is contained in:
Matt Rogers 2013-05-17 19:56:48 -07:00
commit ddba4cde8b
2 changed files with 40 additions and 3 deletions

View File

@ -145,6 +145,15 @@ module Jekyll
configuration.backwards_compatibilize
end
# Public: Split a CSV string into an array containing its values
#
# csv - the string of comma-separated values
#
# Returns an array of the values contained in the CSV
def csv_to_array(csv)
csv.split(",").map(&:strip)
end
# Public: Ensure the proper options are set in the configuration to allow for
# backwards-compatibility with Jekyll pre-1.0
#
@ -176,6 +185,22 @@ module Jekyll
config.delete('server_port')
end
if config.has_key?('exclude') && config['exclude'].is_a?(String)
Jekyll::Stevenson.warn "Deprecation:", "The 'exclude' configuration option" +
" must now be specified as an array, but you specified" +
" a string. For now, we've treated the string you provided" +
" as a list of comma-separated values."
config['exclude'] = csv_to_array(config['exclude'])
end
if config.has_key?('include') && config['include'].is_a?(String)
Jekyll::Stevenson.warn "Deprecation:", "The 'include' configuration option" +
" must now be specified as an array, but you specified" +
" a string. For now, we've treated the string you provided" +
" as a list of comma-separated values."
config['include'] = csv_to_array(config['include'])
end
config
end

View File

@ -53,7 +53,9 @@ class TestConfiguration < Test::Unit::TestCase
@config = Configuration[{
"auto" => true,
"watch" => true,
"server" => true
"server" => true,
"exclude" => "READ-ME.md, Gemfile,CONTRIBUTING.hello.markdown",
"include" => "STOP_THE_PRESSES.txt,.heloses, .git"
}]
end
should "unset 'auto' and 'watch'" do
@ -66,6 +68,16 @@ class TestConfiguration < Test::Unit::TestCase
assert @config.has_key?("server")
assert !@config.backwards_compatibilize.has_key?("server")
end
should "transform string exclude into an array" do
assert @config.has_key?("exclude")
assert @config.backwards_compatibilize.has_key?("exclude")
assert_equal @config.backwards_compatibilize["exclude"], %w[READ-ME.md Gemfile CONTRIBUTING.hello.markdown]
end
should "transform string include into an array" do
assert @config.has_key?("include")
assert @config.backwards_compatibilize.has_key?("include")
assert_equal @config.backwards_compatibilize["include"], %w[STOP_THE_PRESSES.txt .heloses .git]
end
end
context "loading configuration" do
setup do