pug

Global variable for Jade templates in node.js

谁都会走 提交于 2019-12-07 06:30:44
问题 I am using node.js with Jade templating system. Assume, I have these routing rules: // ./routes/first.js exports.first = function(req, res) { res.render('first', { author: 'Edward', title: 'First page' }); }; // ./routes/second.js exports.second = function(req, res) { res.render('second', { author: 'Edward', title: 'Second page' }); }; And these dummy views: // ./views/first.jade html head title #{author} – #{title} body span First page content // ./views/second.jade html head title #{author}

How to separate inline javascript from dynamically generated content in Express/Node.js?

不问归期 提交于 2019-12-07 02:56:46
问题 This is a somewhat noob-question for someone who had a few years of web development experience, but after not finding the answer on either Programmer Stack Exchange or Google , I have decided to ask it here. I am using Express web framework for Node.js , but this question is not specific to any web framework or programming language. Here's a list of games that are queried from the database. Each game entity is a single table row, generated using a for-loop : table.table tbody for game in

Jade Syntax Highlighting in Visual Studio 2013

若如初见. 提交于 2019-12-07 00:53:26
问题 I wonder if there is an option I missed in Visual Studio 2013 to get the Jade syntax highlighting to work? There is a pretty good integration of Node.js , Express and Jade in Visual Studio 2013, but it seems it lacks a proper syntax highlighting. In that WebMatrix Tool of Microsoft the Jade syntax works pretty well and I dont't get because of what that features is missing in VS 2013. Maybe I made a mistake at some point of installation, project creating, missed an option or something like

Expanding an object to set attributes in Jade

帅比萌擦擦* 提交于 2019-12-06 23:37:22
问题 I would like to be able to pass in an object with key/value pairs that represent attributes for an element. Is this possible with Jade? Any solution that allows me to pass an attributes collection into my template would be sufficient, but the ability to mix explicitly declared attributes with attributes extracted from an object (as below) would be ideal. The following syntax does not work, it is just an example of what I'd like to do. For example, if I passed this: { name:'username', value:

Using different indentation for Jade

房东的猫 提交于 2019-12-06 22:14:59
问题 From this tutorial it seems that Jade requires 2-spaces tabs. Can I use another tabbing syntax with Jade? 回答1: It's not necessary to use only two spaces for tabbing. You can use any number of spaces (consistently) or a tab character to indent. The only quirk is you can't use both spaces and tabs at the same time, or it will give an error while compiling. See this link Jade. 回答2: The tab size must be 4, when I use gulp-template. 来源: https://stackoverflow.com/questions/8378471/using-different

Jade: declare a variable over multiple lines

微笑、不失礼 提交于 2019-12-06 20:29:17
问题 I have a jade variable declared like this: BUTTONS = { more_blue: {caption: BUTTONS_CAPTIONS.more, style: BUTTONS_STYLES.blue}, more_red: {caption: BUTTONS_CAPTIONS.more, style: BUTTONS_STYLES.red}, see: {caption: BUTTONS_CAPTIONS.see, style: BUTTON_STYLE_PHOTOS}, see_photos: {caption: BUTTONS_CAPTIONS.see_photos, style: BUTTON_STYLE_PHOTOS}, program : {caption: BUTTONS_CAPTIONS.program, style: BUTTON_STYLE_PROGRAM}, see_program : {caption: BUTTONS_CAPTIONS.see_program, style: BUTTON_STYLE

Long block of text in Jade textarea?

一曲冷凌霜 提交于 2019-12-06 18:54:18
问题 I'm using Jade in my latest node.js app. I'd like to have a long block of text in a textarea by default. If I do something like this: textarea(id="theTextarea") it renders just fine: <textarea id="theTextarea"></textarea> However, if I do something like so: textarea(id="theTextarea") Hello world. I get this: <textarea id="theTextarea"> <hello>world</hello> </textarea> But I'd like it to be like so: <textarea id="theTextarea"> hello, world </textarea> Any ideas? 回答1: textarea(id="theTextarea")

Jade: element attributes without value

本小妞迷上赌 提交于 2019-12-06 18:47:38
问题 I am new to using Jade -- and it's awesome so far. But one thing that I need to happen is an element with 'itemscope' property: <header itemscope itemtype="http://schema.org/WPHeader"> My Jade notation is: header(itemscope, itemtype='http://schema.org/WPHeader') But result is: <header itemscope="itemscope" itemtype="http://schema.org/WPHeader"> How can I make sure that I get the right result -- itemscope instead of itemscope="itemscope" ? 回答1: I just tried it in a Express.js/Jade project and

How to auto-generate html from jade file when only included markdown file has changed in livereload development environment?

大兔子大兔子 提交于 2019-12-06 17:04:24
问题 So I've got a file like this: # index.html.jade p Test include content.md So if I change the content of content.md out/index.html is not regenerated (because the index.html.jade file itself of course has not changed). (I am using livereload - in the HTML 5 Boilerplate docpad template - and the so the browser does not refresh on a valid change :-( ) On the other hand the final out/index.html file of the previous and current version (after the content.md change) are different (most likely on

assigning value to a variable inside a jade file

北战南征 提交于 2019-12-06 17:01:21
问题 Is it possible to assign variables inside a jade file, in order to make the code more readable? Specifically, I created this jade file: extends layout - var format = "%+1.0f" block title title Your score table block body ... td.utilityUtil #{sprintf(format,value)} ... And got an error in the last line, that "format" is not defined. Probably I don't assign it correctly, but I didn't find the correct syntax. P.S. I have Express 3. 回答1: You have to declare the variable in the block scope :