This repository has been archived by the owner on Oct 30, 2018. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 215
[bz5800733] Handlebars Template Helpers (second attempt after #922) #1011
Merged
Merged
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
0d36bf1
introducing the concept of adapter.page which represents an abstracti…
caridy d5c2031
adding support for custom helpers per instance (instance.helpers) whe…
caridy 091bd6c
refactor on the experimental mojito-models-addon to use the new globa…
caridy 3ba7e9b
introducing mojito-helpers-addon which happens to use the same api th…
caridy 7553005
Merge branch 'develop' of github.com:yahoo/mojito into hb-helpers
caridy File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,92 @@ | ||
/* | ||
* Copyright (c) 2011-2013, Yahoo! Inc. All rights reserved. | ||
* Copyrights licensed under the New BSD License. | ||
* See the accompanying LICENSE file for terms. | ||
*/ | ||
|
||
/*jslint nomen:true*/ | ||
/*global YUI*/ | ||
|
||
/** | ||
* @module ActionContextAddon | ||
*/ | ||
YUI.add('mojito-helpers-addon', function (Y, NAME) { | ||
|
||
'use strict'; | ||
|
||
/** | ||
* <strong>Access point:</strong> <em>ac.helpers.*</em> | ||
* Addon that provides helpers functionalities | ||
* @class Helpers.common | ||
*/ | ||
function Addon(command, adapter) { | ||
this._page = adapter.page; | ||
// exposing instance helpers for render engine can use it, | ||
// also, mixing in any previously exposed helper. | ||
this._helpers = command.instance.helpers = Y.merge({}, | ||
(this._page.helpers || {})); | ||
} | ||
|
||
Addon.prototype = { | ||
|
||
namespace: 'helpers', | ||
|
||
/** | ||
* Gets one specific helper if the name is specified, | ||
* otherwise returns all available helpers. | ||
* @method get | ||
* @param {string} helperName The optional helper name | ||
* @return {function|object} a helper function or all available helpers | ||
*/ | ||
get: function (helperName) { | ||
return helperName ? this._helpers[helperName] : this._helpers; | ||
}, | ||
|
||
/** | ||
* set a helper function at the mojit instance. | ||
* @method set | ||
* @param {string} helperName The helper name. | ||
* @param {function} helper The helper function. | ||
*/ | ||
set: function (helperName, helper) { | ||
if (!helperName || !helper) { | ||
Y.log('Invalid helper name or helper function ' + | ||
'when calling `ac.helpers.set()`: ' + helperName, 'error', NAME); | ||
return; | ||
} | ||
if (this._helpers[helperName]) { | ||
Y.log('Overiding an existing helper function with name: ' + | ||
helperName, 'warn', NAME); | ||
} | ||
this._helpers[helperName] = helper; | ||
}, | ||
|
||
/** | ||
* Expose a helper function as global. On the server side | ||
* this means any mojit instance under a particular request | ||
* can use the helper. On the client, any | ||
* mojit instance on the page can use the helper. | ||
* @method expose | ||
* @param {string} helperName The helper name. | ||
* @param {function} helper Optional helper function, if not | ||
* present, the helper will be lookup by name. | ||
*/ | ||
expose: function (helperName, helper) { | ||
this._page.helpers = this._page.helpers || {}; | ||
// you might want to expose an existing local helper | ||
helper = helper || this._helpers[helperName]; | ||
// exposing thru global page object | ||
this._page.helpers[helperName] = helper; | ||
// exposing at the instance level | ||
this._helpers[helperName] = helper; | ||
Y.log('Exposing a global helper: ' + helperName, 'info', NAME); | ||
} | ||
|
||
}; | ||
|
||
Y.namespace('mojito.addons.ac').helpers = Addon; | ||
|
||
}, '0.1.0', {requires: [ | ||
'mojito', | ||
'mojito-util' | ||
]}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
Oooooooh, me like.