-
-
Notifications
You must be signed in to change notification settings - Fork 242
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
Make content_for raise an exception in case of silently overwriting content #713
Merged
denisdefreyne
merged 4 commits into
nanoc:master
from
Fjan:feature/content-for-prevent-overwrite
Nov 1, 2015
Merged
Changes from 3 commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -59,10 +59,10 @@ def test_content_for_recursively | |
<% content_for :box do %> | ||
basic | ||
<% end %> | ||
<% content_for :box do %> | ||
<% content_for :outerbox do %> | ||
before <%= content_for @item, :box %> after | ||
<% end %> | ||
<%= content_for @item, :box %> | ||
<%= content_for @item, :outerbox %> | ||
foot | ||
EOS | ||
|
||
|
@@ -101,6 +101,32 @@ def test_different_sites | |
assert_equal 'Content Two', content_for(@item, :b) | ||
end | ||
|
||
def test_content_for_duplicate_symbols | ||
with_site do |_site| | ||
# Prepare | ||
File.open('lib/helpers.rb', 'w') do |io| | ||
io.write 'include Nanoc::Helpers::Capturing' | ||
end | ||
File.open('content/includer.erb', 'w') do |io| | ||
io.write '[<%= content_for(@items.find { |i| i.identifier == \'/includee/\' }, :blah) %>]' | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Replace @items.find { |i| i.identifier == \'/includee/\' } with @items["/includee/"] There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ok, I changed that, but note that all other tests in that file use the other style |
||
end | ||
File.open('Rules', 'w') do |io| | ||
io.write "compile '*' do ; filter :erb ; end\n" | ||
io.write "route '*' do ; item.identifier + 'index.html' ; end\n" | ||
end | ||
|
||
File.open('content/includee.erb', 'w') do |io| | ||
io.write '{<% content_for :blah do %>First content<% end %><% content_for :blah do %>Second content<% end %>}' | ||
end | ||
|
||
# Using the same symbols twice now raises an error, to be changed to concatenating in a future version | ||
assert_raises KeyError do | ||
Nanoc::CLI.run(%w(compile)) | ||
end | ||
|
||
end | ||
end | ||
|
||
def test_dependencies | ||
with_site do |_site| | ||
# Prepare | ||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don’t think
KeyError
is correct—that is an exception used when the value of a given key isn’t found. I think raising a string is OK.