Skip to content

Commit

Permalink
Initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
rdner authored and Denis Rechkunov committed Feb 9, 2015
0 parents commit d0f55db
Show file tree
Hide file tree
Showing 13 changed files with 4,128 additions and 0 deletions.
10 changes: 10 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
node_modules
.idea
*.log
.DS_Store
.DS_Store?
._*
.Spotlight-V100
.Trashes
ehthumbs.db
Thumbs.db
78 changes: 78 additions & 0 deletions .jscsrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
{
"excludeFiles": [
"./**/node_modules/**",
"./lib/vendors/**",
"./browser/vendors/**",
"./node_modules/**"
],

"requireCurlyBraces": [
"if",
"else",
"for",
"while",
"do",
"try",
"catch"
],

"requireSpaceBeforeBlockStatements": true,
"requireParenthesesAroundIIFE": true,
"requireSpacesInConditionalExpression": {
"afterTest": true,
"beforeConsequent": true,
"afterConsequent": true,
"beforeAlternate": true
},

"requireSpacesInAnonymousFunctionExpression": {
"beforeOpeningRoundBrace": true,
"beforeOpeningCurlyBrace": true
},
"requireSpacesInNamedFunctionExpression": {
"beforeOpeningCurlyBrace": true
},
"disallowSpacesInNamedFunctionExpression": {
"beforeOpeningRoundBrace": true
},

"requireBlocksOnNewline": true,
"disallowEmptyBlocks": true,
"disallowSpacesInsideObjectBrackets": "all",
"disallowSpacesInsideArrayBrackets": "all",
"disallowSpacesInsideParentheses": true,
"disallowQuotedKeysInObjects": true,
"disallowSpaceAfterObjectKeys": true,
"requireSpaceBeforeObjectValues": true,
"requireCommaBeforeLineBreak": true,
"requireOperatorBeforeLineBreak": true,
"disallowSpaceAfterPrefixUnaryOperators": true,
"disallowSpaceBeforePostfixUnaryOperators": true,
"requireSpaceBeforeBinaryOperators": true,
"requireSpaceAfterBinaryOperators": true,
"disallowImplicitTypeConversion": [
"numeric", "boolean", "binary", "string"
],
"requireCamelCaseOrUpperCaseIdentifiers": true,
"disallowKeywords": ["with", "let", "void"],
"disallowMultipleLineBreaks": true,
"disallowMixedSpacesAndTabs": true,
"disallowTrailingWhitespace": true,
"disallowTrailingComma": true,
"disallowKeywordsOnNewLine": ["else", "catch"],
"maximumLineLength": 80,
"requireCapitalizedConstructors": true,
"requireDotNotation": true,
"disallowYodaConditions": true,
"disallowNewlineBeforeBlockStatements": true,
"validateLineBreaks": "LF",
"validateQuoteMarks": "'",
"validateIndentation": "\t",
"validateParameterSeparator": ", ",
"validateJSDoc": {
"checkParamNames": true,
"checkRedundantParams": true,
"requireParamTypes": true
},
"safeContextKeyword": ["self"]
}
3 changes: 3 additions & 0 deletions .jshintignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
lib/vendors
browser/vendors
node_modules
22 changes: 22 additions & 0 deletions .jshintrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
{
"maxerr": 15,

"nonew": true,
"proto": true,
"maxparams": 5,
"maxdepth": 3,
"maxstatements": 50,
"maxcomplexity": 10,

"globalstrict": true,

"browser": false,
"node": true,

"globals": {
"Promise": true,
"window": true,
"describe": true,
"it": true
}
}
11 changes: 11 additions & 0 deletions .npmignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
node_modules
.idea
.git
*.log
.DS_Store
.DS_Store?
._*
.Spotlight-V100
.Trashes
ehthumbs.db
Thumbs.db
19 changes: 19 additions & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
Copyright (c) 2010 Aleksander Williams

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.
29 changes: 29 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
#Catberry Handlebars Adapter

[![NPM](https://nodei.co/npm/catberry-handlebars.png)](https://nodei.co/npm/catberry-handlebars/)

It is an adapter for [Handlebars](http://handlebarsjs.com/) template engine
that makes possible to use it from [Catberry](https://github.com/catberry/catberry) application.

##Usage
You can use the adapter like this in ./browser.js or ./server.js.
Actually, [Catberry CLI](https://github.com/catberry/catberry-cli) does it for you.

```javascript
var handlebars = require('catberry-handlebars'),
cat = catberry.create(config);
handlebars.register(cat.locator);
```

##Contribution
If you have found a bug, please create pull request with [mocha](https://www.npmjs.org/package/mocha)
unit-test which reproduces it or describe all details in an issue if you can not
implement test. If you want to propose some improvements just create an issue or
a pull request but please do not forget to use `npm test` to be sure that your
code is awesome.

All changes should satisfy this [Code Style Guide](https://github.com/catberry/catberry/blob/4.0.0/docs/code-style-guide.md).

Also your changes should be covered by unit tests using [mocha](https://www.npmjs.org/package/mocha).

Denis Rechkunov <[email protected]>
87 changes: 87 additions & 0 deletions browser/TemplateProvider.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
/*
* catberry-handlebars
*
* Copyright (c) 2015 Denis Rechkunov and project contributors.
*
* catberry-handlebars's license follows:
*
* 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.
*
* This license applies to all parts of catberry-handlebars that are not externally
* maintained libraries.
*/

'use strict';

module.exports = TemplateProvider;

/**
* Creates new instance of Handlebars template provider.
* @param {Handlebars} $handlebars Handlebars factory.
* @constructor
*/
function TemplateProvider($handlebars) {
this._handlebars = $handlebars;
this._templates = {};
}

/**
* Current Handlebars factory.
* @type {Handlebars}
* @private
*/
TemplateProvider.prototype._handlebars = null;

/**
* Current set of registered templates.
* @type {Object}
* @private
*/
TemplateProvider.prototype._templates = null;

/**
* Registers compiled (precompiled) Handlebars template.
* http://handlebarsjs.com/reference.html
* @param {String} name Template name.
* @param {String} compiled Compiled template source.
*/
TemplateProvider.prototype.registerCompiled = function (name, compiled) {
this._templates[name] = this._handlebars.template(compiled);
};

/**
* Renders template with specified data.
* @param {String} name Name of template.
* @param {Object} data Data context for template.
* @returns {*}
*/
TemplateProvider.prototype.render = function (name, data) {
if (!this._templates.hasOwnProperty(name)) {
return Promise.reject(new Error('No such template'));
}

var promise;
try {
promise = Promise.resolve(this._templates[name](data));
} catch(e) {
promise = Promise.reject(e);
}
return promise;
};
Loading

0 comments on commit d0f55db

Please sign in to comment.