bldr
bldr copied to clipboard
Locals sent to render() from Sinatra should persist through to templates
Not sure what you mean. We pass them in the bldr sinatra helper method here: https://github.com/ajsharp/bldr/blob/master/lib/sinatra/bldr.rb#L26, and they're made instance variable here https://github.com/ajsharp/bldr/blob/master/lib/bldr/node.rb#L25. This means they're accessible inside a template via the locals method.
They are not.
If you pass current_user as a local when rendering a top-level template, that current_user object is not available when you're rendering via template() inside the top-level one.
Oh. I see what you mean. This is a tough one. I think that in most cases, you don't want all variables that you pass in to a parent templates to be available to child templates. This is how rails does this, requiring all scope to be manually set in templates via a locals argument.
But, I think current_user is a special case. Usually how this is dealt with in rails is that it's available higher up the chain -- you designate certain controller methods as helpers that will be available in all of your view templates.
So, I wouldn't want to bleed scope for all locals passed into a parent template to it's children, but we definitely need a mechanism that's akin to what rails allows you to do in order to get ahold of the current user.
Sounds right to me.