Rename those Utils functions.
This commit is contained in:
parent
5e8643d855
commit
7787d64bce
|
|
@ -83,9 +83,7 @@ module Jekyll
|
||||||
config = config.read_config_files(config.config_files(override))
|
config = config.read_config_files(config.config_files(override))
|
||||||
|
|
||||||
# Merge DEFAULTS < _config.yml < override
|
# Merge DEFAULTS < _config.yml < override
|
||||||
config = Utils.hash_stringify_keys(
|
config = Utils.deep_merge_hashes(config, override).stringify_keys
|
||||||
Utils.hash_deep_merge(config, override)
|
|
||||||
)
|
|
||||||
set_timezone(config['timezone']) if config['timezone']
|
set_timezone(config['timezone']) if config['timezone']
|
||||||
|
|
||||||
config
|
config
|
||||||
|
|
|
||||||
|
|
@ -159,7 +159,7 @@ module Jekyll
|
||||||
begin
|
begin
|
||||||
files.each do |config_file|
|
files.each do |config_file|
|
||||||
new_config = read_config_file(config_file)
|
new_config = read_config_file(config_file)
|
||||||
configuration = Utils.hash_deep_merge(configuration, new_config)
|
configuration = Utils.deep_merge_hashes(configuration, new_config)
|
||||||
end
|
end
|
||||||
rescue ArgumentError => err
|
rescue ArgumentError => err
|
||||||
Jekyll.logger.warn "WARNING:", "Error reading configuration. " +
|
Jekyll.logger.warn "WARNING:", "Error reading configuration. " +
|
||||||
|
|
|
||||||
|
|
@ -20,7 +20,7 @@ module Jekyll
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
Kramdown::Document.new(content, Utils.hash_symbolize_keys(@config["kramdown"])).to_html
|
Kramdown::Document.new(content, Utils.symbolize_hash_keys(@config["kramdown"])).to_html
|
||||||
end
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
|
||||||
|
|
@ -107,7 +107,7 @@ module Jekyll
|
||||||
further_data = Hash[(attrs || self.class::ATTRIBUTES_FOR_LIQUID).map { |attribute|
|
further_data = Hash[(attrs || self.class::ATTRIBUTES_FOR_LIQUID).map { |attribute|
|
||||||
[attribute, send(attribute)]
|
[attribute, send(attribute)]
|
||||||
}]
|
}]
|
||||||
Utils.hash_deep_merge(data, further_data)
|
Utils.deep_merge_hashes(data, further_data)
|
||||||
end
|
end
|
||||||
|
|
||||||
# Recursively render layouts
|
# Recursively render layouts
|
||||||
|
|
@ -123,7 +123,7 @@ module Jekyll
|
||||||
used = Set.new([layout])
|
used = Set.new([layout])
|
||||||
|
|
||||||
while layout
|
while layout
|
||||||
payload = Utils.hash_deep_merge(payload, {"content" => output, "page" => layout.data})
|
payload = Utils.deep_merge_hashes(payload, {"content" => output, "page" => layout.data})
|
||||||
|
|
||||||
self.output = render_liquid(layout.content,
|
self.output = render_liquid(layout.content,
|
||||||
payload,
|
payload,
|
||||||
|
|
|
||||||
|
|
@ -109,7 +109,7 @@ module Jekyll
|
||||||
#
|
#
|
||||||
# Returns nothing.
|
# Returns nothing.
|
||||||
def render(layouts, site_payload)
|
def render(layouts, site_payload)
|
||||||
payload = Utils.hash_deep_merge({
|
payload = Utils.deep_merge_hashes({
|
||||||
"page" => to_liquid,
|
"page" => to_liquid,
|
||||||
'paginator' => pager.to_liquid
|
'paginator' => pager.to_liquid
|
||||||
}, site_payload)
|
}, site_payload)
|
||||||
|
|
|
||||||
|
|
@ -66,13 +66,13 @@ module Jekyll
|
||||||
|
|
||||||
def populate_categories
|
def populate_categories
|
||||||
if categories.empty?
|
if categories.empty?
|
||||||
self.categories = Utils.hash_pluralized_array(data, 'category', 'categories').map {|c| c.to_s.downcase}
|
self.categories = Utils.pluralized_array_from_hash(data, 'category', 'categories').map {|c| c.to_s.downcase}
|
||||||
end
|
end
|
||||||
categories.flatten!
|
categories.flatten!
|
||||||
end
|
end
|
||||||
|
|
||||||
def populate_tags
|
def populate_tags
|
||||||
self.tags = Utils.hash_pluralized_array(data, "tag", "tags").flatten
|
self.tags = Utils.pluralized_array_from_hash(data, "tag", "tags").flatten
|
||||||
end
|
end
|
||||||
|
|
||||||
# Get the full path to the directory containing the post files
|
# Get the full path to the directory containing the post files
|
||||||
|
|
@ -241,7 +241,7 @@ module Jekyll
|
||||||
# Returns nothing.
|
# Returns nothing.
|
||||||
def render(layouts, site_payload)
|
def render(layouts, site_payload)
|
||||||
# construct payload
|
# construct payload
|
||||||
payload = Utils.hash_deep_merge({
|
payload = Utils.deep_merge_hashes({
|
||||||
"site" => { "related_posts" => related_posts(site_payload["site"]["posts"]) },
|
"site" => { "related_posts" => related_posts(site_payload["site"]["posts"]) },
|
||||||
"page" => to_liquid(EXCERPT_ATTRIBUTES_FOR_LIQUID)
|
"page" => to_liquid(EXCERPT_ATTRIBUTES_FOR_LIQUID)
|
||||||
}, site_payload)
|
}, site_payload)
|
||||||
|
|
|
||||||
|
|
@ -16,7 +16,7 @@ module Jekyll
|
||||||
|
|
||||||
other_hash.keys.each do |key|
|
other_hash.keys.each do |key|
|
||||||
if other_hash[key].is_a? Hash and target[key].is_a? Hash
|
if other_hash[key].is_a? Hash and target[key].is_a? Hash
|
||||||
target[key] = Utils.hash_deep_merge(target[key], other_hash[key])
|
target[key] = Utils.deep_merge_hashes(target[key], other_hash[key])
|
||||||
next
|
next
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -29,7 +29,7 @@ class Test::Unit::TestCase
|
||||||
include RR::Adapters::TestUnit
|
include RR::Adapters::TestUnit
|
||||||
|
|
||||||
def build_configs(overrides, base_hash = Jekyll::Configuration::DEFAULTS)
|
def build_configs(overrides, base_hash = Jekyll::Configuration::DEFAULTS)
|
||||||
Utils.hash_deep_merge(base_hash, overrides)
|
Utils.deep_merge_hashes(base_hash, overrides)
|
||||||
end
|
end
|
||||||
|
|
||||||
def site_configuration(overrides = {})
|
def site_configuration(overrides = {})
|
||||||
|
|
|
||||||
|
|
@ -156,7 +156,7 @@ class TestConfiguration < Test::Unit::TestCase
|
||||||
should "load different config if specified" do
|
should "load different config if specified" do
|
||||||
mock(SafeYAML).load_file(@paths[:other]) { {"baseurl" => "http://wahoo.dev"} }
|
mock(SafeYAML).load_file(@paths[:other]) { {"baseurl" => "http://wahoo.dev"} }
|
||||||
mock($stdout).puts("Configuration file: #{@paths[:other]}")
|
mock($stdout).puts("Configuration file: #{@paths[:other]}")
|
||||||
assert_equal Utils.hash_deep_merge(Jekyll::Configuration::DEFAULTS, { "baseurl" => "http://wahoo.dev" }), Jekyll.configuration({ "config" => @paths[:other] })
|
assert_equal Utils.deep_merge_hashes(Jekyll::Configuration::DEFAULTS, { "baseurl" => "http://wahoo.dev" }), Jekyll.configuration({ "config" => @paths[:other] })
|
||||||
end
|
end
|
||||||
|
|
||||||
should "load default config if path passed is empty" do
|
should "load default config if path passed is empty" do
|
||||||
|
|
@ -186,7 +186,7 @@ class TestConfiguration < Test::Unit::TestCase
|
||||||
mock(SafeYAML).load_file(@paths[:other]) { {"baseurl" => "http://wahoo.dev"} }
|
mock(SafeYAML).load_file(@paths[:other]) { {"baseurl" => "http://wahoo.dev"} }
|
||||||
mock($stdout).puts("Configuration file: #{@paths[:default]}")
|
mock($stdout).puts("Configuration file: #{@paths[:default]}")
|
||||||
mock($stdout).puts("Configuration file: #{@paths[:other]}")
|
mock($stdout).puts("Configuration file: #{@paths[:other]}")
|
||||||
assert_equal Utils.hash_deep_merge(Jekyll::Configuration::DEFAULTS, { "baseurl" => "http://wahoo.dev" }), Jekyll.configuration({ "config" => [@paths[:default], @paths[:other]] })
|
assert_equal Utils.deep_merge_hashes(Jekyll::Configuration::DEFAULTS, { "baseurl" => "http://wahoo.dev" }), Jekyll.configuration({ "config" => [@paths[:default], @paths[:other]] })
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
||||||
|
|
@ -35,7 +35,7 @@ class TestKramdown < Test::Unit::TestCase
|
||||||
assert_match /<p>(“|“)Pit(’|’)hy(”|”)<\/p>/, @markdown.convert(%{"Pit'hy"}).strip
|
assert_match /<p>(“|“)Pit(’|’)hy(”|”)<\/p>/, @markdown.convert(%{"Pit'hy"}).strip
|
||||||
|
|
||||||
override = { 'kramdown' => { 'smart_quotes' => 'lsaquo,rsaquo,laquo,raquo' } }
|
override = { 'kramdown' => { 'smart_quotes' => 'lsaquo,rsaquo,laquo,raquo' } }
|
||||||
markdown = Converters::Markdown.new(Utils.hash_deep_merge(@config, override))
|
markdown = Converters::Markdown.new(Utils.deep_merge_hashes(@config, override))
|
||||||
assert_match /<p>(«|«)Pit(›|›)hy(»|»)<\/p>/, markdown.convert(%{"Pit'hy"}).strip
|
assert_match /<p>(«|«)Pit(›|›)hy(»|»)<\/p>/, markdown.convert(%{"Pit'hy"}).strip
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -7,57 +7,57 @@ class TestUtils < Test::Unit::TestCase
|
||||||
|
|
||||||
should "return empty array with no values" do
|
should "return empty array with no values" do
|
||||||
data = {}
|
data = {}
|
||||||
assert_equal [], Utils.hash_pluralized_array(data, 'tag', 'tags')
|
assert_equal [], Utils.pluralized_array_from_hash(data, 'tag', 'tags')
|
||||||
end
|
end
|
||||||
|
|
||||||
should "return empty array with no matching values" do
|
should "return empty array with no matching values" do
|
||||||
data = { 'foo' => 'bar' }
|
data = { 'foo' => 'bar' }
|
||||||
assert_equal [], Utils.hash_pluralized_array(data, 'tag', 'tags')
|
assert_equal [], Utils.pluralized_array_from_hash(data, 'tag', 'tags')
|
||||||
end
|
end
|
||||||
|
|
||||||
should "return empty array with matching nil singular" do
|
should "return empty array with matching nil singular" do
|
||||||
data = { 'foo' => 'bar', 'tag' => nil, 'tags' => ['dog', 'cat'] }
|
data = { 'foo' => 'bar', 'tag' => nil, 'tags' => ['dog', 'cat'] }
|
||||||
assert_equal [], Utils.hash_pluralized_array(data, 'tag', 'tags')
|
assert_equal [], Utils.pluralized_array_from_hash(data, 'tag', 'tags')
|
||||||
end
|
end
|
||||||
|
|
||||||
should "return single value array with matching singular" do
|
should "return single value array with matching singular" do
|
||||||
data = { 'foo' => 'bar', 'tag' => 'dog', 'tags' => ['dog', 'cat'] }
|
data = { 'foo' => 'bar', 'tag' => 'dog', 'tags' => ['dog', 'cat'] }
|
||||||
assert_equal ['dog'], Utils.hash_pluralized_array(data, 'tag', 'tags')
|
assert_equal ['dog'], Utils.pluralized_array_from_hash(data, 'tag', 'tags')
|
||||||
end
|
end
|
||||||
|
|
||||||
should "return single value array with matching singular with spaces" do
|
should "return single value array with matching singular with spaces" do
|
||||||
data = { 'foo' => 'bar', 'tag' => 'dog cat', 'tags' => ['dog', 'cat'] }
|
data = { 'foo' => 'bar', 'tag' => 'dog cat', 'tags' => ['dog', 'cat'] }
|
||||||
assert_equal ['dog cat'], Utils.hash_pluralized_array(data, 'tag', 'tags')
|
assert_equal ['dog cat'], Utils.pluralized_array_from_hash(data, 'tag', 'tags')
|
||||||
end
|
end
|
||||||
|
|
||||||
should "return empty array with matching nil plural" do
|
should "return empty array with matching nil plural" do
|
||||||
data = { 'foo' => 'bar', 'tags' => nil }
|
data = { 'foo' => 'bar', 'tags' => nil }
|
||||||
assert_equal [], Utils.hash_pluralized_array(data, 'tag', 'tags')
|
assert_equal [], Utils.pluralized_array_from_hash(data, 'tag', 'tags')
|
||||||
end
|
end
|
||||||
|
|
||||||
should "return empty array with matching empty array" do
|
should "return empty array with matching empty array" do
|
||||||
data = { 'foo' => 'bar', 'tags' => [] }
|
data = { 'foo' => 'bar', 'tags' => [] }
|
||||||
assert_equal [], Utils.hash_pluralized_array(data, 'tag', 'tags')
|
assert_equal [], Utils.pluralized_array_from_hash(data, 'tag', 'tags')
|
||||||
end
|
end
|
||||||
|
|
||||||
should "return single value array with matching plural with single string value" do
|
should "return single value array with matching plural with single string value" do
|
||||||
data = { 'foo' => 'bar', 'tags' => 'dog' }
|
data = { 'foo' => 'bar', 'tags' => 'dog' }
|
||||||
assert_equal ['dog'], Utils.hash_pluralized_array(data, 'tag', 'tags')
|
assert_equal ['dog'], Utils.pluralized_array_from_hash(data, 'tag', 'tags')
|
||||||
end
|
end
|
||||||
|
|
||||||
should "return multiple value array with matching plural with single string value with spaces" do
|
should "return multiple value array with matching plural with single string value with spaces" do
|
||||||
data = { 'foo' => 'bar', 'tags' => 'dog cat' }
|
data = { 'foo' => 'bar', 'tags' => 'dog cat' }
|
||||||
assert_equal ['dog', 'cat'], Utils.hash_pluralized_array(data, 'tag', 'tags')
|
assert_equal ['dog', 'cat'], Utils.pluralized_array_from_hash(data, 'tag', 'tags')
|
||||||
end
|
end
|
||||||
|
|
||||||
should "return single value array with matching plural with single value array" do
|
should "return single value array with matching plural with single value array" do
|
||||||
data = { 'foo' => 'bar', 'tags' => ['dog'] }
|
data = { 'foo' => 'bar', 'tags' => ['dog'] }
|
||||||
assert_equal ['dog'], Utils.hash_pluralized_array(data, 'tag', 'tags')
|
assert_equal ['dog'], Utils.pluralized_array_from_hash(data, 'tag', 'tags')
|
||||||
end
|
end
|
||||||
|
|
||||||
should "return multiple value array with matching plural with multiple value array" do
|
should "return multiple value array with matching plural with multiple value array" do
|
||||||
data = { 'foo' => 'bar', 'tags' => ['dog', 'cat'] }
|
data = { 'foo' => 'bar', 'tags' => ['dog', 'cat'] }
|
||||||
assert_equal ['dog', 'cat'], Utils.hash_pluralized_array(data, 'tag', 'tags')
|
assert_equal ['dog', 'cat'], Utils.pluralized_array_from_hash(data, 'tag', 'tags')
|
||||||
end
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue