coolony / kiwi Goto Github PK
View Code? Open in Web Editor NEWSimple yet powerful asynchronous JavaScript template engine based on jQuery Template syntax, usable server-side or client-side.
License: MIT License
Simple yet powerful asynchronous JavaScript template engine based on jQuery Template syntax, usable server-side or client-side.
License: MIT License
Hi, I receive the following error when a variable in the template is undefined: ReferenceError: X is not defined
. I know this is expected functionality, however it would nice to be able to test for this within the template so it doesn't throw the error. Is this doable currently or can it be added in the future?
Ability to set a locals vars for inner template file.
For example:
{{each rows}}
{{include item=$value type="top"}}
{{/each}}
Inspired by Smarty engine for php.
{{if x}}
{{include 'item'}}
{{/if}}
And I get the following
SyntaxError: Unexpected identifier
at Object.Function (<anonymous>)
at onCompiled (/Users/ckknight/Development/project/node_modules/kiwi/lib/compiler.js:73:14)
at onCompiled (/Users/ckknight/Development/project/node_modules/kiwi/lib/token.js:182:5)
at /Users/ckknight/Development/project/node_modules/kiwi/lib/utils.js:240:5
at done (/Users/ckknight/Development/project/node_modules/kiwi/lib/utils.js:219:5)
...
It also fails with an else
clause.
Hi,
I am trying to create a custom filter to format JSON. I have tried to create the filter two ways and both fail with the same error. I tried the method shown in the docs:
This is just a test function and really does nothing.
Kiwi.tools.createFilter('json_format', function(str){
console.log(str);
return str.toUpperCase();
});
I also tried adding a new function to /libs/filters/base.js
exports.json_filter = function(str) {
console.log(str);
return str.toUpperCase();
};
I then use it in the template like this:
<div class="test interactive" title="Click to run the Alias">${test.test|json_filter}</div>
The error output is the same in both cases.
/home/swright/code/noschema_cp/node_modules/kiwi/lib/tags/print.js:163
filter[1] = filter[1].replace('"', '\"');
^
TypeError: Cannot read property '1' of null
at mapOne (/home/swright/code/noschema_cp/node_modules/kiwi/lib/tags/print.js:163:40)
at Array.map (native)
at parseFilters (/home/swright/code/noschema_cp/node_modules/kiwi/lib/tags/print.js:161:21)
at Object.compile (/home/swright/code/noschema_cp/node_modules/kiwi/lib/tags/print.js:104:31)
at LeafToken.compile (/home/swright/code/noschema_cp/node_modules/kiwi/lib/token.js:297:31)
at Timer.compileOne (/home/swright/code/noschema_cp/node_modules/kiwi/lib/utils.js:205:11)
at Timer.processOne [as _callback] (/home/swright/code/noschema_cp/node_modules/kiwi/node_modules/frame/lib/async_foreach.js:43:8)
at Timer.<anonymous> (timers.js:172:14)
Hi, I tried this:
var kiwi = require('kiwi');
kiwi.Template('Hello ${name}', { cache : false }).render({ name : 'panosru'}, function (err, output) {
console.log(output);
});
and I got this:
/home/admin/domains/med-app.av/public_html/kiwi/kiwi.js:3
kiwi.Template('Hello ${name}', { cache : false }).render({ name : 'panosru'},
^
TypeError: Cannot call method 'render' of undefined
at Object.<anonymous> (/home/admin/domains/med-app.av/public_html/kiwi/kiwi.js:3:51)
at Module._compile (module.js:446:26)
at Object..js (module.js:464:10)
at Module.load (module.js:353:31)
at Function._load (module.js:311:12)
at Array.0 (module.js:484:10)
at EventEmitter._tickCallback (node.js:190:38)
if I remove the { cache : false }
I also get this:
/home/admin/domains/med-app.av/public_html/kiwi/node_modules/kiwi/lib/template.js:95
if(options.cache && !(this._getCache() instanceof options.cacheHandler)) {
^
TypeError: Object #<Object> has no method '_getCache'
at Object.Template (/home/admin/domains/med-app.av/public_html/kiwi/node_modules/kiwi/lib/template.js:95:30)
at Object.<anonymous> (/home/admin/domains/med-app.av/public_html/kiwi/kiwi.js:3:6)
at Module._compile (module.js:446:26)
at Object..js (module.js:464:10)
at Module.load (module.js:353:31)
at Function._load (module.js:311:12)
at Array.0 (module.js:484:10)
at EventEmitter._tickCallback (node.js:190:38)
for example:
// foo.kiwi
{{block greeting}}Hello{{/block}}
// Template
{{extend "foo"}}
{{block greeting}}Hi, {{parent}} World{{/block}}
// Code
new Template(tpl).render({}, callback);
// Result
Hi, Hello World
From the docs raw
filter is mentioned but when I try to use it I get Error: Rendering error: Unknown filter raw.
from what I see in the source of Kiwi under lib/filters/base.js
raw
filter is not present.
Hi, prepend
and append
work in opposite direction from which they supposed to work.
For instance:
main.kiwi
{{block foobar}}foo{{/block}}
child1.kiwi
{{block foobar append}} bar{{/block}}
child2.kiwi
{{block foobar prepend}}bar {{/block}}
child1.kiwi supposed to return foo bar
but it returns barfoo
similar issue happens with child2.kiwi
Hello, first of all I want to agree you for your Kiwi template engine, it's very good and satisfies most of all needs that I have. This is a great job!
I want to comment you one issue that I'm having with the template engine. In one development I have to to include one javascript file or render it inline according to a variable... and I think that template system crashes.
This is the example code where I've got this issue:
{{if params.presentation._render_inline}}
<script type="text/javascript">{{include "_mini_framework"}}</script>
{{else}}
<script type="text/javascript" src="http://xxxxxx/js/mini_framework.js"></script>
{{/if}}
mini_framework.js is a symlink of _mini_framework(.kiwi).
And when I try to execute this code I've got an syntax error at compiler.js file (the trace is SyntaxError: Unexpected token else, at Object.Function (unknown source), at onCompiled (/yyyyyyy/node_modules/kiwi/lib/compiler.js:70:16), )
Is it an issue, the system doesn't have this feature or I'm missing something (it's the most probable)?
Regards,
L.
Hi,
I am having a problem with the each loops.
If I remove the inner loop then the conditional that evaluates _eachLoop.last works correctly in that it identifies the final iteration.
If I put it back in then the conditional seems to identify each of the inner loops iterations as the final iteration.
My goal is to iterate the following structure outputting headings and a list of values for each heading.
data : {
"heading1" : [ 'item1', 'item2', 'item3' ],
"heading2" : [ 'item1', 'item2', 'item3' ],
}
Where am I going wrong?
<div class="row show-grid">
{{each data}}
{{as namespace}}${$index}{{/as}}
{{if _eachLoop.first }}
<div class="span3">
{{/if}}
<h3>${$index}</h3>
{{each $value}}
<div><a href="/alias_tests/alias/${namespace}${$value}">${$value}</a></div>
{{/each}}
{{if _eachLoop.last }}
</div>
{{/if}}
{{/each}}
</div>
Thanks for the help.
Hi, I use Kiwi as my primary server side templating engine and I also use Handlebars with EmberJS for client-side so I tried today to do something like this: ${'{{action anActionName}}'|raw}
but I got SyntaxError: Unexpected token }
this works: {{raw}}{{action anActionName}}{{/raw}}
but I think that the first should also work since I pass the raw filter.
Thanks :)
Hi I added the following work around, as I was unable to load templates from full paths when debugging on a windows box.
Quick and dirty but worked for me.
if(name[0] === '/' || name[1]=== ':')
utils.js line 71
thanks for kiwi.
Hello there!
Awesome idea, but what about async functions inside the template? It would be wonderfully off we could call some tag that extract info from the db and add to the view, for example :)
oops, there was an error: TypeError: Property 'engine' of object # is not a function
What am I doing wrong? Thanks!!!!
(coffeescript syntax):
express = require('express')
kiwi = require('kiwi')
app = express()
app.set('views', __dirname + '/html')
app.engine('kiwi', kiwi.__express)
app.set('view engine', 'kiwi')
app.get('/', (request, response) ->
response.send('hello world by express')
)
app.get('/console', (request, response) ->
response.render('console.html', {}, (err, rendered) ->
if err
response.send('oops, there was an error: ' + err)
else
response.send('rendered: ' + rendered)
)
)
app.listen(4000)
```javascript
Hi,
Engine looks great so far. In your examples you have this which actually fails because 'name' is undefined:
{{if name}} Hello, ${name|capitalize}! {{else}} Hello, dear unknown! {{/if}}
Should be something like this:
<title>${title}</title>{{if typeof(name) != 'undefined'}} Hello, ${name|capitalize}! {{else}} Hello, dear unknown! {{/if}}
I miss the ability to set a variable as is. for example:
{{set $oldValue null}}
{{each entities}}
{if $oldValue && $oldValue.someTerm == true}} Do Something {{/if}}
{{set $oldValue $value}}
{{/each}}
I cant for the life of me figure how to (or even if its possible) include a template from a child folder
File structure is like:
/views/index.kiwi
/views/partials/header.kiwi
and then I'm trying:
// index.kiwi
{{include "partials/header"}}
Reproducible code:
kiwi.js:
var kiwi = require('kiwi');
var template = new kiwi.Template('{{extend "template"}} {{block welcome append}} ${name}{{/block}}', { cache : false, path : __dirname + '/template.kiwi' });
template.render({name : 'panosru'}, function (err, output) {
if (err) { console.log(err); return; }
console.log(output.trim());
});
template.kiwi:
{{block welcome}}
Hello
{{/block}}
Output:
root@dev:/home/admin/example/kiwi# node kiwi.js
[Error: Compilation error: Unable to parse tag `block welcome append`.]
I like to build a custom tag with an opening and closing tag but can not find a option to set this.
Just got the error: "Tokenization error: test
is not a block tag."
kiwi.tools.createSimpleTag('test', function(context, name) {
return name;
});
{{test "123"}}Content{{/test}}
If there is already an option to do that, please update the readme. Else it would be a great feature!
If you try to use the code specified in the Usage > Loading a template from disk section, it fails with a Cannot call method 'render' of undefined
message on node 0.8.18.
It seems that trying to run a method on a variable being defined in this case fails, and the template
must be instantiated by kiwi beforehand, as such:
// proposed fix
var template = new kiwi.Template();
template.loadFile('template.kiwi', function onLoaded(err) {
template.render({ name: "Kiwi" }, function onRendered(err, rendered) {
console.log('Rendered template is: ' + rendered);
});
});
Hi,
I was wondering if it is possible to feed an array of objects to {{each}} tag. and then read the properties of the objects
for example
var item1 = {title : "Hi", content : "Hola" };
var item2 = {title : "Hello", content : "Buenos" };
response.render("index", posts = [item1, item2]);
in kiwi
{{each posts}}
<p>title is ${value.title} and content is ${value.content}</p>
{{/each}}
I love the kiwi syntax but in order to make it really useful I need layouts, blocks, etc, similar to how RandomETC/ejs-locals works. Any plans for that?
Hi, would it be possible to support macros ?
When not passing a variable to the render function, say
response.render("index", {});
and when using {{if foo}} in the template
the template fails to render. I think in such cases foo should just default to false.
Hello,
trying to get Kiwi and Express setup. I followed the "out of the box" setup as shown but I am getting an error. I am hoping you can help me out.
Here is my main file:
/*
Server.listen(Config.server.port); // Start the party
Here is the content of my views directory:
[swright@swright-dev control_panel]$ ll views/
total 4
-rwxr--r-- 1 swright swright 16 Jul 30 12:53 index
[swright@swright-dev control_panel]$
Here is the error output:
Error: Failed to lookup view "index"
at Function.render (/home/swright/code/noschema/control_panel/node_modules/express/lib/application.js:493:17)
at ServerResponse.render (/home/swright/code/noschema/control_panel/node_modules/express/lib/response.js:676:7)
at /home/swright/code/noschema/control_panel/app.js:24:9
at callbacks (/home/swright/code/noschema/control_panel/node_modules/express/lib/router/index.js:165:11)
at param (/home/swright/code/noschema/control_panel/node_modules/express/lib/router/index.js:139:11)
at pass (/home/swright/code/noschema/control_panel/node_modules/express/lib/router/index.js:146:5)
at Router._dispatch (/home/swright/code/noschema/control_panel/node_modules/express/lib/router/index.js:173:4)
at Object.router as handle
at next (/home/swright/code/noschema/control_panel/node_modules/express/node_modules/connect/lib/proto.js:190:15)
at Object.expressInit [as handle] (/home/swright/code/noschema/control_panel/node_modules/express/lib/middleware.js:31
Hi,
I am having a really difficult time outputting a complex list of data. I was wondering if you would mind pointing me in the right direction. I have an object of objects that contain an array of objects. I cant seem to figure out the right combination of kiwi eachs to use to create an HTML UL from this. I figured I would try the raw tag and just do it in Javascript but the script tag make Kiwi throw an error.
Here is a sample of my data structure:
"monitoring": [
{
"Monitoring Most Recent Feed": [
{
"resultCode": "NO TESTS FOUND"
}
]
}
],
"cloud_sandbox": [
{
"Cloud Sandbox File": [
{
"test": "noname",
"resultCode": 200
},
{
"test": "noname",
"resultCode": 200
}
]
}
],
Here is what I want the output to be:
<ul>
<li>monitoring</li>
<ul>
<li>Monitoring Most Recent Feed</li>
<ul>
<li>resultCode: NO TESTS FOUND</li>
</ul>
</ul>
<li>cloud_sandbox</li>
<ul>
<li>Cloud Sandbox File</li>
<ul>
<li>test: noname</li>
<li>resultCode: 200</li>
</ul>
<ul>
<li>test: namename</li>
<li>resultCode: 200</li>
</ul>
</ul>
</ul>
Any advice you may have to help achieve this would be greatly appreciated.
Thanks
Steve
Hey guys, thanks for your amazing work with kiwi. It's really awesome!
I would like to ask, if possible, to give more flexibility in the tags, for example, allow spacing between {{ and the tag name... that would make the code cleaner.
For example:
{{include "template"}} // works
{{ include "template" }} // doesn't work
Thanks again!
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.