Skip to content
This repository has been archived by the owner on Oct 30, 2018. It is now read-only.

[bz5800733] Handlebars Template Helpers (second attempt after #922) #1011

Merged
merged 5 commits into from
Feb 26, 2013

Conversation

caridy
Copy link
Contributor

@caridy caridy commented Feb 26, 2013

This PR introduces the concept of helpers thru an addon called mojito-helpers-addon. Any mojito requiring this addon will be able to:

  • register a helper function at the instance level
  • register a helper function and expose it at the request level (when in the server)
  • register a helper function and expose it at the page level (when in the client)
  • expose an already registered helper function

API

  • ac.helpers.set(name, func) to set a local helper
  • ac.helpers.get(name) in case you want to get a handler on a global or even local that was registered somewhere
  • ac.helpers.expose(name, func) to make it available locally but also exposing it globally
  • ac.helpers.expose(name) in case you want to expose an existing helper.

How does it work?

Under the hood, any helper function, locally set using ac.helpers.set() or globally exposed by any of the parent mojits using ac.helpers.expose() will be passed into the handlebars render engine, so you can use them in your templates/views.

Limitations and things to keep in mind

  • You will be able to override any default helper provided by Y.Handlebars since the custom helper functions will have priority. This also mean you can break the default handlebar helpers, so be careful.
  • You will not be able to use helpers when using mojitProxy.render() or mojitProxy.refreshView(), only thru mojitProxy.invoke().
  • You will not be able to use helpers when using mojitProxy.invoke() if the helper is supposed to be defined by another mojit that was not instantiated prior to the invoke.

Examples

https://github.com/caridy/mojito-demos/tree/master/mojito-helpers

…on of req in the server and doc in the client. This structure could be use to store data per request on the server and per page on the client. at the moment, this structure will not be serialized or used after the dispatcher ends
…l adapter.page object to expose models per request. also, changing the api to align with helpers
…at mojito-models-addon uses. this is experimental in 0.5.5
@caridy
Copy link
Contributor Author

caridy commented Feb 26, 2013

ping issue #922

@@ -30,6 +30,7 @@ var NAME = 'OutputHandler.server',
this.res = res;
this.next = next;
this.headers = {};
this.page = {};
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oooooooh, me like.

@drewfish
Copy link
Contributor

+2

caridy added a commit that referenced this pull request Feb 26, 2013
Closes PR #922. Fixes bz5800733. Adds support for handlebars template helpers thru mojito-helpers-addon. Consolidates mojito-models-addon api.
@caridy caridy merged commit 4b776c4 into YahooArchive:develop Feb 26, 2013
@rwaldura
Copy link
Contributor

@gotwarlost check this out, released in 0.5.5 today
https://github.com/yahoo/mojito/wiki/ReleaseNotes0_5_5

@gotwarlost
Copy link

already incorporated :)

@caridy
Copy link
Contributor Author

caridy commented Feb 28, 2013

Just keep in mind that this feature is EXPERIMENTAL and API might change in the future. If you use it, and it is fine to use it, you will be in the bleeding edge of mojito :).

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants