Explicitly set falsy values for :template should not render a template #628

Merged
merged 1 commit into from Feb 25, 2013

Conversation

Projects
None yet
2 participants
Contributor

richo commented Feb 2, 2013

No description provided.

Owner

rkh commented Feb 2, 2013

This would change the behaviour of the :layout option and might break apps and especially extensions. It also influences eat_errors (see line below). What's the use case?

Contributor

richo commented Feb 2, 2013

Well, would it? I checked that all the specs are passing and this only affects the behaviour when nil is explicitly set. It doesn't affect the value of eat_errors, because it tests for existance in the opts hash.

The usecase is my utter confusion when I set the :layout parameter to nil and still got a layout. My (I feel reasonable) expectation is that setting either of the false values in ruby should opt out.

Contributor

richo commented Feb 6, 2013

Any news on this? I think it's the right behaviour for a reasonable set of expectations but open to discussion.

Owner

rkh commented Feb 6, 2013

Sorry, yes, I'm travelling atm.

Contributor

richo commented Feb 6, 2013

Ah, no stress.

You got caught up in my periodic bump of all my pull requests. Speak to you when you're available :)

Contributor

richo commented Feb 19, 2013

Bamp.

@rkh rkh commented on the diff Feb 25, 2013

lib/sinatra/base.rb
@@ -714,13 +714,15 @@ def render(engine, data, options={}, locals={}, &block)
# extract generic options
locals = options.delete(:locals) || locals || {}
views = options.delete(:views) || settings.views || "./views"
- layout = options.delete(:layout)
+ layout = options[:layout]
+ layout = false if layout.nil? && options.include?(:layout)
@rkh

rkh Feb 25, 2013

Owner

This messes with the line right beneath it.

@richo

richo Feb 25, 2013

Contributor

Can you elaberate on how? eat_errors was previously true if the default value (nil) was used. This just specialcases where you've specified nil.

Can you show me a testcase for what you mean, and I'll fix it.

@rkh

rkh Feb 25, 2013

Owner

It seems like we don't have a test for this yet. But given the code eat_errors will always be false.

@rkh

rkh Feb 25, 2013

Owner

Ah, no, sorry, missed the include? part.

@richo

richo Feb 25, 2013

Contributor

Yeah I'm pretty sure there are tests over it. I'll open a PR with some explainatory comments if you want, if it took you a couple of goes to work out what I'm doing it'll probably be an issue again in the future.

@rkh rkh added a commit that referenced this pull request Feb 25, 2013

@rkh rkh Merge pull request #628 from richo/bugs/falsy_layouts
Explicitly set falsy values for :template should not render a template
2fc53ac

@rkh rkh merged commit 2fc53ac into sinatra:master Feb 25, 2013

1 check passed

default The Travis build passed
Details
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment