mirror of
https://github.com/coderaiser/cloudcmd.git
synced 2026-07-21 02:29:23 +00:00
feature(bower) Util.render -> rendy
This commit is contained in:
parent
cb219ae64e
commit
da2768d56b
17 changed files with 315 additions and 57 deletions
35
modules/rendy/.bower.json
Normal file
35
modules/rendy/.bower.json
Normal file
|
|
@ -0,0 +1,35 @@
|
|||
{
|
||||
"name": "rendy",
|
||||
"version": "1.1.0",
|
||||
"homepage": "https://github.com/coderaiser/rendy",
|
||||
"authors": [
|
||||
"coderaiser <mnemonic.enemy@gmail.com>"
|
||||
],
|
||||
"description": "simple template engine",
|
||||
"main": "lib/rendy.js",
|
||||
"moduleType": [
|
||||
"globals",
|
||||
"node"
|
||||
],
|
||||
"keywords": [
|
||||
"template",
|
||||
"engine",
|
||||
"rendy"
|
||||
],
|
||||
"license": "MIT",
|
||||
"ignore": [
|
||||
"**/.*",
|
||||
"node_modules",
|
||||
"test"
|
||||
],
|
||||
"_release": "1.1.0",
|
||||
"_resolution": {
|
||||
"type": "version",
|
||||
"tag": "v1.1.0",
|
||||
"commit": "4ad810d131db34863df83977afea92b6fb2f1127"
|
||||
},
|
||||
"_source": "git://github.com/coderaiser/rendy.git",
|
||||
"_target": "~1.1.0",
|
||||
"_originalSource": "rendy",
|
||||
"_direct": true
|
||||
}
|
||||
59
modules/rendy/ChangeLog
Normal file
59
modules/rendy/ChangeLog
Normal file
|
|
@ -0,0 +1,59 @@
|
|||
2015.05.21, v1.1.0
|
||||
|
||||
feature:
|
||||
- (rendy) 5 times spead up
|
||||
- (package) should v6.0.1
|
||||
- (travis) add iojs, rm global gulp
|
||||
- (package) scripts: test
|
||||
- (test) greedy
|
||||
- (package) should v5.2
|
||||
- (package) scripts: gulp
|
||||
|
||||
|
||||
2015.03.13, v1.0.6
|
||||
|
||||
fix:
|
||||
- (rendy) clean up regexp: lazy -> greedy
|
||||
|
||||
|
||||
2015.03.13, v1.0.5
|
||||
|
||||
feature:
|
||||
- (rendy) put vars in forEach
|
||||
- (package) should v5.0.0
|
||||
- (bower) add
|
||||
|
||||
|
||||
2015.01.26, v1.0.4
|
||||
|
||||
feature:
|
||||
- (rendy) improve speed
|
||||
|
||||
|
||||
2015.01.26, v1.0.3
|
||||
|
||||
feature:
|
||||
- (rendy) speed up in 10 times: rm greedy quantifier
|
||||
- (package) should v4.6
|
||||
- (package) should v4.4.1
|
||||
|
||||
|
||||
2014.12.12, v1.0.2
|
||||
|
||||
fix:
|
||||
- (util) render: do not remove empty blocks "{{", "}}"
|
||||
- (rendy) indexOf -> ~indexOf
|
||||
|
||||
feature:
|
||||
- (package) v1.0.1
|
||||
- (rendy) add expr
|
||||
|
||||
|
||||
2014.12.12, v1.0.1
|
||||
|
||||
fix:
|
||||
- (rendy) indexOf -> ~indexOf
|
||||
|
||||
feature:
|
||||
- (rendy) add expr
|
||||
|
||||
21
modules/rendy/LICENSE
Normal file
21
modules/rendy/LICENSE
Normal file
|
|
@ -0,0 +1,21 @@
|
|||
The MIT License (MIT)
|
||||
|
||||
Copyright (c) 2014-2015 coderaiser
|
||||
|
||||
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.
|
||||
52
modules/rendy/README.md
Normal file
52
modules/rendy/README.md
Normal file
|
|
@ -0,0 +1,52 @@
|
|||
# Rendy [![License][LicenseIMGURL]][LicenseURL] [![NPM version][NPMIMGURL]][NPMURL] [![Dependency Status][DependencyStatusIMGURL]][DependencyStatusURL] [![Build Status][BuildStatusIMGURL]][BuildStatusURL]
|
||||
Simple template engine compatible with [handlebars](http://handlebarsjs.com "Handlebars") and [mustache](https://mustache.github.io "Mustache").
|
||||
|
||||
## Install
|
||||
![NPM_INFO][NPM_INFO_IMG]
|
||||
|
||||
`npm i rendy --save`
|
||||
|
||||
## How to use?
|
||||
Rendy could be used in browser or node.
|
||||
|
||||
Browser version:
|
||||
|
||||
```html
|
||||
<script src="rendy.js"></script>
|
||||
<script>
|
||||
var Tmpl = 'hello {{ where }}';
|
||||
result = rendy(Tmpl, {
|
||||
where: 'in browser'
|
||||
});
|
||||
// returns
|
||||
'hello in browser'
|
||||
</script>
|
||||
```
|
||||
|
||||
Node version:
|
||||
|
||||
```js
|
||||
var rendy = require('rendy'),
|
||||
Tmpl = 'hello {{ who }}';
|
||||
result = rendy(Tmpl, {
|
||||
who: 'world'
|
||||
});
|
||||
// returns
|
||||
'hello world'
|
||||
|
||||
```
|
||||
|
||||
## License
|
||||
|
||||
MIT
|
||||
|
||||
[NPM_INFO_IMG]: https://nodei.co/npm/rendy.png?downloads&&stars&&downloadRank "npm install rendy"
|
||||
[NPMIMGURL]: https://img.shields.io/npm/v/rendy.svg?style=flat
|
||||
[BuildStatusIMGURL]: https://img.shields.io/travis/coderaiser/rendy/master.svg?style=flat
|
||||
[DependencyStatusIMGURL]: https://img.shields.io/gemnasium/coderaiser/rendy.svg?style=flat
|
||||
[LicenseIMGURL]: https://img.shields.io/badge/license-MIT-317BF9.svg?style=flat
|
||||
[NPMURL]: https://npmjs.org/package/rendy "npm"
|
||||
[BuildStatusURL]: https://travis-ci.org/coderaiser/rendy "Build Status"
|
||||
[DependencyStatusURL]: https://gemnasium.com/coderaiser/rendy "Dependency Status"
|
||||
[LicenseURL]: https://tldrlegal.com/license/mit-license "MIT License"
|
||||
|
||||
25
modules/rendy/bower.json
Normal file
25
modules/rendy/bower.json
Normal file
|
|
@ -0,0 +1,25 @@
|
|||
{
|
||||
"name": "rendy",
|
||||
"version": "1.1.0",
|
||||
"homepage": "https://github.com/coderaiser/rendy",
|
||||
"authors": [
|
||||
"coderaiser <mnemonic.enemy@gmail.com>"
|
||||
],
|
||||
"description": "simple template engine",
|
||||
"main": "lib/rendy.js",
|
||||
"moduleType": [
|
||||
"globals",
|
||||
"node"
|
||||
],
|
||||
"keywords": [
|
||||
"template",
|
||||
"engine",
|
||||
"rendy"
|
||||
],
|
||||
"license": "MIT",
|
||||
"ignore": [
|
||||
"**/.*",
|
||||
"node_modules",
|
||||
"test"
|
||||
]
|
||||
}
|
||||
18
modules/rendy/gulpfile.js
Normal file
18
modules/rendy/gulpfile.js
Normal file
|
|
@ -0,0 +1,18 @@
|
|||
(function() {
|
||||
'use strict';
|
||||
|
||||
var gulp = require('gulp'),
|
||||
mocha = require('gulp-mocha');
|
||||
|
||||
gulp.task('test', function() {
|
||||
gulp.src('test/test.js')
|
||||
.pipe(mocha({reporter: 'min'}))
|
||||
.on('error', onError);
|
||||
});
|
||||
|
||||
gulp.task('default', ['test']);
|
||||
|
||||
function onError(error) {
|
||||
console.log(error.message);
|
||||
}
|
||||
})();
|
||||
43
modules/rendy/lib/rendy.js
Normal file
43
modules/rendy/lib/rendy.js
Normal file
|
|
@ -0,0 +1,43 @@
|
|||
(function(global) {
|
||||
'use strict';
|
||||
|
||||
if (typeof module === 'object' && module.exports)
|
||||
module.exports = rendy;
|
||||
else
|
||||
global.rendy = rendy;
|
||||
|
||||
/**
|
||||
* render template with data
|
||||
*
|
||||
* @param templ
|
||||
* @param data
|
||||
*/
|
||||
function rendy(templ, data) {
|
||||
var result = templ;
|
||||
|
||||
check(templ, data);
|
||||
|
||||
Object
|
||||
.keys(data)
|
||||
.forEach(function(param) {
|
||||
var name = '{{ ' + param + ' }}',
|
||||
str = data[param];
|
||||
|
||||
while(~result.indexOf(name))
|
||||
result = result.replace(name, str);
|
||||
});
|
||||
|
||||
if (~result.indexOf('{{'))
|
||||
result = result.replace(/{{.*?}}/g, '');
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
function check(templ, data) {
|
||||
if (typeof templ !== 'string')
|
||||
throw(Error('template should be string!'));
|
||||
|
||||
if (typeof data !== 'object')
|
||||
throw(Error('data should be object!'));
|
||||
}
|
||||
})(this);
|
||||
28
modules/rendy/package.json
Normal file
28
modules/rendy/package.json
Normal file
|
|
@ -0,0 +1,28 @@
|
|||
{
|
||||
"name": "rendy",
|
||||
"version": "1.1.0",
|
||||
"description": "simplest template engine",
|
||||
"main": "lib/rendy.js",
|
||||
"scripts": {
|
||||
"test": "gulp test"
|
||||
},
|
||||
"repository": {
|
||||
"type": "git",
|
||||
"url": "git://github.com/coderaiser/rendy.git"
|
||||
},
|
||||
"keywords": [
|
||||
"template",
|
||||
"engine"
|
||||
],
|
||||
"author": "coderaiser <mnemonic.enemy@gmail.com> (http://coderaiser.github.io/)",
|
||||
"license": "MIT",
|
||||
"bugs": {
|
||||
"url": "https://github.com/coderaiser/rendy/issues"
|
||||
},
|
||||
"homepage": "https://github.com/coderaiser/rendy",
|
||||
"devDependencies": {
|
||||
"gulp": "~3.8.10",
|
||||
"gulp-mocha": "~2.0.0",
|
||||
"should": "~6.0.1"
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue