GithubHelp home page GithubHelp logo

8lueberry / express-dot-engine Goto Github PK

View Code? Open in Web Editor NEW
43.0 43.0 10.0 140 KB

Node.js engine using the ultra fast doT templating with support for layouts, partials and friendly for front-end web libraries (Angular, Ember, Backbone...)

License: MIT License

JavaScript 100.00%

express-dot-engine's People

Contributors

1mike12 avatar 8lueberry avatar cjsturgess avatar danlevan 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

Watchers

 avatar  avatar  avatar

express-dot-engine's Issues

Choose layout master while rendering

I'd like to switch layout master based on whether the request was made over xhr or directly. I can also imagine someone switching layout based on other information or model state.

I could not find a direct way to do this. What I came up with for the moment is the following

  • change render and renderSync to pass options directly to template.render()
  • this requires the express call to be of the form res.render(template,{model:{},layout:{layout:'other.dot'}})
  • adjust template.render to redefine this.master based on the given layout template.

However, this is not in line with how a model is normally passed on in express template engines.

Any other ideas?

Crash server when template is incorrect.

The error should be handle by express,but it didn't.

 webServer.use(function(err, req, res, next) {
        // set locals, only providing error in development
        res.locals.message = err.message;
        res.locals.error = req.app.get('env') === 'development' ? err : {};

        // render the error page
        res.status(err.status || 500);
        res.render('error');
    });

It just crash the whole application.
image

And the client never get response and server dead.
It can be fixed by modify the script

index.js line:321 in buildTemplate(...)
// function to call when retrieved template content
  function done(err, templateText) {
    callback(err, builtTemplateFromString(templateText, filename, options));
  }

to

index.js line:321 in buildTemplate(...)
 // function to call when retrieved template content
  function done(err, templateText) {
    if(err)
        callback(err);
    else
      callback(err, builtTemplateFromString(templateText, filename, options));
  }

Result:Errors handle by express and client get the server side error response.
image

Is any reason why for providing synchronized code? Will this project supports ES6 Promise in the future?

Hi,

I was looking for a better view engine and got to know doT.js template engine. Firstly, I want to thank you for writing this awesome work.

I just look deeply into this project. And I found this project have greatly supports the synchronized coding style, but not so sure, why?

I think the occasion for a templating engine firing is when server executing res.render(filename, options, (callback)) which is often at the end of a client request. So, that's why I'm not sure if anything is sitting behind req.render should wait if no callback function being provided (i.e. synchronized mode). To me, it seems if any task behind req.render will have to wait until its accomplishment, so there is no differences as if synchronized or asynchronized. Am I wrong?

Also, instead of a callback function, I see more and more developers switch their gear to Promises. So will you provide this feature? (although I'm trying to rewire this engine for supporting native ES6 Promise feature right now, and I'm happy to issue a PR.)

Npm update

Hi,

Please update npm repository with the latest version.

Thanks.

Passing data to partials.

Not really an issue, more usability issue in that 'how can I pass data to a partial?'

In the past I have used Zetzer https://github.com/brainshave/zetzer which is also based on dot.

When using partials in Zetzer you can pass data to the partial like so:

{{= partial(path, {varA: va;, varB: val ...} )

Which are then accessed in the partial like so:

{{= model.varA }}

Q: How can I achieve the same using express-dot-engine ?

SOLVED: express-dot-engine works in exactly the same way as described above. A couple of my own errors had led me to the false conclusion that express-dot did not support partial with data.

Yet another 'numpty' moment ! :)

Make syntax change more obvious.

It's really nice, but could you please make it more obvious that you changed the {{}} to [[]] ?
I spent half an hour trying to figure out what was wrong, completely forgetting to rtm. It'd be nice if you put it at the top of readme.md =)

Give location for rendering error

I'm currently moving some existing code from some nasty stand-alone wrappers for Dot to use the express engine instead. Sometimes when I convert a file I get an error

/Users/jacob/Dev/work/cloud/node_modules/express-dot-engine/index.js:372
  str.replace(settings.config, function(m, conf) {
      ^
TypeError: Cannot call method 'replace' of undefined
    at builtTemplateFromString (/Users/jacob/Dev/work/cloud/node_modules/express-dot-engine/index.js:372:7)
    at done (/Users/jacob/Dev/work/cloud/node_modules/express-dot-engine/index.js:323:19)
    at /Users/jacob/Dev/work/cloud/node_modules/express-dot-engine/index.js:355:7
    at fs.js:271:14
    at Object.oncomplete (fs.js:107:15)

Preceeding this stack is the entire stringified dot template that I'm trying to render into. There really needs to be some kind of marker so that I know which template item in the file is failing to render correctly. Some of these files are large with a lot of templating in them and trying to track this down is almost impossible.

No data in model

//doT defaults
expressDoT.settings.dot = {
evaluate: /[[([\s\S]+?)]]/g,
interpolate: /[[=([\s\S]+?)]]/g,
encode: /[[!([\s\S]+?)]]/g,
use: /[[#([\s\S]+?)]]/g,
define: /[[##\s_([\w.$]+)\s_(:|=)([\s\S]+?)#]]/g,
conditional: /[[?(?)?\s_([\s\S]?)\s]]/g,
iterate: /[[~\s_(?:]]|([\s\S]+?)\s_:\s_([\w$]+)\s_(?::\s_([\w$]+))?\s*]])/g,
varname: 'layout, model',
strip: false,
append: true,
selfcontained: false
};

//server side
var context = {
csrf: req.csrfToken(),
navbar: 'map',
accountTypeID: req.session.accountTypeID,
accountID: req.session.accountID,
accountUsername: req.session.accountUsername,
accountEmail: req.session.accountEmail,
accountName: req.session.accountName,
accountPhoto: req.session.accountPhoto,
accountReference: req.session.accountReference,
payload: payload
};

res.render('map/index-view.dot', context);

//inside index-view.dot
[[= model.csrf ]]
[[= JSON.stringify(model) ]]

Both say undefined

chane settings to use {{}} issue

When I changed to use {{ }} instead of [[ ]] the partial dont work anymore
// doT settings

engine.settings.dot = {
evaluate: /[[([\s\S]+?)]]/g,
interpolate: /[[=([\s\S]+?)]]/g,
encode: /[[!([\s\S]+?)]]/g,
use: /[[#([\s\S]+?)]]/g,
define: /[[##\s_([\w.$]+)\s_(:|=)([\s\S]+?)#]]/g,
conditional: /[[?(?)?\s_([\s\S]?)\s]]/g,
iterate: /[[~\s_(?:]]|([\s\S]+?)\s_:\s_([\w$]+)\s_(?::\s_([\w$]+))?\s*]])/g,
varname: 'layout, model',
strip: false,
append: true,
selfcontained: false,
};

then
{{= partial('path/test')}} - partials is not defined

Multiple section support with UTF-8 BOM

Hi,

Multiple section support with a file encoded in UTF-8 only works without BOM, with BOM the mark "---" isn't recognized.

Solved using

engine.settings.config = /^\uFEFF?---([\s\S]+?)---/g;

Thanks,
Emanuel

How to pass a variable to a helper method

How do I pass a variable to a helper method?

This throws "ReferenceError: item is not defined":

[[~ model.array :item]]
    <tr>
        <td>[[# def.DateFormat(item.date) ]]</td>
    </tr>
[[~]]

Is there a way to do this?

How forEach works ?

I cant figure out how forEach work, I followed dot.js instructions but it gives syntax error.

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.