pug

Passing an array to a JSON object for Jade rendering

不打扰是莪最后的温柔 提交于 2019-11-28 18:08:28
问题 I have a node.js server written in express and at a certain moment I send to some .jade page an array. The problem is that when rendering the Jade page, the Jade compiler renders the array as [object Object] and the JavaScript compiler on Chrome complains about it saying "Unexpected identifier". This is the Jade code: !!! 5 html(lang="en") head title= "Rankings" body h1 Ranking div(id="rankings") script(type='text/javascript') function fillRanking(){ var rankArray = #{ranking}; alert("inside

What about Line Breaks in Jade?

醉酒当歌 提交于 2019-11-28 18:05:26
I'm pretty sure that this is a no-brainer but I didn't find any snippet of sample code. What's the best way to insert line breaks (aka the good ol' br/)? As far as I can see if I put a "br" at the beginning of an empty line, it is rendered as <br/> but if I have to show several lines of text, the resulting code is quite verbose: .poem p | Si chiamava Tatiana, la sorella… br | Noi siamo i primi, almeno lo crediamo br | Che un tale nome arditamente nella br | Cornice d’un romanzo introduciamo. br | E che dunque? E’ piacevole, sonoro. br | Lo so che a molti privo di decoro br | Apparirà, già

Jade conditional (if/else) to add class to div inline

人盡茶涼 提交于 2019-11-28 17:42:45
Is there a way to do this inline in a jade template? if(typeof fromEdit != 'undefined') div#demo.collapse.in else div#demo.collapse Would like to do this conditional check "inline" and the result would add the .in to the end of the div if fromEdit exists. This works: div#demo.collapse(class=typeof fromEdit === "undefined" ? "" : "in") Try it out here . If you don't want the class attribute to be added when there is no value, you can assign it undefined instead of an empty string. Here is the previous example, slightly modified: div#demo.collapse(class=typeof fromEdit === "undefined" ?

Using Jade Templates (jade-lang.com) client-side

寵の児 提交于 2019-11-28 17:16:37
I'd like to use Jade templates client-side. Preferably generated using the Rails 3.1 asset pipeline. I can't really figure out how to do this. Anyone who've stumbled upon the same problem and found a great solution? Any thoughts are much appreciated. http://jade-lang.com/ http://ryanbigg.com/guides/asset_pipeline.html Alfred P.S: Probably right now Substack's answer is better. browserify Maybe you can use https://github.com/substack/node-browserify Browser-side require() for your node modules and npm packages Just point a javascript file or two at browserify and it will walk the AST to read

Node.js + Express without using Jade

强颜欢笑 提交于 2019-11-28 17:11:44
Is it possible to use express without any template engine? UPDATED Some might have concerns that sendFile only provides client side caching. There are various ways to have server side caching and keeping inline with the OP's question one can send back just text too with send : res.send(cache.get(key)); Below was the original answer from 3+ years ago: For anyone looking for an alternative answer to PavingWays, one can also do: app.get('/', function(req, res) { res.sendFile('path/to/index.html'); }); With no need to write: app.use(express['static'](__dirname + '/public')); Yes, app.get('/',

Jade: Change active menu item in parent template

天涯浪子 提交于 2019-11-28 17:01:50
I have a navigation bar in my parent jade template and I'd like to highlight the item which is currently in view. So if I'm on the blog page, ul li Home li.active Blog li Contact Us li About Without copying the navigation bar structure into each child template, is there a way to have the parent template see what page it's extending and apply the active class accordingly? parent.jade doctype 5 html block link -var selected = 'home'; //default -var menu = { 'home': '/home', 'blog': '/blog', 'contact': '/contact' }; body nav ul each val, key in menu li if selected === key a.selected(href=val,

Jade: Links inside a paragraph

前提是你 提交于 2019-11-28 16:54:17
问题 I'm trying to author a few paragraphs with Jade, but finding it difficult when there are links inside a paragraph. The best I can come up with, and I'm wondering if there's a way to do it with less markup: p span. this is the start of the para. a(href="http://example.com") a link span. and this is the rest of the paragraph. 回答1: As of jade 1.0 there's an easier way to deal with this, unfortunately I can't find it anywhere in the official documentation. You can add inline elements with the

Jade - Template Engine: How to check if a variable exists

强颜欢笑 提交于 2019-11-28 15:37:56
I'm currently using Jade on a new project. I want to render a page and check if a certain variable is available. app.js : app.get('/register', function(req, res){ res.render('register', { locals: { title: 'Register', text: 'Register as a user.', } }); }); register.jade : - if (username) p= username - else p No Username! I always get the following error: username is not defined Any ideas on how I can fix this? Chetan This should work: - if (typeof(username) !== 'undefined'){ //-do something -} BMiner Simpler than @Chetan's method if you don't mind testing for falsy values instead of undefined

Syntax highlighting for Jade in Sublime Text 2?

我们两清 提交于 2019-11-28 15:11:08
I just started using Sublime Text 2 on Mac. I also just started using Jade for my views in Node.js, and am wondering if there is a way to add syntax highlighting for Jade into Sublime Text 2. Rob Cowie Sublime Text 2 supports Textmate syntax definition files. There is a Jade Textmate bundle at https://github.com/miksago/jade-tmbundle . Install by creating a new folder in your Sublime Text "Packages" folder, call the new folder Jade , then curl -O https://raw.github.com/miksago/jade-tmbundle/master/Syntaxes/Jade.tmLanguage or otherwise download that file into the new folder. The editor will

Change value of input placeholder via model?

▼魔方 西西 提交于 2019-11-28 09:34:45
I'm trying to change the value of the input placeholder from a controller but cant quite figure out how. input(type='text', ng-model='inputText', side='30', placeholder='enter username') Is there a way to modify a model's element attributes? You can bind with a variable in the controller: <input type="text" ng-model="inputText" placeholder="{{somePlaceholder}}" /> In the controller: $scope.somePlaceholder = 'abc'; The accepted answer still threw a Javascript error in IE for me (for Angular 1.2 at least). It is a bug but the workaround is to use ngAttr detailed on https://docs.angularjs.org