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

Throw a warning if a layout does not exist #2620

Merged
merged 8 commits into from Jul 29, 2014

Conversation

alfredxing
Copy link
Member

Throw a warning if a layout is specified in a Convertible or Document but the layout file (in the _layouts dir) does not exist.

Should address #2251 and #2583.

Throw a warning if a non-"none" layout is specified but the corresponding
layout file does not exist.

if !data["layout"].nil? && data["layout"] != "none" && layout.nil?
Jekyll.logger.warn("Build Warning:", "Layout #{data["layout"]} does not exist.")
end
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is all very complicated. Can you put it in a method which encapsulates this? 🐸

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sure. It also seems the Travis build failed because some docs don't have a data variable; I'll fix that as well.

@@ -163,6 +172,9 @@ def place_in_layout?
def render_all_layouts(layouts, payload, info)
# recursively render layouts
layout = layouts[data["layout"]]

Jekyll.logger.warn("Build Warning:", "Layout #{data["layout"]} does not exist.") if invalid_layout? layout
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should also mention in which file the layout is being called.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done!

#
# Returns true if the layout is invalid, false if otherwise
def invalid_layout?(layout)
!data["layout"].nil? && data["layout"] != "none" && layout.nil? && self.class.to_s != "Jekyll::Excerpt"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please use #is_a? for class checking

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed! 😛

#
# Returns true if the layout is invalid, false if otherwise
def invalid_layout?(layout)
!document.data["layout"].nil? && document.data["layout"] != "none" && layout.nil?
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

none should be a valid layout name. Can we just do the first and last checks? If a layout is specified but doesn't exist, warn.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@parkr Yeah, here I'm excluding none as a valid layout, so if a page has layout: none in the front matter, Jekyll won't throw a warning.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

layout: none would be invalid unless _layouts/none.html exists. We should only consider nil (and maybe false?) as the user not specifying a layout. If I have a layout called none but haven't created the file, I'm going to be upset that this warning didn't catch my error.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sure, I'll update the code to match that.

@parkr
Copy link
Member

parkr commented Jul 27, 2014

Looking pretty good. One comment above and I'll merge.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants