Skip to content

Commit 1eda1aa

Browse files
committed
Merge pull request #39 from djds23/make-title-string-literal
Merge pull request 39
2 parents afbbdfc + 710ddc4 commit 1eda1aa

File tree

2 files changed

+52
-6
lines changed

2 files changed

+52
-6
lines changed

lib/jekyll-compose/file_info.rb

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,11 @@ def file_name
1010
end
1111

1212
def content
13-
<<-CONTENT.gsub /^\s+/, ''
14-
---
15-
layout: #{params.layout}
16-
title: #{params.title}
17-
---
18-
CONTENT
13+
front_matter = YAML.dump({
14+
'layout' => params.layout,
15+
'title' => params.title,
16+
})
17+
18+
front_matter + "---\n"
1919
end
2020
end

spec/file_info_spec.rb

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
RSpec.describe(Jekyll::Compose::FileInfo) do
2+
describe '#content' do
3+
context 'with a title of only words' do
4+
let(:expected_result) {<<-CONTENT.gsub(/^\s+/, '')
5+
---
6+
layout: post
7+
title: A test arg parser
8+
---
9+
CONTENT
10+
}
11+
12+
let(:parsed_args) { Jekyll::Compose::ArgParser.new(
13+
['A test arg parser'],
14+
{}
15+
)
16+
}
17+
18+
it 'does not wrap the title in quotes' do
19+
file_info = described_class.new parsed_args
20+
expect(file_info.content).to eq(expected_result)
21+
end
22+
end
23+
24+
context 'with a title that includes a colon' do
25+
let(:expected_result) {<<-CONTENT.gsub(/^\s+/, '')
26+
---
27+
layout: post
28+
title: 'A test: arg parser'
29+
---
30+
CONTENT
31+
}
32+
33+
let(:parsed_args) { Jekyll::Compose::ArgParser.new(
34+
['A test: arg parser'],
35+
{}
36+
)
37+
}
38+
39+
it 'does wrap the title in quotes' do
40+
file_info = described_class.new parsed_args
41+
expect(file_info.content).to eq(expected_result)
42+
end
43+
end
44+
end
45+
end
46+

0 commit comments

Comments
 (0)