-
Notifications
You must be signed in to change notification settings - Fork 0
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
Templating API #16
Comments
I would say it shouldn't be supported at all by default. If people are using Handlebars they should be precompiling and using Handlebars runtime in prod |
I don't disagree with you. The primary reason I want to support it out-of-the-box is for throwing together a quick example app, like a JSFiddle or Codepen. |
I would prefer using |
Personally, I would greatly prefer to move this to an extension |
I'm not sure if the routing system I'm developing will work with Underscore. If it does work with Underscore, then, sure, Underscore could be the default. Otherwise, what do you propose that I do? |
Maybe I'll make this an officially-supported plugin. It would suck for Codepens tho' |
Why build a system for them? In general, they're just functions that take a |
What do you mean?
Mhm, mhm. These methods would be really small, for the most part. Examples are already in the repo. |
The resolving/compiling/caching/rendering functions. I haven't found a need for it, and it gently nudges people away from templates in one giant HTML file -- I really dislike giant files full of unrelated things.
When ever I'm doing really small demos, it's not hard to whip up a jQuery resolver myself. function template(selector) {
return template[selector] || (template[selector] = _.template($(selector)));
}
var View = Mn.View.extend({
template: template('#main-view-template')
}); It's just never seemed necessary to formalize this into anything, especially not into a system as complex as Marionette's. Anything that means less code for the library is a net win, I think. |
Hmmm...I'm not sure if including nothing nudges anyone toward anything, though?
For confident developers, I agree. It's simple enough to write these 10 or so lines of code and move on with things. But not all developers are so confident with coming up with systems like that. Perhaps it's fear of building something that doesn't scale, but on the teams I've worked with, Backbone's lack of opinion only leads to indecision, a feeling of doing it 'wrong,' and an overall loss of productivity. If I can include a few extra lines of code to alleviate any of that, then I think that that is a really good thing! |
Marionette's template API is potentially more complex than it needs to be. TemplateCache and Renderer are the two abstractions in Marionette for doing things with templates, yet I'm not sure if they're a good idea.
The actions that these two things do are:
This works, but it strikes me as an odd systems. In Puppets, the system could possibly be conceptually simpler. Rather than grouping these actions into two arbitrary objects, I will approach each of them as independent things.
Resolving templates
A common default resolution mechanism is to make AJAX requests to fetch templates from the server. LayoutManager and Angular take this approach. In Puppets, I will discourage this to the extent that it won't be as easily configured. Rather, the default will look for the templates at:
Puppets.templates
which is more similar to Ember's approach. This will encourage users to precompile their templates into functions.
Proposed API:
Puppets.resolveTemplate( templateName )
Fetch a compiled or precompiled template by name.
Compiling templates
Compiling templates on the fly will be discouraged, but it will be possible out-of-the-box. The API
will look like:
Puppets.compileTemplate( templateString )
This would be Handlebars by default.
Caching templates
A lightweight
Puppets.Cache
object should be created. Each instance of Puppets should create a new one for the templates, and store it asPuppets.templateCache
.Puppets.templateCache.get( templateName )
Puppets.templateCache.set( templateName )
Rendering templates
Last but not least is the render method.
Puppets.renderTemplate( templateFunction, data )
The text was updated successfully, but these errors were encountered: