Support for handlebar partials #842

Merged
merged 26 commits into from Jan 29, 2013

Conversation

Projects
None yet
2 participants
Collaborator

caridy commented Dec 6, 2012

Example:

./MojitName/views/
    foo.hb.html
./MojitName/views/partials/
    bar.hb.html

by following that structure, you should be able to define foo.hb.html like this:

<div id="{{mojit_view_id}}">
    {{> bar}}
</div>

Few more notes:

  • a partial view can be used by any view within the same context/mojit.
  • global partial views are also supported.

Details:

  • adding support for partials in the store. there is now instance.partials with a similar structure than instance.views after expanding the instance.
  • views within partials/* folder are now consider partials, which are an special type of view.
  • adding support for application.json->viewEngine->preloadTemplates to preload any view in memory, and this is disabled by default.
  • consolidating application.json->viewEngine->cacheTemplates as a static config across the board.
  • adding support for preloadTemplates for HB client and server to avoid loading the template if is is part of the expanded instance.
  • adding support for partials on hb client and server.
  • view-renderer is now a class and a factory to avoid creating renderer objects over and over again.
  • removing viewId argument that is not really relevant for this abstraction.
  • using the new Y.mojito.ViewRenderer() factory to access the renderer instance.
  • removing unnecesary dependencies (mojito-perf).
  • removing unnecessary configuration that is not semantically correct for action-context or mojito-client like cacheTemplates and pathToRoot.

Second attempt for PR #683

caridy added some commits Oct 30, 2012

adding support for partials in the store. views within partials/* fol…
…der are now consider partials, which are an special type of view. Adding support for application.json->viewEngine->preloadTemplates to preload any view in memory, and this is disabled by default for now
consolidating application.json->viewEngine->cacheTemplates as a stati…
…c config across the board. Adding support for preloadTemplates for HB client and server to avoid loading the template if is is part of the expanded instance. Adding support for partials on hb client and server.
view-renderer is now a class and a factory to avoid creating renderer…
… objects over and over again. removing viewId argument that is not really relevant for this abstraction.
using the new Y.mojito.ViewRenderer factory to access the renderer in…
…stance. removing unnecesary dependencies and unnecessary configuration that is not semantically correct for action-context or mojito-client
Collaborator

caridy commented Dec 14, 2012

This is set to land on 0.5.2.

Collaborator

caridy commented Jan 24, 2013

Ready for review.

Contributor

drewfish commented Jan 28, 2013

From reading the description:

I worry about getting rid of pathToRoot. It was necessary for some users of mojito build html5app. Evidence strongly suggests that this was no longer being used (dead code) anyways.

HandleBarsAdapter.prototype = {
/**
* Renders the handlebars template using the data provided.
* @param {object} data The data to render.
- * @param {string} mojitType The name of the mojit type.
- * @param {string} tmpl The name of the template to render.
+ * @param {object} instance The expanded mojit instance.
@drewfish

drewfish Jan 28, 2013

Contributor

Passing the whole instance, nice.

+ // in case the engine supports partials
+ if (res.name.indexOf('partials/') === 0) {
+ // removing the "partials/" prefix
+ details.partials[this._libs.path.basename(res.name)] = template;
@drewfish

drewfish Jan 28, 2013

Contributor

This looks like it won't support subdirectories in views/partials/, which might be nice to have.

Contributor

drewfish commented Jan 28, 2013

+1 good stuff.

One comment about supporting subdirectories in views/partials/, but we can add that feature in the future when/if requested.

Collaborator

caridy commented Jan 28, 2013

Thanks @drewfish, I will resolve the conflicts and merge.

caridy added a commit that referenced this pull request Jan 29, 2013

Merge pull request #842 from caridy/partials
Adding support for handlebar partials:
- a partial view (e.g. views/partials/foo.hb.html) can be used by any view within the same context/mojit.
- global partial views are also supported.

@caridy caridy merged commit d7c0e8b into YahooArchive:develop Jan 29, 2013

isao added a commit to isao/mojito that referenced this pull request Jan 29, 2013

isao added a commit that referenced this pull request Jan 29, 2013

Merge pull request #958 from isao/newsboxes
fix unit tests after newsboxes code was updated for pull #842
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment