Skip to content

Commit 5753549

Browse files
committed
Merge pull request #25 from jekyll/additional-tests
Don't double convert @mentions in posts in Jekyll > 3.0
2 parents a93effd + 4b0c627 commit 5753549

File tree

7 files changed

+35
-20
lines changed

7 files changed

+35
-20
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,3 +3,4 @@
33
bin
44
/*.gem
55
Gemfile.lock
6+
/tmp

jekyll-mentions.gemspec

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ Gem::Specification.new do |s|
1010
s.files = [ "lib/jekyll-mentions.rb" ]
1111

1212
s.add_dependency "jekyll", '~> 3.0'
13-
s.add_dependency "html-pipeline", '~> 2.2'
13+
s.add_dependency "html-pipeline", '~> 2.3'
1414

1515
s.add_development_dependency 'rake'
1616
s.add_development_dependency 'rdoc'

lib/jekyll-mentions.rb

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,14 +13,12 @@ def initialize(config = Hash.new)
1313

1414
def generate(site)
1515
site.pages.each { |page| mentionify page if html_page?(page) }
16-
site.posts.docs.each { |post| mentionify post }
1716
site.docs_to_write.each { |doc| mentionify doc }
1817
end
1918

2019
def mentionify(page)
2120
return unless page.content.include?('@')
22-
# see https://github.com/jekyll/jekyll-mentions/pull/22 if you're wondering about the nils
23-
page.content = @filter.mention_link_filter(page.content, nil, nil, HTML::Pipeline::MentionFilter::UsernamePattern)
21+
page.content = @filter.mention_link_filter(page.content)
2422
end
2523

2624
def html_page?(page)

test/fixtures/_config.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
collections:
2+
docs:
3+
output: true
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
title: I'm a post
3+
---
4+
5+
test @test test

test/helper.rb

Lines changed: 9 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -8,22 +8,18 @@
88

99
TEST_DIR = File.expand_path("../", __FILE__)
1010
FIXTURES_DIR = File.expand_path("fixtures", TEST_DIR)
11-
DEST_DIR = File.expand_path("destination", TEST_DIR)
11+
DEST_DIR = File.expand_path("../tmp/destination", TEST_DIR)
1212

1313
module MentionsTestHelpers
14+
def config
15+
@config ||= Jekyll.configuration({
16+
"source" => FIXTURES_DIR,
17+
"destination" => DEST_DIR
18+
})
19+
end
20+
1421
def fixture_site
15-
Jekyll::Site.new(
16-
Jekyll::Utils.deep_merge_hashes(
17-
Jekyll::Configuration::DEFAULTS,
18-
{
19-
"source" => FIXTURES_DIR,
20-
"destination" => DEST_DIR,
21-
"collections" => {
22-
"docs" => {}
23-
}
24-
}
25-
)
26-
)
22+
@site ||= Jekyll::Site.new(config)
2723
end
2824

2925
def page_with_name(site, name)

test/test_jekyll_mentions.rb

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,9 +24,21 @@ def setup
2424
assert_equal @mention, page.content
2525
end
2626

27-
should "replace page content on generate" do
28-
@mentions.generate(@site)
29-
assert_equal @mention, @site.pages.first.content
27+
context "generating" do
28+
should "replace page content on generate" do
29+
@mentions.generate(@site)
30+
assert_equal @mention, @site.pages.first.content
31+
end
32+
33+
should "replace post content on generate" do
34+
@mentions.generate(@site)
35+
assert_equal @mention, @site.posts.docs.first.content.strip
36+
end
37+
38+
should "replace doc content on generate" do
39+
@mentions.generate(@site)
40+
assert_equal @mention, @site.collections["docs"].docs.first.content
41+
end
3042
end
3143

3244
should "not mangle liquid templating" do

0 commit comments

Comments
 (0)