Skip to content
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

Add rendrApp to the Handlebars object #1

Open
wants to merge 143 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
143 commits
Select commit Hold shift + click to select a range
6159198
Refactor to not use Handlebars as global; getTemplate & getLayout met…
spikebrehm Jun 1, 2013
acdcf9b
Create and expose a 'registerHelpers' method, for use by app
spikebrehm Jun 29, 2013
a4f6273
Release 0.0.2.
spikebrehm Jun 29, 2013
4ca5632
Update the peerDependency for rendr
spikebrehm Jun 29, 2013
a63fcc5
Move rendr to dependencies from peerDependencies
spikebrehm Jun 29, 2013
4880255
Update Handlebars to one commit past 1.0.12, to support CommonJS.
spikebrehm Jul 12, 2013
03c3c7d
Release 0.0.4.
spikebrehm Jul 12, 2013
ace4328
0.0.5: Use ref of handlebars that includes parser.js
spikebrehm Jul 14, 2013
9ffe9be
0.0.6: Add support for multiple template source files.
spikebrehm Jul 31, 2013
c0ecf29
Using regexp instead of 'minimatch' for better browser compat
spikebrehm Jul 31, 2013
243396e
Can't use 'util' module in shared environment
spikebrehm Aug 2, 2013
fd81f58
Merge pull request #1 from airbnb/template-pattern
Aug 3, 2013
f4e5c2f
Use [email protected]
spikebrehm Aug 3, 2013
261acba
Fix use of {{partial}} inside block helper like {{each}}
spikebrehm Oct 24, 2013
c97c9cf
More sane Rendr version ref: >=0.4.9
spikebrehm Oct 24, 2013
5e207bc
Release 0.0.7.
spikebrehm Oct 24, 2013
28febc5
Merge pull request #4 from airbnb/fix-partial-in-each
Oct 25, 2013
2489bfd
Release 0.0.8.
spikebrehm Oct 25, 2013
9c110c8
move rendr dependency to peerDependencies
c089 Nov 3, 2013
d4a0477
adjust engines.npm to ensure support for peerDeps
c089 Nov 3, 2013
5369c68
Merge pull request #6 from c089/use-peer-dependency-for-rendr
Nov 3, 2013
40e4c9a
Made it play nice with RequireJs powered setup.
alexindigo Nov 6, 2013
b87d17f
Adjust compiled templates loader to suport AMD.
alexindigo Nov 13, 2013
4b3c2bc
Made globals dependency more vocal.
alexindigo Nov 22, 2013
7366814
consume the entryPath and return a new version of the templateAdapter
trshafer Nov 21, 2013
27dc5ff
Version bump
trshafer Nov 21, 2013
400850b
Merge pull request #9 from givingstage/remove_global_entry_path
Nov 23, 2013
67195e9
Release 0.1.0
spikebrehm Nov 23, 2013
657c998
Merge changes from master
alexindigo Dec 2, 2013
4e7696e
Merge pull request #7 from alexindigo/master
Dec 4, 2013
b204579
Remove references to global 'rendr'
spikebrehm Dec 11, 2013
56ac927
Update helpers.js
mattpardee Dec 11, 2013
1092c7f
Small style tweaks
spikebrehm Dec 20, 2013
5e2e506
Release 0.2.0-rc1.
spikebrehm Dec 20, 2013
6e9bee5
Merge pull request #11 from mattpardee/master
Dec 20, 2013
4427cb7
Add .travis.yml; closes #10
spikebrehm Dec 20, 2013
3065208
Merge pull request #12 from airbnb/travis-ci
Dec 20, 2013
b114215
Add Travis CI, David DM badges to README
Dec 20, 2013
48a58d0
Update README.md
Dec 20, 2013
7bcc2fc
Update to [email protected] to match rendr
spikebrehm Dec 20, 2013
6e53630
Update peerDependency to [email protected]
spikebrehm Dec 20, 2013
2e12160
save the original Handlebars each function module wide
Feb 13, 2014
40c9416
don’t hide the require path from browserify
Feb 13, 2014
a0e7ee7
added tests for rendr-bundled Handlebars each helper
Feb 14, 2014
26bcd62
Merge pull request #16 from lusini/Fixes-the-each-helper-function
lo1tuma Feb 14, 2014
3cdfcba
Merge pull request #17 from lusini/fix-browserify-compatibility
c089 Feb 14, 2014
bf35ef9
Upgrade to [email protected]
spikebrehm Feb 14, 2014
50503d8
Merge pull request #18 from airbnb/handlebars-upgrade
Feb 14, 2014
ac99347
Add vim swapfiles to gitignore
spikebrehm Feb 14, 2014
fd426a4
Version 0.2.0-rc2
spikebrehm Feb 14, 2014
b7d6dc4
Merge pull request #19 from airbnb/version-0.2.0-rc2
Feb 17, 2014
2e655f1
Removing lazyLoading circus.
alexindigo Feb 18, 2014
6cfd66e
Merge pull request #20 from alexindigo/master
c089 Feb 18, 2014
6ee6373
change urls to new GH organization
Feb 24, 2014
ec40695
Merge pull request #22 from lusini/change-urls-to-new-gh-organization
Feb 24, 2014
54bb9be
Update repo in package.json to rendrjs/rendr-handlebars
spikebrehm Feb 24, 2014
c8c17b7
Bump to 0.2.0 for [email protected]
spikebrehm Feb 25, 2014
a792785
Merge pull request #23 from rendrjs/version-0.2.0
lo1tuma Feb 25, 2014
4c99355
Add LICENSE
spikebrehm Aug 5, 2014
8d1eb89
Updated the view helper to only create an instance of the view if it'…
Oct 2, 2014
553b45b
make sure that app is set for setting up models, but isn't passed int…
Oct 17, 2014
5029737
globals are bad
Oct 23, 2014
473c7f7
update the version to be 0.2.1 of rendr, and this fix requires rendr …
Nov 4, 2014
96b0c53
Merge pull request #26 from saponifi3d/fix_double_initialization
saponifi3d Nov 4, 2014
b80b201
Update HISTORY.md
saponifi3d Dec 12, 2014
4f0efa7
Stringify nested object options
mattpardee Dec 15, 2014
9e8f772
Merge pull request #1 from change/nested-options-fix
mattpardee Dec 15, 2014
df48205
Merge pull request #28 from change/master
saponifi3d Jan 5, 2015
b0c1d89
created a forEach helper that will add things like indx, total, isFir…
Jan 6, 2015
db4b6ce
Merge pull request #29 from saponifi3d/forEach-helper
saponifi3d Jan 7, 2015
c23ab43
restuctured the helpers
Jan 7, 2015
8ed0aa8
cleaned up the view function
Jan 8, 2015
c23c953
Merge pull request #30 from saponifi3d/restructure-helpers
saponifi3d Jan 8, 2015
474605c
allow partials and views to be passed block elements
Jan 8, 2015
f57466b
Merge pull request #31 from saponifi3d/pass-blocks
saponifi3d Jan 8, 2015
429bfa0
added dev dependencies for testing
Jan 8, 2015
58427ca
added tests for the forEach helper
Jan 8, 2015
956632d
run all tests with *.test.js in teh test directory
Jan 8, 2015
60ff9c4
added a test for json helper
Jan 8, 2015
1b84a29
moved the each test from helpers.test.js to each.test.js, changed hel…
Jan 8, 2015
c5e402f
added tests for partial helper
Jan 8, 2015
7181b00
removed the test for the view for now because it's really intense and…
Jan 8, 2015
1bb4610
Update README.md
saponifi3d Jan 8, 2015
b262a0d
Merge pull request #32 from saponifi3d/add-helper-tests
saponifi3d Jan 8, 2015
19138db
Update README.md
saponifi3d Jan 9, 2015
2c44a25
upgrade dependency tree
Jan 9, 2015
d2c2f12
Merge pull request #33 from rendrjs/upgrade-deps
saponifi3d Jan 9, 2015
8fc7081
Update README.md
saponifi3d Jan 9, 2015
88bc3b8
version bump to 0.2.2
Jan 9, 2015
2a3745c
Update README.md
saponifi3d Jan 9, 2015
e8b6b0a
Update README.md
saponifi3d Jan 9, 2015
ac4366c
Update HISTORY.md
saponifi3d Jan 9, 2015
e538f1b
add forgotten require
wvengen Jan 14, 2015
4aa0a57
Merge pull request #34 from wvengen/master
saponifi3d Jan 22, 2015
2a776db
added some pending tests for the view helper. need to do some work wi…
Jan 22, 2015
8650c48
drop node 0.8 support
Jan 22, 2015
852da39
Merge pull request #38 from rendrjs/test-view-helper
saponifi3d Feb 2, 2015
9a6dba9
Stringify arrays when returning string for client placeholder
Feb 2, 2015
d145f55
Merge pull request #40 from jordanfbrown/stringify-arrays-on-client
saponifi3d Feb 2, 2015
e0120e9
Serialize objects and added test
mattpardee Feb 2, 2015
31937c0
Spellcheck
mattpardee Feb 2, 2015
2d2ec1b
Merge pull request #41 from mattpardee/stringify-object-values
saponifi3d Feb 2, 2015
dc9d6e1
minor rev for a few bug fixes
Feb 3, 2015
112c43c
Update HISTORY.md
saponifi3d Feb 3, 2015
d679f2d
fix bug where '_' attributes aren't defined for blocks.
Feb 3, 2015
b12e804
Merge pull request #43 from rendrjs/block-opts
saponifi3d Feb 3, 2015
cbaa229
upgrade to 0.2.4 with the fix for blocks
Feb 3, 2015
ec840e3
Update HISTORY.md
saponifi3d Feb 3, 2015
bc939c6
Don't include data attributes that are present in the fetch summary
Feb 4, 2015
9ff4ced
Set _app by binding context instead of in data
Feb 4, 2015
d7b4f62
Merge pull request #46 from jordanfbrown/omit-fetch-params-keys
saponifi3d Feb 4, 2015
5f3f50f
add serverToClientJson helper - this should be set when you pass any …
Feb 24, 2015
7631e80
verify that the string is what we'd want and the data is parsed the w…
Feb 25, 2015
f1ee88e
Merge pull request #48 from rendrjs/server-2-client-json
saponifi3d Feb 25, 2015
d45a71a
upgrade dependencies and fix tests that broke when upgrading chai
Feb 25, 2015
36045af
fixed tests to use .to.have.property instead of .to.equal
Feb 25, 2015
b5be754
cleanup on the to.deep.equal tests to hceck the property and it's value
Feb 25, 2015
62ebe06
Merge pull request #49 from rendrjs/update-dependencies
saponifi3d Feb 25, 2015
44c1345
bump to version 1.0.0 because of breaking changes with handlebars 2.0.0
Feb 25, 2015
a9f4bca
Update HISTORY.md
saponifi3d Feb 25, 2015
d98c3f6
Update README.md
saponifi3d Feb 25, 2015
4dd4ef8
Update README.md
saponifi3d Feb 25, 2015
792edf4
Only ship the handlebars runtime to the client
jmerrifield Feb 28, 2015
c475c50
Allow an instance of templateFinder to be passed in
jmerrifield Mar 3, 2015
1819995
Merge pull request #51 from jmerrifield/dependency-injection
saponifi3d Mar 4, 2015
a52726b
Update README.md
saponifi3d Mar 4, 2015
2f9c955
Update README.md
saponifi3d Mar 4, 2015
fa4daf4
Update README.md
saponifi3d Mar 4, 2015
45ec245
Merge pull request #50 from jmerrifield/runtime-only-on-client
saponifi3d Mar 26, 2015
e9e75ac
update to 1.0.1
Mar 26, 2015
4065e4a
remove handlebars as a dependency, get it as init param
ingiulio Apr 29, 2015
bf8b39e
add supported Handlebars version to README
ingiulio Jun 28, 2015
3108484
Merge pull request #52 from ingiulio/decoupleFromHandlebars
saponifi3d Jul 11, 2015
816c74e
Update to 2.0.0, because we are removing handlebars as a dependency t…
Jul 17, 2015
06d51d2
Update package.json
saponifi3d Jul 20, 2015
cbca1b1
version 2.0.1
Jul 31, 2015
b770611
check if collection is a collection object before checking whether it…
Oct 7, 2015
a6bdf02
add test for empty collection calling the inverse function
Oct 7, 2015
7b3b7a6
Merge pull request #56 from sarchila/SA-forEach-else
jmerrifield Oct 8, 2015
afe3c41
fix nested partial view client render issue
Feb 11, 2016
7e92d65
changed type compare to instanceof and added test
Feb 23, 2016
a3e81fd
Merge pull request #59 from brian-hall/fix_partial_view_nesting
saponifi3d Feb 24, 2016
df63328
Update the package / HISTORY
Mar 1, 2016
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
node_modules
npm-debug.log
*.sw?
5 changes: 5 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
language: node_js
node_js:
- "0.10"
notifications:
email: false
50 changes: 50 additions & 0 deletions HISTORY.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
# 2.0.2
* bugfix for the forEach / else helper
* bugfix for parital -> view nesting

# 2.0.1
* Bug fix for the peerDependency of rendr to be at 1.1.0 instead of 1.2.0.

# 2.0.0
* handlebars is no longer included here, it needs to be installed at the app level.

# 1.0.1
## 2015-03-26
* allow instance of templateFinder to be passed in
* only ship handlbars runtime, greatly reduces client bundle size

# 1.0.0
## 2015-02-24
* update to handlebars 2.0.0
* update to underscore 1.8.2
* add serverToClientJson for an example of how to escape JSON between the client and server
* omit anything in the fetch params that as a data attribute

# 0.2.4
## 2015-02-03
* invoke block views with the parent scope

# 0.2.3
## 2015-02-03
* stringify objects
* added view tests
* fixed missing require for underscore

# 0.2.2
## 2015-01-08
* Changed the shared/helpers to follow a CommonJS pattern of requiring each helper separately
* added tests for the helpers
* added a `forEach` helper
* added documentation for all the helpers
* added ability to pass blocks into partials / views
* upgrade to [email protected]

# 0.2.1
## 2014-12-11
* Removed need to initialize the view twice on the client-side. This fixed leaking listeners and makes the code perform as expected

# 0.2.0
## 2014-02-25
* Add support for AMD modules.
* Upgraded to [email protected].
* Upgraded to [email protected].
22 changes: 22 additions & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
Copyright (c) 2013-2014 Adam Hull & Airbnb, Inc

Permission is hereby granted, free of charge, to any person
obtaining a copy of this software and associated documentation
files (the "Software"), to deal in the Software without
restriction, including without limitation the rights to use,
copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the
Software is furnished to do so, subject to the following
conditions:

The above copyright notice and this permission notice shall be
included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
OTHER DEALINGS IN THE SOFTWARE.
158 changes: 157 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,160 @@
[![travis-ci status](https://secure.travis-ci.org/rendrjs/rendr-handlebars.png)](http://travis-ci.org/#!/rendrjs/rendr-handlebars/builds)
[![Dependency Status](https://david-dm.org/rendrjs/rendr-handlebars.png)](https://david-dm.org/rendrjs/rendr-handlebars)

rendr-handlebars
================

[Handlebars](http://handlebarsjs.com/) template adapter for [Rendr](https://github.com/airbnb/rendr) apps.
[Handlebars](http://handlebarsjs.com/) template adapter for [Rendr](https://github.com/rendrjs/rendr) apps.
This library has been tested using [Handlebars 2.0.0](https://github.com/wycats/handlebars.js/tree/v2.0.0).

If you'd like to use a more recent version number of `Handlebars` for your app, just specify it in the [package.json](https://github.com/rendrjs/rendr/blame/master/README.md#L315) of your app and start testing it.


## Configuration options

- `entryPath` *optional* - change the location of the application for the given rendr-app.
- `templateFinder` *optional* - allows the ability to require a different template finder. Commonly used to make a non-dynamic version of `require` to make build systems more efficient.

## Helpers

There are a number of variables that are set by default to these helpers and are passed in the context. Those variables include:
- `_app` - The instance of the Rendr application
- `_model` - when setting the `model` attribute, the `_model` variable will be set as the instance of a Rendr model.
- `_collection` - when using a `collection` attribute, the `_collection` variable will be set to the instance of the Rendr collection.
- `_block` - when passing a block to the `view` or `partial` helper, the `_block` variable will be available. This `_block` variable will be the HTML passed in.


#### view
------
The view helper is used to insert a new Rendr view. This is done on the server-side by generating the html and inserting it inline. On the client-side it creates a placeholder, and then in Rendr it will call the `attach` function to create a view instance and insert the HTML. If you don't pass any attributes to the helper, it sets the context (or scope) of the helper to the same as the parents.

You can also pass a block into the helper and it will be available inside of the created view as `_block`. This is helpful when you want to have a chunk of HTML differ in a view, but have the majority of it stay the same.

Example:
```
// no attributes
{{ view "viewName" }}

{{ view "viewName" model=_model an_option="my option" }}

// with a block
{{ view "viewName" }}
<div class="test">My Block</div>
{{/view}}
```


#### partial
------
A partial is HTML only, and it is inserted at compile time of the templates, making them more performant than a view. These are good to use in cases where you don't have any view interaction and just want to reduce the amount of copied HTML. This will inherit the parents context if no attributes are passed into the helper.

Again, you can pass a block into the partial and access the `_block` variable inside of the partial. This is helpful when you want to set a variable chunk of HTML inside of a partial

Example:
```
// no attributes
{{ partial "partialName" }}

{{ partial "partialName" attr="example" }}

// with block
{{ partial "partialName" }}
<div class="test">My Block</div>
{{/partial}}
```


#### json
------
This helper simply takes an object and runs `JSON.stringify` on the object. You can also pass the [spacing](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/JSON/stringify#space_argument) into the helper.

Example:
```
{{json myObject}}

// with spacing
{{ json myObject " " }}
```


#### each
------
Iterates an array setting the context to the value of the array element. Works as you would expect the Handlebars [each](http://handlebarsjs.com/builtin_helpers.html#iteration) helper to work, but this adds Rendr specific options set in the context (`_app`, `_model`, `_collection`, `_block`)

Example:
```html
<ul>
{{ each arr }}
<li>{{this}}<li>
{{/each}}
</ul>
```


#### forEach
------
Another helper to iterate items in the template, this has a bit more included though. You can iterate objects, arrays, or Collections with this, setting the value and the key attributes in the scope.

Always available in the `forEach` helper
- `key` - The key on the object, or the index in the array
- `value` - The value of the item being iterated.

If iterating arrays or collections there is extra data included:
- `_isFirst` - Boolean, is true if it's the first item in the array / collection
- `_isLast` - Boolean, is true if it's the last item in the array / collection
- `_total` - The number of items in the array / collection

If iterating an instance of a collection, you can set the `toJSON` attribute to convert the model being iterated into JSON instead of an instance of the model. By default the `value` will be set to a Backbone model when iterating a collection.

Example:
```html
<!-- iterating an object -->
<h1>for each obj test</h1>
{{forEach obj}}
<div>{{ key }} :::: {{ value }}</div>
{{/forEach}}

<!-- inverse available -->
{{forEach arr}}
<div>{{ value }}</div>
{{else}}
<div>Array is empty</div>
{{/forEach}}

<!-- pass variables into the scope -->
{{forEach arr attribute="test"}}
<div>{{attribute}}</div>
{{/forEach}}

<!-- where value is what is stored in the array, can also store an array of objects
and access them on the value with the dot operator -->
<h1>for each array of objs test</h1>
{{forEach arr}}
{{if _isFirst}}
<div>Will only display for first element in array and collection</div>
{{/if}}

{{if _isLast}}
<div>Will only display for last element in array and collection</div>
{{/if}}
<span>{{ value }}</span>
{{/forEach}}

<!-- array of a collection which returns a model -->
<h1>for each array of objs test</h1>
{{forEach myCollection}}
<span>{{ key }} :::: {{ value.attributes.someAttr }}</span>
{{/forEach}}

<!-- array of collection which turns models into json -->
<h1>for each array of objs test toJSON</h1>
{{forEach myCollection toJSON=true}}
<span>{{ key }} :::: {{ value.someAttr }}</span>
{{/forEach}}

<!-- can be used in conjunction with the view operator to pass the model to child views -->
<h1>forEach collection -> subview</h1>
{{forEach myCollection }}
{{view model=value model_name="ExampleModel"}}
{{/forEach}}
```
72 changes: 67 additions & 5 deletions index.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,68 @@
require('./shared/globals');
module.exports = function(options, Handlebars) {

exports.templateFinder = require('./shared/templateFinder');
if(!this.window) {
exports.layoutFinder = require('./server/layoutFinder');
}
if (Handlebars['default']) {
// If we only have the Handlebars runtime available, use that here.
// Until Handlebars 3, we have to use 'default' instead of just requiring 'handlebars'.
Handlebars = Handlebars['default'];
}

var localExports = {},
templateFinder = options.templateFinder || require('./shared/templateFinder')(Handlebars);

/**
* Export the `Handlebars` object, so other modules can add helpers, partials, etc.
*/
localExports.Handlebars = Handlebars;

/**
* `getTemplate` is available on both client and server.
*/
localExports.getTemplate = templateFinder.getTemplate;

/**
* Expose `templatePatterns` for manipulating how `getTemplate` finds templates.
*/
localExports.templatePatterns = templateFinder.templatePatterns;

/**
* The default pattern `/.+/` is very greedy; it matches anything, including nested paths.
* To add rules that should match before this default rule, `unshift` them from this array.
*/
localExports.templatePatterns.push({pattern: /.+/, src: options.entryPath + 'app/templates/compiledTemplates'})

/**
* `getLayout` should only be used on the server.
*/
if (typeof window === 'undefined') {
// server only, "hide" it from r.js compiler
// by having require statement with variable
var serverOnlyLayoutFinderPath = './server/layoutFinder';
localExports.getLayout = require(serverOnlyLayoutFinderPath)(Handlebars).getLayout;
} else {
localExports.getLayout = function() {
throw new Error('getLayout is only available on the server.');
};
}

/**
* Register helpers, available on both client and server.
*
* Export it so other modules can register helpers as well.
*/
localExports.registerHelpers = function registerHelpers(helpersModule) {
var helpers = helpersModule(Handlebars, localExports.getTemplate);

for (var key in helpers) {
if (!helpers.hasOwnProperty(key)) continue;
Handlebars.registerHelper(key, helpers[key]);
}
};

/**
* Register the pre-bundled Rendr helpers.
*/
var rendrHelpers = require('./shared/helpers');
localExports.registerHelpers(rendrHelpers);

return localExports;
}
25 changes: 25 additions & 0 deletions lib/getOptions.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
/**
* Grab important underscored properties from the current context.
* These properties come from BaseView::decorateTemplateData().
*/
module.exports = function (obj) {
var options, keys, value;

keys = [
'_app',
'_view',
'_model',
'_collection',
'_block'
];

options = keys.reduce(function(memo, key) {
value = obj[key];
if (value) {
memo[key] = value;
}
return memo;
}, {});

return options;
};
9 changes: 9 additions & 0 deletions lib/getProperty.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
/**
* Get a property that is being passed down through helpers, such as `_app`
* or `_view`. It can either live on the context, i.e. `this._app`, or in the
* `options.data` object passed to the helper, i.e. `options.data._app`, in the
* case of a block helper like `each`.
*/
module.exports = function (key, context, options) {
return context[key] || (options.data || {})[key];
}
Loading