pug

How to copy compiled jade files to a destination folder using grunt

佐手、 提交于 2019-12-03 10:19:35
问题 For a single page app that I'm working on, I have the following structure: dist css js lib partials index.html src css js lib views partials index.jade Directory dist will be used by the express server to serve the project. I have trivial grunt tasks (using grunt-contrib-clean , grunt-contrib-copy ) for cleaning dist and copying src/css , src/js , src/lib to dist . The problem lies with src/views . This directory contains jade files which need to be compiled to html files. After compilation I

Include SVG xml in Jade template

旧时模样 提交于 2019-12-03 09:14:50
问题 Is it possible to create a Jade mixin, which reads a file from the file system, and echoes it into the rendered HTML? I tried this... mixin svg(file) - var fs = require("fs"); - var xml = fs.readFileSync(file) div= xml ... but it fails because require does not exist. 回答1: I guess there are two ways to achieve this. Latter one just shows the straight way in case not using mixins is acceptable for you. The first solution wraps up your approach: A: Pass variable require or fs to your jade

How to render precompiled Jade (Pug) templates in a Node.js Express app?

时光怂恿深爱的人放手 提交于 2019-12-03 08:07:42
I have a nodejs app that uses Express and Jade(now Pug). I want to precompile the jade templates for better performance. I have been able to convert the jade to javascript using jade --client to compile all the .jade files to corresponding .js. How do I use these js files in my app? I don't have much experience with nodejs/express, but I think it must require changing the rendering engine? I have read the official documentation that says to use runtime.js but I couldn't find any documentation as how exactly it is to be used. Jade (now Pug) is a great templating engine, but the compilation of

Passing raw Markdown text to Jade

安稳与你 提交于 2019-12-03 07:38:11
问题 I'm playing around with my first Node.js Express application, and as every programmer knows, the first thing you should build when testing out a new framework is a blog! Anyway, I'd like to write the articles in Markdown and then render it in the view. I saw that Jade allows for this to be done inside the view itself, using filters, but I can't get that working. To simplify the situation, here's an example of what I'm talking about. //app.js res.render("article", { md : "Hello World!\n\n*Woo*

Jade template layouts not working in combination with Node.js

限于喜欢 提交于 2019-12-03 07:11:59
问题 I'm trying to create a simple server in Node.js which uses Jade templates and layouts. For some reason it will only load the template and not the layout. Here's what I've got: main.js var express = require('express'); var app = express.createServer(); app.set('views', __dirname + '/views'); app.set('view engine','jade'); app.set('view options', { layout: true }); app.get('/', function(req,res) { res.render('index', { title: 'My site' }); }); app.listen(4000); As you can see layouts are

Partial Not Defined in Jade

本秂侑毒 提交于 2019-12-03 06:46:47
Here is what I have in index.jade. And yes I am using express.js extends layout block content h1 Invoices: != partial("invoice") This matches what I see in every single Jade/Express tutorial. But I get "Reference error: partial not defined". Any ideas why? Jade newest version doesn't support partials. You might be following outdated tutorials. Please read up on jade documentation here Use include , without quotes (This example is from the jade documentation ) users = [{ name: 'Tobi', occupation: 'Ferret' }] each user in users .user include invoice Where invoice is your "partial" template. 来源:

Node - how to run app.js?

纵饮孤独 提交于 2019-12-03 06:11:56
问题 I am very new to Node.js and I tried to run a project (made by other developer) by having a command in terminal node app.js . But I encountered below error, do you have any idea how to run this project? I followed few instructions here to run a project. Error logs below: Junryls-Mac-mini:app junrylmaraviles$ node app.js /Users/junrylmaraviles/Desktop/myfolder/mysubfolder/app/app.js:1 (function (exports, require, module, __filename, __dirname) { define('src/app' ^ ReferenceError: define is not

Is there a Jade template syntax checker/validator?

这一生的挚爱 提交于 2019-12-03 06:02:39
I have some syntax errors in my Jade templates. Are there any tools that can help me debug? Found it. Use jade [fileName].jade to debug your Jade template. You can install the Jade tool with npm install jade --global . Adding this here because I still had to google. npm i -g pug-lint NOTE: jade has changed its name to pug web storm is a better tool for jade development ,it idents and corrects jade files 来源: https://stackoverflow.com/questions/14173144/is-there-a-jade-template-syntax-checker-validator

Express.js: app.locals vs res.locals vs req.session

僤鯓⒐⒋嵵緔 提交于 2019-12-03 05:55:24
问题 I'm trying to understand when it's best to use each of the following. Here is my rudimentary understanding: app.locals -- good for storing global variables at the app level. all users/sessions will see the same values for these variables. the variables are available to all views. res.locals -- good for storing variables for the specific request/response cycle. the variables are only available to the view associated with the response. req.session -- good for storing variables associated with

Static HTML compilation with partials using Grunt.js [closed]

送分小仙女□ 提交于 2019-12-03 05:51:37
问题 Closed. This question is off-topic. It is not currently accepting answers. Want to improve this question? Update the question so it's on-topic for Stack Overflow. Closed 5 years ago . I've been looking all over for something that will let me precompile static websites using Grunt. It needs to have partials, so I can include things like a common header/footer across the pages. So far, I've only really found Jade, which has a grunt plugin, and this plugin for Grunt that compiles Dust.js