Skip to content

Commit

Permalink
Merge pull request #1114 from mojombo/backwards-compatibilize-exclude…
Browse files Browse the repository at this point in the history
…-include

Backwards-compatibilize 'exclude' and 'include' config tags
  • Loading branch information
mattr- committed May 18, 2013
2 parents fa1cbb7 + 63dc563 commit ddba4cd
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 3 deletions.
25 changes: 25 additions & 0 deletions lib/jekyll/configuration.rb
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,15 @@ def read_config_files(files)
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
#
Expand Down Expand Up @@ -176,6 +185,22 @@ def backwards_compatibilize
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

Expand Down
18 changes: 15 additions & 3 deletions test/test_configuration.rb
Original file line number Diff line number Diff line change
Expand Up @@ -51,9 +51,11 @@ class TestConfiguration < Test::Unit::TestCase
context "#backwards_compatibilize" do
setup do
@config = Configuration[{
"auto" => true,
"watch" => true,
"server" => true
"auto" => true,
"watch" => 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
Expand All @@ -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
Expand Down

0 comments on commit ddba4cd

Please sign in to comment.