Comments (5)
ERB, Haml, Builder all support separate scope and locals and both are used heavily in typical Sinatra apps. They're definitely treated as different things in most web frameworks I have experience with. It's true that Liquid and Mustache have single context objects that bring scope/locals under a single abstraction (I like this approach, personally), but I don't see any way to change the interface and support the more prevalent case.
from tilt.
I don't think ERB and Builder support both natively. Looks like Tilt is adding the locals to the scope. But yes, I see that Haml does take both --in fact it looks like Tilt's #render method was patterned after Haml's?
Yet if you look at the Haml code, all it is doing is converting the scope to a Binding and then adding the locals to the binding via:
def set_locals(locals, scope, scope_object)
scope_object.send(:instance_variable_set, '@_haml_locals', locals)
set_locals = locals.keys.map { |k| "#{k} = @_haml_locals[#{k.inspect}]" }.join("\n")
eval(set_locals, scope)
end
See http://github.com/nex3/haml/blob/master/lib/haml/engine.rb#L165
I'm inclined to simplify this procedure and make it a general extension, something like:
object.to_binding(locals)
So I'm not sure if Tilt needs to cater to the greatest common multiple --Haml is the one outlay here. Consider, I originally had my template engine accept any number of scopes and locals and it effectively merged them together for rendering, but in the end I realized it was just overkill. If my end user need to merge different data sources, it is better that I just give them to the tools to easily do so before passing it into my template engine --that gives them the most control.
Anyway, that's just my "thinking aloud" on the subject.
(Sorry, I may have double posted this.)
from tilt.
ERB and Builder don't support locals natively but frameworks like Sinatra and Rails have layered that on top and benefit from having an interface that provides that abstraction.
That being said, this object.to_binding(locals)
concept is really compelling. If you can find some way of 1.) providing a #render
interface that takes a single scope/locals argument, and 2.) is backward compatible with the current interface, I'd certainly be interested in getting it merged in.
from tilt.
I think #1 and #2 are mutually exclusive. If you were ever to do it, it would be "2.0" type deal. It's not worth breaking backward compatibility at this point (perhaps never, although I suspect most use cases wouldn't be effected). However I do think it is worth using something along the lines of object.to_binding(locals) as well as a function for the opposite effect, converting a scope to locals, under the hood, so that there is a uniform bases that all the templates can use for doing so.
I'll make a example implementation for you to consider. In the meantime, a reminder that I sent a pull request for fixing the RadiusTemplate.
from tilt.
I an running into issues with Tilt where different engines are not giving consistent results. Depending on the type of scope/locals being fed in: Binding, Struct, OpenStruct, Object, and/or Hash Locals, different engine renders differently for equivalent templates. To remedy I started writing some Cucumber features, and realized that there were at least 9 variations to account for: Binding, Struct, OpenStruct, Object, Locals, Binding/Locals, Struct/Locals, OpenStruct/Locals and Object/Locals. Not sure how Hash or Hash/Locals should behave. And hopefully I haven't missed any!
I am working on a project that uses Tilt extensively. I've decided that it's interface will only allow a single argument.
from tilt.
Related Issues (20)
- SyntaxError when rendering ERB `<%=` with a block HOT 3
- Eliminate dependency on deprecated 'sass' Gem HOT 6
- HAML SASS Directive fails when passed an 8-digit hex value HOT 2
- Push tag v2.0.9 HOT 1
- How do you pass Redcarpet render options through Tilt? HOT 2
- Missing extensions for markdown when using Redcarpet HOT 4
- Pug support HOT 3
- [2.0.10 Regression] Methods defined in a template can't be used later in the template HOT 22
- Slim fails since tilt 2.0.10 HOT 1
- Uninitialized constant problem in Heroku / Sinatra HOT 3
- Test failure: TestSlimEmbeddedEngines#test_render_with_markdown HOT 1
- CVE-2020-14001 Kramdown gem version HOT 8
- Opal support outdated HOT 2
- Not support all options for CommonMarker HOT 1
- uninitialized constant Tilt::Dummy on special conditions HOT 1
- Trying to get in touch regarding a security issue HOT 2
- coffee-script is getting deprecated HOT 7
- Haml::TempleEngine: Option :line is invalid HOT 2
- Warnings when running tests with ruby 3.0 and 3.1 in Debian and Ubuntu HOT 2
- Can we have a Gem release of the current state of Tilt? HOT 3
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from tilt.