-
Notifications
You must be signed in to change notification settings - Fork 1.3k
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
Template registration, first implementation (now in dev-3.x) #1026
Conversation
/** | ||
Simple cache that maps a template name to the revived template functions. | ||
|
||
@property _cache |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm wondering if _registry
is a better name for this property…
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I agree. It makes more sense than _cache
, so I'll change it all around.
About |
+1 |
@clarle I sent you a PR: https://github.com/clarle/yui3/pull/1 with some changes:
|
@clarle here's some improvements on the example based on your comments: https://github.com/clarle/yui3/pull/2 |
|
</dl> | ||
|
||
<p> | ||
Using template registration usually involves taking a precompiled template, and wrapping it as a YUI module. You can use packages such as <a href="https://github.com/yahoo/locator-handlebars">locator-handlebars</a> to do so automatically, by having it find the location of your existing templates. The wrapped pre-compiled template should look something like this: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There is also the module I wrote, mustache-wax, but it is admittedly not as integrated into the Y.Template
sphere as locator-handlebars
is.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I like the patterns
idea that you have there, though we'll probably do more of that on the server-side compilation step. It might be useful to group templates by their templating engine, if we have a project that has precompiled templates with multiple rendering engines.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@evocateur once this lands, would this be something that you'd use in mustache-wax?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@ericf Totally! I've always felt kind of weird by the namespacing options I added to simulate this kind of registry in the past.
Thanks for waiting guys. Sorry I couldn't get to this sooner; I'm swamped. I really like this! I suggested a few minor API doc tweaks above, but otherwise this looks great. Incidentally, I would love to see multi-template registration like @clarle mentioned in the PR description. I would use that all the time. |
templates available from invoking a template to render it. This central | ||
registry and abstraction of templates to names separates concerns, creates a | ||
level of indirection, and enables templates to be easily overridden. | ||
([#1021][]) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I realized I forgot to add the URL to this issue…
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'll do that when I finish up the API docs changes too.
I think I've addressed any outstanding issues, and I've fixed one small bug in the user guide where Anything else before I merge? |
|
Manually merged into |
As discussed in #1021 and the linked gist.
Here's a first drop for template registration, including full tests, user guide documentation, and API docs.
@ericf and I were discussing a possible addition to the
Y.Template.register
API, where it would also accept a hash of template names to template functions. For example:I started implementing something like this, but I wasn't sure what
Y.Template.register(templateHash)
would return. The currentY.Template.register(templateName, template)
returns the revived template to maintain compatibility with therevive()
API.Pinging @caridy also for review.