Merge pull request #2571 from yous/patch-mixed-case-category
This commit is contained in:
commit
ba2e1390ad
|
@ -141,7 +141,7 @@ Feature: Post data
|
||||||
And I have a simple layout that contains "Post categories: {{ page.categories | array_to_sentence_string }}"
|
And I have a simple layout that contains "Post categories: {{ page.categories | array_to_sentence_string }}"
|
||||||
When I run jekyll build
|
When I run jekyll build
|
||||||
Then the _site directory should exist
|
Then the _site directory should exist
|
||||||
And I should see "Post categories: scifi and movies" in "_site/scifi/movies/2009/03/27/star-wars.html"
|
And I should see "Post categories: scifi and Movies" in "_site/scifi/movies/2009/03/27/star-wars.html"
|
||||||
|
|
||||||
Scenario: Use post.categories variable when category is in YAML
|
Scenario: Use post.categories variable when category is in YAML
|
||||||
Given I have a _posts directory
|
Given I have a _posts directory
|
||||||
|
@ -163,7 +163,7 @@ Feature: Post data
|
||||||
And I have a simple layout that contains "Post category: {{ page.categories }}"
|
And I have a simple layout that contains "Post category: {{ page.categories }}"
|
||||||
When I run jekyll build
|
When I run jekyll build
|
||||||
Then the _site directory should exist
|
Then the _site directory should exist
|
||||||
And I should see "Post category: movies" in "_site/movies/2009/03/27/star-wars.html"
|
And I should see "Post category: Movies" in "_site/movies/2009/03/27/star-wars.html"
|
||||||
|
|
||||||
Scenario: Use post.categories variable when categories are in YAML
|
Scenario: Use post.categories variable when categories are in YAML
|
||||||
Given I have a _posts directory
|
Given I have a _posts directory
|
||||||
|
@ -197,8 +197,8 @@ Feature: Post data
|
||||||
And I have a simple layout that contains "Post categories: {{ page.categories | array_to_sentence_string }}"
|
And I have a simple layout that contains "Post categories: {{ page.categories | array_to_sentence_string }}"
|
||||||
When I run jekyll build
|
When I run jekyll build
|
||||||
Then the _site directory should exist
|
Then the _site directory should exist
|
||||||
And I should see "Post categories: scifi and movies" in "_site/scifi/movies/2009/03/27/star-wars.html"
|
And I should see "Post categories: scifi and Movies" in "_site/scifi/movies/2009/03/27/star-wars.html"
|
||||||
And I should see "Post categories: scifi and movies" in "_site/scifi/movies/2013/03/17/star-trek.html"
|
And I should see "Post categories: SciFi and movies" in "_site/scifi/movies/2013/03/17/star-trek.html"
|
||||||
|
|
||||||
Scenario Outline: Use page.path variable
|
Scenario Outline: Use page.path variable
|
||||||
Given I have a <dir>/_posts directory
|
Given I have a <dir>/_posts directory
|
||||||
|
|
|
@ -52,7 +52,7 @@ module Jekyll
|
||||||
@base = containing_dir(dir)
|
@base = containing_dir(dir)
|
||||||
@name = name
|
@name = name
|
||||||
|
|
||||||
self.categories = dir.downcase.split('/').reject { |x| x.empty? }
|
self.categories = dir.split('/').reject { |x| x.empty? }
|
||||||
process(name)
|
process(name)
|
||||||
read_yaml(@base, name)
|
read_yaml(@base, name)
|
||||||
|
|
||||||
|
@ -80,7 +80,7 @@ module Jekyll
|
||||||
categories_from_data = Utils.pluralized_array_from_hash(data, 'category', 'categories')
|
categories_from_data = Utils.pluralized_array_from_hash(data, 'category', 'categories')
|
||||||
self.categories = (
|
self.categories = (
|
||||||
Array(categories) + categories_from_data
|
Array(categories) + categories_from_data
|
||||||
).map {|c| c.to_s.downcase}.flatten.uniq
|
).map { |c| c.to_s }.flatten.uniq
|
||||||
end
|
end
|
||||||
|
|
||||||
def populate_tags
|
def populate_tags
|
||||||
|
@ -218,7 +218,7 @@ module Jekyll
|
||||||
:title => slug,
|
:title => slug,
|
||||||
:i_day => date.strftime("%-d"),
|
:i_day => date.strftime("%-d"),
|
||||||
:i_month => date.strftime("%-m"),
|
:i_month => date.strftime("%-m"),
|
||||||
:categories => (categories || []).map { |c| c.to_s }.join('/'),
|
:categories => (categories || []).map { |c| c.to_s.downcase }.uniq.join('/'),
|
||||||
:short_month => date.strftime("%b"),
|
:short_month => date.strftime("%b"),
|
||||||
:short_year => date.strftime("%y"),
|
:short_year => date.strftime("%y"),
|
||||||
:y_day => date.strftime("%j"),
|
:y_day => date.strftime("%j"),
|
||||||
|
|
|
@ -5,6 +5,7 @@ categories:
|
||||||
- bar
|
- bar
|
||||||
- baz
|
- baz
|
||||||
- z_category
|
- z_category
|
||||||
|
- MixedCase
|
||||||
tags:
|
tags:
|
||||||
- first
|
- first
|
||||||
- second
|
- second
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
---
|
---
|
||||||
categories: foo bar baz
|
categories: foo bar baz MixedCase
|
||||||
foo: bar
|
foo: bar
|
||||||
layout: default
|
layout: default
|
||||||
tags: ay bee cee
|
tags: ay bee cee
|
||||||
|
|
|
@ -0,0 +1,7 @@
|
||||||
|
---
|
||||||
|
layout: default
|
||||||
|
title: Another Mixed Case Category in YAML
|
||||||
|
category: Mixedcase
|
||||||
|
---
|
||||||
|
|
||||||
|
Best *post* ever
|
|
@ -0,0 +1,7 @@
|
||||||
|
---
|
||||||
|
layout: default
|
||||||
|
title: Mixed Case Category in YAML
|
||||||
|
category: MixedCase
|
||||||
|
---
|
||||||
|
|
||||||
|
Best *post* ever
|
|
@ -76,9 +76,9 @@ class TestExcerpt < Test::Unit::TestCase
|
||||||
context "#to_liquid" do
|
context "#to_liquid" do
|
||||||
should "contain the proper page data to mimick the post liquid" do
|
should "contain the proper page data to mimick the post liquid" do
|
||||||
assert_equal "Post Excerpt with Layout", @excerpt.to_liquid["title"]
|
assert_equal "Post Excerpt with Layout", @excerpt.to_liquid["title"]
|
||||||
assert_equal "/bar/baz/z_category/2013/07/22/post-excerpt-with-layout.html", @excerpt.to_liquid["url"]
|
assert_equal "/bar/baz/z_category/mixedcase/2013/07/22/post-excerpt-with-layout.html", @excerpt.to_liquid["url"]
|
||||||
assert_equal Time.parse("2013-07-22"), @excerpt.to_liquid["date"]
|
assert_equal Time.parse("2013-07-22"), @excerpt.to_liquid["date"]
|
||||||
assert_equal %w[bar baz z_category], @excerpt.to_liquid["categories"]
|
assert_equal %w[bar baz z_category MixedCase], @excerpt.to_liquid["categories"]
|
||||||
assert_equal %w[first second third jekyllrb.com], @excerpt.to_liquid["tags"]
|
assert_equal %w[first second third jekyllrb.com], @excerpt.to_liquid["tags"]
|
||||||
assert_equal "_posts/2013-07-22-post-excerpt-with-layout.markdown", @excerpt.to_liquid["path"]
|
assert_equal "_posts/2013-07-22-post-excerpt-with-layout.markdown", @excerpt.to_liquid["path"]
|
||||||
end
|
end
|
||||||
|
|
|
@ -34,13 +34,13 @@ class TestPost < Test::Unit::TestCase
|
||||||
post = setup_post('2013-12-20-properties.text')
|
post = setup_post('2013-12-20-properties.text')
|
||||||
|
|
||||||
attrs = {
|
attrs = {
|
||||||
categories: %w(foo bar baz),
|
categories: %w(foo bar baz MixedCase),
|
||||||
content: "All the properties.\n\nPlus an excerpt.\n",
|
content: "All the properties.\n\nPlus an excerpt.\n",
|
||||||
date: Time.new(2013, 12, 20),
|
date: Time.new(2013, 12, 20),
|
||||||
dir: "/foo/bar/baz/2013/12/20",
|
dir: "/foo/bar/baz/mixedcase/2013/12/20",
|
||||||
excerpt: "All the properties.\n\n",
|
excerpt: "All the properties.\n\n",
|
||||||
foo: 'bar',
|
foo: 'bar',
|
||||||
id: "/foo/bar/baz/2013/12/20/properties",
|
id: "/foo/bar/baz/mixedcase/2013/12/20/properties",
|
||||||
layout: 'default',
|
layout: 'default',
|
||||||
name: nil,
|
name: nil,
|
||||||
path: "_posts/2013-12-20-properties.text",
|
path: "_posts/2013-12-20-properties.text",
|
||||||
|
@ -48,7 +48,7 @@ class TestPost < Test::Unit::TestCase
|
||||||
published: nil,
|
published: nil,
|
||||||
tags: %w(ay bee cee),
|
tags: %w(ay bee cee),
|
||||||
title: 'Properties Post',
|
title: 'Properties Post',
|
||||||
url: "/foo/bar/baz/2013/12/20/properties.html"
|
url: "/foo/bar/baz/mixedcase/2013/12/20/properties.html"
|
||||||
}
|
}
|
||||||
|
|
||||||
attrs.each do |attr, val|
|
attrs.each do |attr, val|
|
||||||
|
@ -256,14 +256,39 @@ class TestPost < Test::Unit::TestCase
|
||||||
|
|
||||||
context "with space (categories)" do
|
context "with space (categories)" do
|
||||||
setup do
|
setup do
|
||||||
@post.categories << "French cuisine"
|
@post.categories << "french cuisine"
|
||||||
@post.categories << "Belgian beer"
|
@post.categories << "belgian beer"
|
||||||
@post.process(@fake_file)
|
@post.process(@fake_file)
|
||||||
end
|
end
|
||||||
|
|
||||||
should "process the url correctly" do
|
should "process the url correctly" do
|
||||||
assert_equal "/:categories/:year/:month/:day/:title.html", @post.template
|
assert_equal "/:categories/:year/:month/:day/:title.html", @post.template
|
||||||
assert_equal "/French%20cuisine/Belgian%20beer/2008/09/09/foo-bar.html", @post.url
|
assert_equal "/french%20cuisine/belgian%20beer/2008/09/09/foo-bar.html", @post.url
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
context "with mixed case (category)" do
|
||||||
|
setup do
|
||||||
|
@post.categories << "MixedCase"
|
||||||
|
@post.process(@fake_file)
|
||||||
|
end
|
||||||
|
|
||||||
|
should "process the url correctly" do
|
||||||
|
assert_equal "/:categories/:year/:month/:day/:title.html", @post.template
|
||||||
|
assert_equal "/mixedcase/2008/09/09/foo-bar.html", @post.url
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
context "with duplicated mixed case (categories)" do
|
||||||
|
setup do
|
||||||
|
@post.categories << "MixedCase"
|
||||||
|
@post.categories << "Mixedcase"
|
||||||
|
@post.process(@fake_file)
|
||||||
|
end
|
||||||
|
|
||||||
|
should "process the url correctly" do
|
||||||
|
assert_equal "/:categories/:year/:month/:day/:title.html", @post.template
|
||||||
|
assert_equal "/mixedcase/2008/09/09/foo-bar.html", @post.url
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -518,6 +543,12 @@ class TestPost < Test::Unit::TestCase
|
||||||
assert !post.categories.include?(2013)
|
assert !post.categories.include?(2013)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
should "recognize mixed case category in yaml" do
|
||||||
|
post = setup_post("2014-07-05-mixed-case-category.markdown")
|
||||||
|
assert post.categories.include?('MixedCase')
|
||||||
|
assert !post.categories.include?('mixedcase')
|
||||||
|
end
|
||||||
|
|
||||||
should "recognize tag in yaml" do
|
should "recognize tag in yaml" do
|
||||||
post = setup_post("2009-05-18-tag.textile")
|
post = setup_post("2009-05-18-tag.textile")
|
||||||
assert post.tags.include?('code')
|
assert post.tags.include?('code')
|
||||||
|
@ -590,6 +621,20 @@ class TestPost < Test::Unit::TestCase
|
||||||
'escape-+ %20[].html'))
|
'escape-+ %20[].html'))
|
||||||
end
|
end
|
||||||
|
|
||||||
|
should "write properly when category has different letter case" do
|
||||||
|
%w(2014-07-05-mixed-case-category.markdown 2014-07-05-another-mixed-case-category.markdown).each do |file|
|
||||||
|
post = setup_post(file)
|
||||||
|
do_render(post)
|
||||||
|
post.write(dest_dir)
|
||||||
|
end
|
||||||
|
|
||||||
|
assert File.directory?(dest_dir)
|
||||||
|
assert File.exist?(File.join(dest_dir, 'mixedcase', '2014', '07', '05',
|
||||||
|
'mixed-case-category.html'))
|
||||||
|
assert File.exist?(File.join(dest_dir, 'mixedcase', '2014', '07', '05',
|
||||||
|
'another-mixed-case-category.html'))
|
||||||
|
end
|
||||||
|
|
||||||
should "write properly without html extension" do
|
should "write properly without html extension" do
|
||||||
post = setup_post("2008-10-18-foo-bar.textile")
|
post = setup_post("2008-10-18-foo-bar.textile")
|
||||||
post.site.permalink_style = ":title"
|
post.site.permalink_style = ":title"
|
||||||
|
|
|
@ -219,7 +219,7 @@ class TestSite < Test::Unit::TestCase
|
||||||
|
|
||||||
posts = Dir[source_dir("**", "_posts", "**", "*")]
|
posts = Dir[source_dir("**", "_posts", "**", "*")]
|
||||||
posts.delete_if { |post| File.directory?(post) && !Post.valid?(post) }
|
posts.delete_if { |post| File.directory?(post) && !Post.valid?(post) }
|
||||||
categories = %w(2013 bar baz category foo z_category publish_test win).sort
|
categories = %w(2013 bar baz category foo z_category MixedCase Mixedcase publish_test win).sort
|
||||||
|
|
||||||
assert_equal posts.size - @num_invalid_posts, @site.posts.size
|
assert_equal posts.size - @num_invalid_posts, @site.posts.size
|
||||||
assert_equal categories, @site.categories.keys.sort
|
assert_equal categories, @site.categories.keys.sort
|
||||||
|
|
Loading…
Reference in New Issue