Giter Club home page Giter Club logo

ejs's People

Contributors

3imed-jaberi avatar baoshan avatar bergren2 avatar bodokaiser avatar cyrilf avatar dead-horse avatar dislido avatar halfcrazy avatar kozakvoj avatar lopezchr avatar nswbmw avatar pana avatar runrioter avatar sirwumpus avatar titanism avatar webnard avatar zedgu avatar zensh 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  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar

ejs's Issues

Upgrade ejs to v3.x

ejs 3.x drops support for Node 4 and 6, and it removes require.extensions which previously caused an annoying warning in webpack bundles: mde/ejs#412.

Since this package already requires Node >= 7.6, I don't think this upgrade should warrant a major version bump.

why the response like this?

I use koa2 and koa-ejs to make a react ssr demo
koa code:

const markup = renderToString(
    <Provider store={store()} >
        <RouterContext { ...props } />
    </Provider>
);
await ctx.render('index', { markup });

chrome devtool look like this:

<html>
<head>
    <title>koa2 webpack2 react ssr</title>
</head>
<body>
    <div id="root">&lt;div data-reactroot=&#34;&#34; data-reactid=&#34;1&#34; data-react-checksum=&#34;-1292022691&#34;&gt;&lt;h4 data-reactid=&#34;2&#34;&gt;This is React App Component&lt;/h4&gt;&lt;a href=&#34;/a&#34; data-reactid=&#34;3&#34;&gt;A&lt;/a&gt;&lt;a href=&#34;/b&#34; data-reactid=&#34;4&#34;&gt;B&lt;/a&gt;&lt;a href=&#34;/c&#34; data-reactid=&#34;5&#34;&gt;C&lt;/a&gt;&lt;div data-reactid=&#34;6&#34;&gt;This is B&lt;/div&gt;&lt;/div&gt;</div>
    <script src="./bundle.js"></script>
</body>
</html>

why?

can't cache <% include('./head.html', {foo: 'bar'}) %>

can't cache <% include('./head.html', {foo: 'bar'}) %> because ejs.compile options not have params cache which developer seted:

const fn = ejs.compile(tpl, {
    filename: viewPath,
    _with: settings._with,
    compileDebug: settings.debug && settings.compileDebug,
    debug: settings.debug,
    delimiter: settings.delimiter
});

Satus of the project

Hello,

is this package/repository still maintained or is slowly getting to death?

Thank you

Always get a 204 (no content) response no matter what settings I use

currently i have this on the server:

var path = require('path');
var koa = require('koa');
var render = require('koa-ejs');

var app = koa();

render(app,{
  root: path.join(__dirname, "views"),
  layout:false
});

app.use(function*(){
  this.body = yield this.render("home");
});

app.listen(3000);
console.log("listen at localhost:3000");

.. and as "home" (views/home.html)

<html>
  <head>
    <title>koa ejs</title>
  </head>

  <body>
    hello koa-ejs
  </body>

</html>

when a run curl localhost:3000 -v I get:

* Rebuilt URL to: localhost:3000/
* Hostname was NOT found in DNS cache
*   Trying 127.0.0.1...
* Connected to localhost (127.0.0.1) port 3000 (#0)
> GET / HTTP/1.1
> User-Agent: curl/7.35.0
> Host: localhost:3000
> Accept: */*
> 
< HTTP/1.1 204 No Content
< X-Powered-By: koa
< Date: Wed, 15 Oct 2014 03:08:15 GMT
< Connection: keep-alive
< 
* Connection #0 to host localhost left intact

Am I doing something wrong? I'm using this dependencies:

"dependencies": {
    "koa": "^0.12.2",
    "koa-ejs": "^1.1.2"
  }

koa 2.x

Hi,
Is there any sample code for ejs to be used with koa 2.x? thanks,
A.

有时候正常运行过程中会报这个错

RangeError: Maximum call stack size exceeded
at ejs.resolveInclude (/aaa/node_modules/koa-ejs/index.js:85:26)
at ejs.resolveInclude (/aaa/node_modules/koa-ejs/index.js:89:14)
at ejs.resolveInclude (/aaa/node_modules/koa-ejs/index.js:89:14)
at ejs.resolveInclude (/aaa/node_modules/koa-ejs/index.js:89:14)
at ejs.resolveInclude (/aaa/node_modules/koa-ejs/index.js:89:14)
at ejs.resolveInclude (/aaa/node_modules/koa-ejs/index.js:89:14)
at ejs.resolveInclude (/aaa/node_modules/koa-ejs/index.js:89:14)
at ejs.resolveInclude (/aaa/node_modules/koa-ejs/index.js:89:14)
at ejs.resolveInclude (/aaa/node_modules/koa-ejs/index.js:89:14)
at ejs.resolveInclude (/aaa/node_modules/koa-ejs/index.js:89:14)

然后后面的渲染就全挂了,一直报这个错

Wrong function reference cause 'Maxiumn call stack size exceeded'

ejs/index.js

Line 84 in f70a090

const parentResolveInclude = ejs.resolveInclude;

Each call to the render function will be reassigned parentResolveInclude. The call stack gets longer and longer.

Add the log on line 86

    const parentResolveInclude = ejs.resolveInclude;
    ejs.resolveInclude = function(name, filename, isDir) {
      console.log(name);
      if (!path.extname(name)) {
        name += settings.viewExt;
      }
      return parentResolveInclude(name, filename, isDir);
    }
  • The first access page
template/head
template/google-analysis
template/nav
template/copyright
  • The second access page
template/head
template/head.ejs
template/google-analysis
template/google-analysis.ejs
template/nav
template/nav.ejs
template/copyright
template/copyright.ejs
  • The third access page
template/head
template/head.ejs
template/head.ejs
template/google-analysis
template/google-analysis.ejs
template/google-analysis.ejs
template/nav
template/nav.ejs
template/nav.ejs
template/copyright
template/copyright.ejs
template/copyright.ejs

I think should move line 84 to line 32.

doctype html bug

adding DOCTYPE html to the top of the layout template inserts HTML file in an HTML file

New verson was not release.

Hi,

thanks a lot for merging all the PR. When will be release new version of the package please?

Thanks
Jan Opravil

Provide own filesystem

Right now koa-ejs uses only actual node's filesystem.

This becomes trouble when using it with webpack-dev-middleware.

My case: I have server that uses dev middleware to manage compilation for client-side javascript. It keeps all generated assets in memory. I am able to access it's memory filesystem via devMiddlewareInstance.fileSystem which is memfs node's fs api compliant fs.

But koa-ejs accepts only path to root.

So, solution is either to add fs property to koa-ejs options which will accept any node's fs api compliant type. Or second way is to provide root as callback of type (templateFilename: string) => Promise<string>, like: root: (templateFilename) => myfs.readFilePromise(templateFilename).

What do you think?

how can i use "await locals.fn.call()"

Hi, I need such function like the co-ejs
the co-ejs only support koa1.x but I hope use in koa2
I can write code in ejs

 <% user= await locals.user.get(1) %>

thank you

Layout feature does not return layout.ejs

Can't get the layout feature to work. I have the following files.

File index.js

const path = require('path')
const views = require('koa-views')
const Koa = require('koa')
const app = module.exports = new Koa()

app.use(views(path.join(__dirname, '/views'), { extension: 'ejs' }))

const user = { name: { first: 'Tobi', last: 'Holowaychuk' }, species: 'ferret', age: 5 }

app.use(async function(ctx) {
  await ctx.render('user', { user })
})

app.listen(3000)

File views/layout.ejs

<html>
  <head>
    <title>koa ejs</title>
  </head>
  <body>
    <h3>koa ejs</h3>
    <%- body %>
  </body>
</html>

File views/user.ejs

<p><%= user.name.first %> is a <%= user.age %> year old <%= user.species %>.</p>

Copied from https://github.com/koajs/examples/blob/master/templates/app.js

Changing await ctx.render('user', { user }) to await ctx.render('user', { user, layout: 'layout.ejs' }) also does nothing.

The only result I get is <p>Tobi is a 5 year old ferret.</p> (no sign of layout.ejs).

Custom delimiters not supported

Look here: https://github.com/tj/ejs

Custom delimiters can also be applied globally:

var ejs = require('ejs');
ejs.open = '{{';
ejs.close = '}}';

Which would make the following a valid template:

<h1>{{= title }}</h1>

I thought koa-ejs supported all features? If so, howcome this isn't supported?

default settings

Hey,

would it be possible to change default settings to:

var defaultSettings = {
  cache: true,
  layout: 'layout',
  viewExt: 'html',
  open: '<%',
  close: '%>',
  filters: {},
  locals: {},
  debug: false
};

Else this does not make much sense as we need to define viewExt (to omit extension in middleware) and overwrite layout as it else searches for layout.html.html.

Would you accept a pr on this?

Ejs 2.0

I have marked that ejs have already version great then 2.0. Koa-ejs in dependencies have ejs 1.0. Why? When will the update in plans?

"locals" is not working

I suppose I should be able to add global-type variables into locals and have access to them in each template, without passing them to render function. Can you confirm that, and if it is true fix that ASAP. Thanks)

example code:
ejs(app, {
root: path.join(__dirname, '/../view'),
layout: 'layout',
viewExt: 'html',
cache: true,
debug: false,
locals: {
test: "some global variable"
}
});

mount koa-ejs@2 with koa-mount fails

When mounting another app:

Example code:

var client1 = koa();  
render(client1, {
    root: path.join(__dirname, "view"),
    viewExt: "html",
    cache: false,
    debug: true
  });
client1.context.render = co.wrap(app.context.render);

client1.use(async (ctx, next) => {
    await ctx.render(view, locals);
});

var app = koa();  
app.use(mount("/demo", client1)

Error:

"ctx.render is not a function"
{"name":"ps-search","hostname":"Phani-Pearlshare.local","pid":67479,"level":50,"req":{"method":"GET","url":"/","headers":{"host":"localhost:8080","connection":"keep-alive","pragma":"no-cache","cache-control":"no-cache","upgrade-insecure-requests":"1","user-agent":"Mozilla/5.0 (Macintosh; Intel Mac OS X 10_11_6) A
ppleWebKit/537.36 (KHTML, like Gecko) Chrome/55.0.2883.95 Safari/537.36","accept":"text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8","accept-encoding":"gzip, deflate, sdch, br","accept-language":"en-GB,en-US;q=0.8,en;q=0.6","cookie":"DFTT_END_USER_AUTH_TOKEN=derhv5sa32t86pdhkgcrwyvbirss8wk36
wfegi; DFTT_REALTIME_SESSION_TOKEN=sT9byMt5s1I2bILfzjy2jzJC-1gKYmslRc1RFkAptVqwLELpPoC5xUthRbeHXWf6P96Sc49yy50wy0kNQnkKWw.8-1; DFTT_END_USER_ID=10628333; cookieconsent_dismissed=yes; _ga=GA1.1.1305685054.1470246540; driftt_aid=7dc5c5af-5b35-4874-8c16-a92041ab68a2; driftt_wmd=true; DFTT_END_USER_PREV_BOOTSTRAPPED=true
; connect.sid=s%3Ap4MlIDqncrnWj50o1SogZgp3.wSsF%2FSEbxRWp2PIeiXAUg7dsNUS55J5kNtPn47mwgmA"},"remoteAddress":"::1","remotePort":55063},"res":{},"err":{"message":"ctx.render is not a function","name":"TypeError","stack":"TypeError: ctx.render is not a function\n    at _callee$ (/Users/Phani/new_work/ps-search/clients/de
mo/index.js:21:13)\n    at tryCatch (/Users/Phani/new_work/ps-search/node_modules/regenerator-runtime/runtime.js:64:40)\n    at Generator.invoke [as _invoke] (/Users/Phani/new_work/ps-search/node_modules/regenerator-runtime/runtime.js:355:22)\n    at Generator.prototype.(anonymous function) [as next] (/Users/Phani/ne
w_work/ps-search/node_modules/regenerator-runtime/runtime.js:116:21)\n    at step (/Users/Phani/new_work/ps-search/clients/demo/index.js:29:191)\n    at /Users/Phani/new_work/ps-search/clients/demo/index.js:29:437\n    at /Users/Phani/new_work/ps-search/clients/demo/index.js:29:99\n    at /Users/Phani/new_work/ps-sea
rch/clients/demo/index.js:20:1\n    at dispatch (/Users/Phani/new_work/ps-search/node_modules/koa-compose/index.js:44:32)\n    at next (/Users/Phani/new_work/ps-search/node_modules/koa-compose/index.js:45:18)\n    at send.then.done (/Users/Phani/new_work/ps-search/node_modules/koa-static/index.js:43:20)"},"duration":
30,"msg":"  --> GET /demo 500 30ms","time":"2016-12-20T17:24:51.737Z","v":0}

why set option 'compileDebug' as 'settings.debug && settings.compileDebug'?

koa-ejs/index.js line 96:

const fn = ejs.compile(tpl, {
      filename: viewPath,
      _with: settings._with,
      compileDebug: settings.debug && settings.compileDebug,
      debug: settings.debug,
      delimiter: settings.delimiter,
      cache: settings.cache,
      async: settings.async
    });

why set option 'compileDebug' as 'settings.debug && settings.compileDebug'
instead of 'settings.compileDebug'?

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.