feature(bower) Util.render -> rendy

This commit is contained in:
coderaiser 2015-05-21 09:33:25 -04:00
parent cb219ae64e
commit da2768d56b
17 changed files with 315 additions and 57 deletions

View file

@ -25,6 +25,7 @@
"jquery": "~2.1.4",
"menu": "~0.7.8",
"promise-polyfill": "~2.0.0",
"format-io": "~0.9.6"
"format-io": "~0.9.6",
"rendy": "~1.1.0"
}
}

View file

@ -27,18 +27,21 @@ var CloudCmd;
client + 'key'
].map(function(name) {
return lib + name;
}),
moduleFiles = [
'promise-polyfill/Promise',
'format-io/lib/format',
'rendy/lib/rendy',
].map(function(name) {
return modules + name;
});
files.concat([
'promise-polyfill/Promise',
'format-io/lib/format'
].map(function(name) {
return modules + name;
}));
files = files.map(function(name) {
return name + '.js';
});
files = moduleFiles
.concat(files)
.map(function(name) {
return name + '.js';
});
urlFiles = getJoinURL(files);

View file

@ -3,6 +3,8 @@ var CloudCmd, Util, DOM, io;
(function(CloudCmd, Util, DOM) {
'use strict';
/* global rendy */
CloudCmd.Config = ConfigProto;
function ConfigProto() {
@ -126,7 +128,7 @@ var CloudCmd, Util, DOM, io;
obj[obj.editor + '-selected'] = 'selected';
delete obj.editor;
data = Util.render(Template, obj);
data = rendy(Template, obj);
div = DOM.load({
name : 'div',
className : 'config',

View file

@ -3,6 +3,8 @@ var CloudCmd, Util, DOM, CloudFunc, Dialog;
(function(Util, window) {
'use strict';
/* global rendy */
var DOMFunc = function() {},
DOMProto,
@ -387,7 +389,7 @@ var CloudCmd, Util, DOM, CloudFunc, Dialog;
});
remote = remoteTmpls.map(function(tmpl) {
return Util.render(tmpl, {
return rendy(tmpl, {
version: version
});
});
@ -1581,6 +1583,7 @@ var CloudCmd, Util, DOM, CloudFunc, Dialog;
shouldAsk,
sameName,
ok,
tmpl = '"{{ name }}" already exist. Overwrite?',
RESTful = DOM.RESTful,
from = '',
@ -1627,7 +1630,7 @@ var CloudCmd, Util, DOM, CloudFunc, Dialog;
ok = from !== to && to;
if (ok && shouldAsk && sameName)
ok = Dialog.confirm(Util.render('"{{ name }}" already exist. Overwrite?', {
ok = Dialog.confirm(rendy(tmpl, {
name: name
}));

View file

@ -3,6 +3,8 @@ var Util, DOM;
(function (Util, DOM) {
'use strict';
/* global rendy */
var DOMProto = Object.getPrototypeOf(DOM);
DOMProto.load = new LoaderProto(Util, DOM.Images, DOM.Events);
@ -51,7 +53,7 @@ var Util, DOM;
var callback,
template = 'file {{ src }} could not be loaded',
isQuit = true,
msg = Util.render(template, {
msg = rendy(template, {
src: p.src
}),

View file

@ -3,8 +3,10 @@ var CloudCmd, Util, DOM, CloudFunc, $;
(function(CloudCmd, Util, DOM, CloudFunc) {
'use strict';
/* global rendy */
CloudCmd.View = ViewProto;
function ViewProto(CallBack) {
var Name = 'View',
Loading = false,
@ -239,7 +241,7 @@ var CloudCmd, Util, DOM, CloudFunc, $;
is = isAudio(name);
type = is ? 'audio' : 'video';
rendered = Util.render(TemplateAudio, {
rendered = rendy(TemplateAudio, {
src : src,
type: type,
name: Info.name

View file

@ -7,10 +7,9 @@ var Util;
if (typeof module === 'object' && module.exports) {
rendy = require('rendy');
module.exports = new CloudFuncProto(Util);
} else {
rendy = Util.render;
rendy = window.rendy;
scope.CloudFunc = new CloudFuncProto(Util);
}

View file

@ -3,6 +3,8 @@
var Scope = scope.window ? window : global;
/* global rendy */
if (typeof module === 'object' && module.exports)
module.exports = new UtilProto();
else if (!Scope.Util)
@ -40,7 +42,7 @@
else
name = names[emptyIndex];
msg = Util.render(template, {
msg = rendy(template, {
name: name
});
@ -202,31 +204,6 @@
return regExp;
};
/**
* function render template with view and own symbols
*
* @param templ
* @param data
*/
this.render = function(templ, data) {
var result = templ;
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;
};
this.type = new TypeProto();
function TypeProto() {

35
modules/rendy/.bower.json Normal file
View 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
View 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
View 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
View 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
View 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
View 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);
}
})();

View 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);

View 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"
}
}

View file

@ -81,18 +81,6 @@
});
});
describe('render', function() {
it('should render template with object of params', function() {
var WORD = 'hello world',
word = Util.render('hello {{ name }}', {
name: 'world'
});
WORD.should.equal(word);
});
});
});
})();