GithubHelp home page GithubHelp logo

ravelsoft / node-jinjs Goto Github PK

View Code? Open in Web Editor NEW
86.0 5.0 6.0 589 KB

The Jinja templating language ported to Javascript, usable with NodeJS and compatible with browserify.

License: MIT License

Shell 3.47% JavaScript 96.53%

node-jinjs's Introduction

JinJS

As stated on Jinja's home page, "Jinja Is Beautiful"

{% extends "layout.html" %}
{% block body %}
  <ul>
  {% for user in users %}
    <li><a href="{{ user.url }}">{{ user.username }}</a></li>
  {% endfor %}
  </ul>
{% endblock %}

JinJS is the native port of Jinja to the world of NodeJS. Just like Jinja, it aims to transform template documents to native javascript code to maximize execution speed.

Head over to the Documentation

node-jinjs's People

Contributors

corbinbs avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar

node-jinjs's Issues

proper way to do {% extends 'some.template' %}

I can't seem to get your extends syntax to work.

require("jinjs").registerExtension(".template");
var base_template = require("./base");

var the_template = require("./test");

var result = the_template.render({});

test.template:

{% extends "base.template" %}

{% block body %}
  Testing 123
{% endblock %}

base.template:

<head>
<title>Hello there!</title>
</head>
<body>
{% block body %}
{% endblock %}
</body>
</head>

This gives me:

Error: Cannot find module 'base.template'

just js would be nice

I really want to provide a solid django-inspired template engine for the Express users, and this certainly looks like a good start. however that weird language you're using is going to be a big barrier for contribution. I definitely recommend just writing js in js so people like myself who actually know the language can help tune/fix things

Implement the test with "is"

Jinja has a lovely testing facility : {% toto is divisibleby 3 %}. see : http://jinja.pocoo.org/docs/templates/#list-of-builtin-tests

Also ; pass this as the context

Implement the following :

  • callable (function)
  • defined
  • divisibleby
  • escaped
  • even
  • --iterable-- can't implement this in JS ; everything is iterable (except maybe numbers and dates)
  • lower
  • null (none)
  • number
  • odd
  • sameas
  • array
  • string
  • undefined
  • upper

And the operators is and is not in the expression grammar.

Template inclusion and browserify

The fact that __get_template__ is used to get the templates confuses browserify, which requires explicit calls to require.

This should change to not have to manually load the template base elsewhere.

npm istall jinjs 0.3.6 bug

Hi

require("jinjs")
Error: Cannot find module 'jinjs'
at Function._resolveFilename (module.js:334:11)
at Function._load (module.js:279:25)
at Module.require (module.js:357:17)
at require (module.js:373:17)
at repl:1:2
at REPLServer.eval (repl.js:80:21)
at Interface. (repl.js:182:12)
at Interface.emit (events.js:67:17)
at Interface._onLine (readline.js:162:10)
at Interface._line (readline.js:426:8)

$ node -v
v0.6.9
$ npm -v
1.1.0-2

P.S. jinjs v 0.3.5 works fine

Filters broken?

I'm trying to use filters in an Exprss.js-application, but it isn't working for me, and I can't quite figure out what's wrong.

Given this template :

{{ foo }}
{{ foo | capitalize }}
{{ foo | $capitalize }}
{{ foo | Capitalize }}
{{ foo | nosuchfilter }}

With {foo: "bar this"}, I get the following output:

bar this
0
0
0
0

(From using Jinja, I would expect at least one of the above to be foo this.)

I'm running Node.js v0.6.19 and the relevant parts of npm ls are as follow:

├─┬ [email protected]
│ ├─┬ [email protected]
│ │ └── [email protected]
│ ├── [email protected]
│ ├── [email protected]
│ └── [email protected]
├─┬ [email protected]
│ └─┬ [email protected]
│ └── [email protected]

The server I'm using looks like this:

var express = require('express'),
    app = express.createServer();

app.set("view options", { layout: false });

app.get('/*', function (req, res) {
    res.render('test.jinjs', {foo: "bar this"});
});

app.listen(3000);

As I can't generally see other people complain about this fairly obvious bug, my working assumption is that I've missed something important. Any pointers?

use jinjs with express, errors occured

500 TypeError: object is not a function
at ExpressEnvironment.CALL_NON_FUNCTION (native)
at ExpressEnvironment.getTemplateFromString (/usr/local/lib/node_modules/jinjs/lib/express.js:34:82)
at Object.compile (/usr/local/lib/node_modules/jinjs/lib/express.js:64:45)
at Function.compile (/usr/local/lib/node_modules/locomotive/node_modules/express/lib/view.js:68:33)
at ServerResponse._render (/usr/local/lib/node_modules/locomotive/node_modules/express/lib/view.js:417:18)
at ServerResponse.render (/usr/local/lib/node_modules/locomotive/node_modules/express/lib/view.js:318:17)

who can explain that?

Jinjs: 0.3.5
Express: 2.5.6
Node: 0.6.7
OS: Debian

"news" in for-loop variable name gives TypeError

Following situation:

test.tpl

{% for i in news %}
{{ i.title }}
{% endfor %}

test.js

require("jinjs").registerExtension(".tpl");
var main_template = require("./test");
var context = { news : [{title: "test one"}, {title: "test two"}]};
console.log(main_template.render(context));

Then, node test.js gives me the following error:

var _fref = new $$.s || [], _prev_loop = $$.loop, _prev_key = $$['i'], _prev_value = null, k = null, v = null, i = 0, l = 0, x = null, last_v = null, last_k = null;
            ^

TypeError: $$.s is not a constructor

Changing to foo and the error goes away

If I replace news with foo or bnews, then the error doesn't occur anymore.

However, the error still occurs for words like newsarticles.

fs: TypeError: Bad arguments

TypeError: Bad arguments
at fs.js:521:10
at ExpressEnvironment. (/home/razor/Documents/dev/dinetou/website/node_modules/jinjs/lib/environment.js:106:14)
at ExpressEnvironment.trackFile (/home/razor/Documents/dev/dinetou/website/node_modules/jinjs/lib/express.js:23:64)
at ExpressEnvironment. (/home/razor/Documents/dev/dinetou/website/node_modules/jinjs/lib/environment.js:140:10)
at ExpressEnvironment.getTemplateFromString (/home/razor/Documents/dev/dinetou/website/node_modules/jinjs/lib/express.js:31:73)
at Object.compile (/home/razor/Documents/dev/dinetou/website/node_modules/jinjs/lib/express.js:59:43)
at Function.compile (/home/razor/Documents/dev/dinetou/website/node_modules/express/lib/view.js:64:33)
at ServerResponse._render (/home/razor/Documents/dev/dinetou/website/node_modules/express/lib/view.js:415:18)
at ServerResponse.render (/home/razor/Documents/dev/dinetou/website/node_modules/express/lib/view.js:316:17)
at Router. (/home/razor/Documents/dev/website/views/root.js:31:7)

Node v0.4.11
express v2.4.2

this error pops up 3-4 times, and after some refreshes, it magically shows the template perfectly.
Any idea what might be going wrong?

combined for with else statements throws ReferenceError

<ul>
{% for user in users %}
    <li>{{ user.username|e }}</li>
{% else %}
    <li><em>no users found</em></li>
{% endfor %}
</ul>

sample taken from http://jinja.pocoo.org/docs/templates/

throws

500 ReferenceError: loop is not defined
at eval at (/home/razor/Documents/dev/dinetou/website/node_modules/jinjs/lib/environment.js:152:7)
at __for (/home/razor/Documents/dev/dinetou/website/node_modules/jinjs/lib/utils.js:52:5)
at Object.render (eval at (/home/razor/Documents/dev/dinetou/website/node_modules/jinjs/lib/environment.js:152:7))
at ServerResponse._render (/home/razor/Documents/dev/dinetou/website/node_modules/express/lib/view.js:424:21)
at ServerResponse.render (/home/razor/Documents/dev/dinetou/website/node_modules/express/lib/view.js:316:17)
at Promise. (/home/razor/Documents/dev/dinetou/website/views/root.js:51:9)
at Promise. (/home/razor/Documents/dev/dinetou/website/node_modules/mongoose/lib/mongoose/promise.js:120:8)
at Promise. (events.js:64:17)
at Promise.emit (/home/razor/Documents/dev/dinetou/website/node_modules/mongoose/lib/mongoose/promise.js:59:38)
at Promise.complete (/home/razor/Documents/dev/dinetou/website/node_modules/mongoose/lib/mongoose/promise.js:70:20)

call() fails with imported macros.

If a macro is defined in a separate, imported file, attempting to use it via call() will result in the following:

ReferenceError: <macro_name> is not defined

implement raw

Hi, as I see {% raw %} is not implemented, I tried to use angular js which uses {{ }} as well so I realized that raw is not there :/

Any workaround for that?

ability to add filters

Hello!

Is it possible to add filters to the environment/context?
Or if it is possible, would you document it please?

With express you get - Maximum call stack size exceeded when running

Steps to reproduce

  1. cd test/express
  2. coco app.co

Expected results

All tests honored

Actual results

4 honored and 2 broken.

The jinja templates in Express can use its own include facility
test
"Hello World." == "RangeError: Maximum call stack size exceeded"

The jinja templates in Express can use its own include facility
test
"Hello World." == "RangeError: Maximum call stack size exceeded"

Environment

  • Ubuntu 11.04
  • node v0.6.0
  • jinjs 0.3.3

let instead of set? typo?

Just wondering, you have let tag instead of set tag, is it a typo?

For instance this:

{% set foo = 'something' %}
foo is {{ foo }}

throws Error: Unexpected tag : 'set'

this works fine:

{% let foo = 'something' %}
foo is {{ foo }}

npm install is broken.

I tested git version vs npm install.

The two issues i noticed when using npm install

Cannot require without modifying package.json. I have posted this bug in another ticket.

TypeError: object is not a function
    at ExpressEnvironment.CALL_NON_FUNCTION (native)

This happens while requesting a simple page.

If i clone jinjs from git, and install its dependencies via npm the parser works correctly.

Change the undefined var printing policy

Allow for greater control :

  • throw Exception
  • print ""
  • catch Exception when using/calling stuff of undefined variables.

Only will work in the {{ }} statement, and will be defined at the environment level.

directory layout and/or package.json wrong possibly?

While attempting to use the jinjs package for the first time via npm install

npm install jinjs

coffee test.coffee 
Error: Cannot find module 'jinjs'
    at Function._resolveFilename (module.js:334:11)
    at Function._load (module.js:279:25)
    at Module.require (module.js:357:17)
    at require (module.js:373:17)

   <snip>Im paranoid about file paths :)</snip>
# contents of test.coffee
jinjs = require "jinjs"

I was able to get it working by simply creating symlink to tball/lib

ln -s tball/lib/ lib

express running, modified template cannot be rendered rightly

when express server is running, I modify my template. Then access the page, the errors occurred:

500 TypeError: Cannot set property '/home/jock/apps/huodongtong/app/views/layout/form_layout.html' of undefined
at /home/jock/node_modules/jinjs/lib/environment.js:159:38
at eval at (/home/jock/node_modules/jinjs/lib/environment.js:165:14)
at Object.render (eval at (/home/jock/node_modules/jinjs/lib/environment.js:165:14))
at ServerResponse._render (/home/jock/node_modules/express/lib/view.js:425:21)
at ServerResponse.render (/home/jock/node_modules/express/lib/view.js:318:17)
at Controller.render (/home/jock/node_modules/locomotive/lib/locomotive/controller.js:98:14)

But, when I restart the server, all is right again.

what's the problem? Jinjs cached something or not?

Another question, can Jinjs can persist the compiled templates into physical files?

Implement named arguments function calling

This can't be implemented on functions that comme from javascript.

However, it would be possible for macros, filters, and tests, to have an optional signature attribute with a list of arguments and a default_args to fill up the missing attributes when not specified.

Exemple ;

exports.dictsort = (value, case_sensitive ? false, _by ? 'value') ->
   ...
exports.dictsort.signature = ["value", "case_sensitive", "by"]
exports.dictsort.default_args = ["", false, "value"]

if a call is parsed and "by" is specified, then case_sensitive still gets sent false.

A little wish

I would you would port that application to Fortran.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.