pug

Jade - print all possible variables

微笑、不失礼 提交于 2019-12-01 23:06:49
问题 I would like to be able to display all available variables that the currently loaded jade file has access to. I realise this is a little odd, but there you go :) I am not really bothered if its in the console or outputting to the page. console.info(res.locals) //this gives back way more than jade has access to. 回答1: Assign that locals onto a property of itself app.use(function locals(req, res, next) { res.locals.locals = res.locals; next(); }); Then simply access locals in your Jade template.

req.files not working node.js - express

僤鯓⒐⒋嵵緔 提交于 2019-12-01 21:42:31
Hey so I am trying to accept an uploaded file but everytime I call req.files it is considered undefined... Not sure what I am doing wrong... This is my app.js file: var express = require('express') , user = require('./routes/user') , http = require('http') , path = require('path') , mongoose = require('mongoose') , mongoConnect = mongoose.connect('mongodb://localhost/clothing') , app = express(); // all environments app.set('port', process.env.PORT || 3000); app.set('views', path.join(__dirname, 'views')); app.set('view engine', 'jade'); app.use(express.favicon()); app.use(express.logger('dev'

Do the indents in an else block continue from the then block?

梦想的初衷 提交于 2019-12-01 21:31:26
The following Pug script: - data = [ "A", "B", "C", "D" ] - for (i=0,i<data.length;i++) - var even = (i%2)==0 if even .row .col #{data[i]} else .col #{data[i]} produces: <div class="row"> <div class="col">A</div> </div> <div class="col">B</div> <div class="row"> <div class="col">C</div> </div> <div class="col">D</div> What I want is: <div class="row"> <div class="col">A</div> <div class="col">B</div> </div> <div class="row"> <div class="col">C</div> <div class="col">D</div> </div> Why is the indent in the else block not followed? How do I achieve my desired output? Pug, by nature, doesn't

Applying nested object of attributes in Jade/Pug

﹥>﹥吖頭↗ 提交于 2019-12-01 19:56:06
Is there a way to pass an object of data/aria attributes to an element? I've tried: div(data={foo:'bar'}) div(data={foo='bar'}) div&attributes({aria:{foo:'bar'}}) But none of these output the desired attribute notation. The first and third place an object literal in the base data/aria attribute. The second is a syntax error. The only ways that I can find that work are: div(data-foo='bar') div&attributes({'aria-foo':'bar'}) By leading new lines with a minus - you are able to write regular JavaScript in JADE / PUG. This gives you a powerfull weapon to resolve almost everything. Just grab an

static javascript not rendering in jade (with express/node.js)

无人久伴 提交于 2019-12-01 19:33:28
I hope you are well. I'm suddenly unable to render any external javascript in jade templates! To get to the bottom of things, I stripped it down to the bare minimum : Node 0.6.11, Express 2.5.8, jade 0.20.3 app.js var express = require('express') , routes = require('./routes'); var app = module.exports = express.createServer(); app.configure(function(){ app.set('views', __dirname + '/views'); app.set('view engine', 'jade'); app.use(express.bodyParser()); app.use(express.methodOverride()); app.use(app.router); app.use(express.static(__dirname + '/public')); }); app.configure('development',

ng-view not working with partials in AngularJS/Express

拥有回忆 提交于 2019-12-01 18:43:55
Everything was working until I tried to display a partial file in ng-view. /public/app/app.js angular.module('app', ['ngResource', 'ngRoute']); angular.module('app').config(function($routeProvider,$locationProvider){ $locationProvider.html5Mode(true); $routeProvider .when('/', {templateUrl: '/partials/main', controller: 'mainCtrl'}); }); angular.module('app').controller('mainCtrl', function($scope){ $scope.myVar = "Hello Angular"; }); /server/includes/layout.jade doctype html 5 html head link(rel="stylesheet", href="/css/bootstrap.css") link(rel="stylesheet", href="/vendor/toastr/toastr.css")

ng-view not working with partials in AngularJS/Express

血红的双手。 提交于 2019-12-01 18:01:48
问题 Everything was working until I tried to display a partial file in ng-view. /public/app/app.js angular.module('app', ['ngResource', 'ngRoute']); angular.module('app').config(function($routeProvider,$locationProvider){ $locationProvider.html5Mode(true); $routeProvider .when('/', {templateUrl: '/partials/main', controller: 'mainCtrl'}); }); angular.module('app').controller('mainCtrl', function($scope){ $scope.myVar = "Hello Angular"; }); /server/includes/layout.jade doctype html 5 html head link

Pug/ Jade - input is a self closing element: <input/> but contains nested content?

瘦欲@ 提交于 2019-12-01 15:32:32
I want to create the html like this: <label class="radio-inline"> <input type="radio" name="hidden" checked="" value="Visible"> Visible </label> Pug/ Jade: label.radio-inline input(type="radio", name="hidden", value="0", checked="") Visible But I get an error: input is a self closing element: but contains nested content. What does it mean? How I can fix this? There are multiple ways to do that using Jade / Pug. The first way is to use a pipe char (which requires a new line): input | text The second way is to use tag interpolation (and you can stay on the same line): #[input] text So an

How to get image that is within a data attrbute with Webpack 2?

孤街浪徒 提交于 2019-12-01 13:55:58
I am using .pug templates for my HTML and standard src attributes on my images like so: img(src=`../images/${image}`) When I run webpack -p , any images defined in the src 's of my images are found by Webpack and placed into my dist directory. This is exactly what I would expect to happen. However, I now have a requirement to lazy load my images, so I want to place the reference to the image into a data-src attribute instead of the standard src , like so: img(data-src=`../images/${image}` src='data:image/gif;base64,R0lGODlhAQABAIAAAAAAAP///yH5BAEAAAAALAAAAAABAAEAAAIBRAA7') Running webpack -p

Pug support for Angular 2 / Angular 4 / Angular 6 / Angular cli / Angular cli 6 (without custom WebPack config)

喜欢而已 提交于 2019-12-01 12:19:17
How to install correctly PUG / JADE to Angular 2 or above So that while working and AOT and JiT Worked Unit and Integration Tests and do not suffer much when creating each new component Никита Середа I saw many solutions, some of them: in each component was added something like "require!pug-loader()some.component.pug" Get away from using angular-cli and create magic around webpack Use other servers (who know how to work with the Pug / Jade) Before running the build, convert all the pug files to html I think that they will refuse the server justified for angular - it's not true, run some pre