Skip to content

Support for handlebar partials #842

Merged
merged 26 commits into from Jan 29, 2013

2 participants

@caridy
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
@caridy caridy 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
374826d
@caridy caridy 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.
9a40739
@caridy caridy 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.
da53ea3
@caridy caridy 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
6b2a5c4
@caridy caridy getting pr4 merged for partials 459bd50
@caridy caridy adding warning and moving assets for top level views to exclude them …
…from partials
a2311e4
@caridy caridy Merge branch 'develop-perf' of git://github.com/yahoo/mojito into par…
…tials
82fcda6
@caridy caridy Merge branch 'yui-name-collision' of github.com:caridy/mojito into gl…
…obal-models
baed690
@caridy caridy supporting registration of global models f5251aa
@caridy caridy Merge branch 'develop-perf' of git://github.com/yahoo/mojito into par…
…tials
5948e36
@caridy caridy Merge branch 'develop-perf' of git://github.com/yahoo/mojito into par…
…tials
e6499c5
@caridy caridy Merge branch 'develop-perf' of git://github.com/yahoo/mojito into par…
…tials
9d75095
@caridy caridy merge partials and 0.5.0GA 2044d1f
@caridy caridy Merge branch 'develop' of yahoo/mojito into partials 5721724
@caridy
caridy commented Dec 14, 2012

This is set to land on 0.5.2.

@caridy
caridy commented Jan 24, 2013

Ready for review.

@drewfish
Yahoo Inc. member

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.

@drewfish drewfish commented on the diff Jan 28, 2013
lib/app/addons/view-engines/hb.client.js
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
Yahoo Inc. member
drewfish added a note Jan 28, 2013

Passing the whole instance, nice.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
@drewfish drewfish commented on the diff Jan 28, 2013
lib/app/autoload/store.server.js
- details.views[res.name] = {};
- }
- if (env === 'client') {
- details.views[res.name]['content-path'] = res.url;
+ template = {
+ 'content-path': (env === 'client' ?
+ this._libs.path.join(this._appConfigStatic.pathToRoot || '', res.url) :
+ res.source.fs.fullPath),
+ 'content': res.content,
+ 'engine': res.view.engine
+ };
+ // we want to separate partials from actual templates
+ // 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
Yahoo Inc. member
drewfish added a note Jan 28, 2013

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
@drewfish
Yahoo Inc. member

+1 good stuff.

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

@caridy
caridy commented Jan 28, 2013

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

@caridy caridy merged commit d7c0e8b into yahoo:develop Jan 29, 2013
@isao isao added a commit to isao/mojito that referenced this pull request Jan 29, 2013
@isao isao fix unit tests after newsboxes code was updated for pull #842 71e02ac
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.