pug

Would it benefit to pre-compile jade templates on production in express

时光怂恿深爱的人放手 提交于 2019-12-01 04:12:44
When using jade-lang on production, would I benefit from having some form of a middleware that pre-compiles all the .jade views and then uses them in res.render? Or does that automatically happen when you do NODE_ENV=production? I'm simply exploring options on how to speed-up jade rendering on production. When Jade compiles the template, the template is cached. In production environment if you warm up the cache, then there is no need to pre-compile template. Even if you don't, the template will be cached after its first compilation. I recommend you to have a look Jade's source code to better

node.js + express 3 + socket.io = Can't set headers after they are sent

浪子不回头ぞ 提交于 2019-12-01 04:09:45
I'm new to learning node.js and seem to have run into an error that can't get to fix. Its a very simple and beginners code so shouldn't need much explanation, more over it works fine on localhost, but breaks on production server. App.js var express = require('express') , routes = require('./routes') , http = require('http') , path = require('path'); var app = express(); app.configure(function(){ app.set('port', process.env.PORT || 8000); app.set('views', __dirname + '/views'); app.set('view engine', 'jade'); app.use(express.favicon()); app.use(express.logger('dev')); app.use(express.bodyParser

Jade templating, variable scope in includes

孤街醉人 提交于 2019-12-01 04:03:45
I am using Jade (without Express, just for static HTML templating) - which I understood as able to create partials, meaning scope is not an issue, but this doesn't seem to be the case and I can find no reference to this use-case. master.jade !!! 5 html block vars - var slug= 'home' head block pagetitle title Static HTML link(rel='stylesheet', href='css/styles.css') body(class= slug) .wrapper include includes/header includes/header.jade .header ul li(class= slug) I have tried syntax variants including #{slug} and always get the error "slug is not defined" within the includes/header.jade file -

get user agent from inside jade

假如想象 提交于 2019-12-01 03:35:12
I am trying to port a script I wrote for groovy over to jade, and have run into a stumbling block I need to access the user-agent from inside a jade file. Here is what I have tried so far: - var agent = req.headers['user-agent']; - var agent = headers['user-agent']; - var agent = navigator.userAgent; every time I get a 500 error from express. Is this even possible? I know I could do it in a module and pass it to the render statement, but that would mean passing it to EVERY render, as it needs to be global. Very new to node, and confused. Thanks SO. Just write your own tiny middleware app.use

Jade - way to add dynamic includes

孤人 提交于 2019-12-01 03:11:36
I'd like to do something like the following within a jade template. include page-content/#{view.template} As this won't work I have ended up with. -if(view.path==="/") include ../page_content/home -else if(view.path==="/login/") include ../page_content/login -else if(view.path==="/join/") include ../page_content/join -else if(view.path==="/user/") include ../page_content/user ad nauseum I asked TJ whether it was possible, he replied unfortunately no, they're compile-time includes, which is somewhat necessary for a few technical reasons that I wont get into but we may eventually need to add a

Writing dynamic CSS with Jade

纵然是瞬间 提交于 2019-12-01 02:55:40
I'm trying to write out some dynamic CSS using Jade, like so: style(type='text/css') each item in colors .#{item.class} { background-color : #{item.background}; color: #{item.foreground}; } However this gives the following error: ReferenceError: media='print') 7| style(type='text/css') > 8| - for(var item in colors) 9| .#{item.class} { background-color : #{item.background}; color: #{item.foreground}; } 10| block Content 11| include scheduleTemplate item is not defined If I remove the style tag, it renders fine. Is there any way to use iteration within a style block? Because style tags only

Reload a page after res.redirect('back') in route

你说的曾经没有我的故事 提交于 2019-12-01 02:01:12
I'm working on an application which allows you to upload images, and create albums. Everything works fine accept that after an album is created the new album isn't shown in the client until the page is reloaded, and I can't figure out how to solve this. Below is the route for creating an album. Is it somehow possible to use something else than res.redirect('back') in this case so that the page is reloaded after the route has finished? Of course I could copy/paste the code from the route for loading the page in the first place, but that would be to much DRY. Maybe I can call the other route

node.js + express 3 + socket.io = Can't set headers after they are sent

醉酒当歌 提交于 2019-12-01 01:45:12
问题 I'm new to learning node.js and seem to have run into an error that can't get to fix. Its a very simple and beginners code so shouldn't need much explanation, more over it works fine on localhost, but breaks on production server. App.js var express = require('express') , routes = require('./routes') , http = require('http') , path = require('path'); var app = express(); app.configure(function(){ app.set('port', process.env.PORT || 8000); app.set('views', __dirname + '/views'); app.set('view

Jade templating, variable scope in includes

◇◆丶佛笑我妖孽 提交于 2019-12-01 00:32:13
问题 I am using Jade (without Express, just for static HTML templating) - which I understood as able to create partials, meaning scope is not an issue, but this doesn't seem to be the case and I can find no reference to this use-case. master.jade !!! 5 html block vars - var slug= 'home' head block pagetitle title Static HTML link(rel='stylesheet', href='css/styles.css') body(class= slug) .wrapper include includes/header includes/header.jade .header ul li(class= slug) I have tried syntax variants

How to pass value to a onclick function in (Jade)pug?

青春壹個敷衍的年華 提交于 2019-11-30 23:08:17
I am new to jade and stuck on this issue. I think I have tried everything from the StackOverflow posts and still at nothing. The things I have tried button(type='button' class=' c-btn-blue c-btn-circle c-btn-uppercase' value="Read More" onclick='gotoBlog( #{val.link} )') Error 1:8 Uncaught SyntaxError: Invalid or unexpected token Changing it to !{val.link} Error Uncaught SyntaxError: Unexpected token . Changing it to "!{val.link}" and "#{val.link}" just gives me string understandably so. BTW val.link is a string Just giving val.link says Uncaught ReferenceError: val is not defined I am out of