Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove leading blank line, if any #1293

Merged
merged 1 commit into from
Jan 14, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion nanoc/lib/nanoc/data_sources/filesystem/parser.rb
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ def parse_with_frontmatter(content_filename)
end

meta = parse_metadata(pieces[2], content_filename)
content = pieces[4]
content = pieces[4].sub(/\A\n/n, '')

ParseResult.new(content: content, attributes: meta, attributes_data: pieces[2])
end
Expand Down
36 changes: 36 additions & 0 deletions nanoc/test/data_sources/test_filesystem.rb
Original file line number Diff line number Diff line change
Expand Up @@ -917,6 +917,42 @@ def test_parse_embedded_empty_meta
# Create data source
data_source = Nanoc::DataSources::Filesystem.new(nil, nil, nil, nil)

# Parse it
result = data_source.instance_eval { parse('test.html', nil) }
assert_equal({}, result.attributes)
assert_equal("blah blah\n-----", result.content)
end

def test_parse_with_one_blank_line_after_metadata
# Create a file
File.open('test.html', 'w') do |io|
io.write "-----\n"
io.write "-----\n"
io.write "\nblah blah\n"
io.write '-----'
end

# Create data source
data_source = Nanoc::DataSources::Filesystem.new(nil, nil, nil, nil)

# Parse it
result = data_source.instance_eval { parse('test.html', nil) }
assert_equal({}, result.attributes)
assert_equal("blah blah\n-----", result.content)
end

def test_parse_with_two_blank_lines_after_metadata
# Create a file
File.open('test.html', 'w') do |io|
io.write "-----\n"
io.write "-----\n"
io.write "\n\nblah blah\n"
io.write '-----'
end

# Create data source
data_source = Nanoc::DataSources::Filesystem.new(nil, nil, nil, nil)

# Parse it
result = data_source.instance_eval { parse('test.html', nil) }
assert_equal({}, result.attributes)
Expand Down