pug

how to escape <> in javascript underscore template?

元气小坏坏 提交于 2019-11-30 04:46:19
问题 when using underscore template i want to interpolate a value in anchor's href attribute like a(href= "<%= id %>", class='products') //underscore template in jade but the out put is <a href="&lt;% id %&gt;" class="products"> so how to escape the < and > sign , and interpolate the value correctly? 回答1: Use != instead of = to unescape. In your case: a.products(href!="<%= id %>") 来源: https://stackoverflow.com/questions/12362290/how-to-escape-in-javascript-underscore-template

In Express.js, how can I render a Jade partial-view without a “response” object?

丶灬走出姿态 提交于 2019-11-30 04:01:45
Using Express.js, I'd like to render a partial-view from a Jade template to a variable. Usually, you render a partial-view directly to the response object: response.partial('templatePath', {a:1, b:2, c:3}) However, since I'm inside a Socket.io server event, I don't have the "response" object. Is there an elegant way to render a Jade partial-view to a variable without using the response object? You can manually compile the Jade template. var jade = require('jade'); var template = require('fs').readFileSync(pathToTemplate, 'utf8'); var jadeFn = jade.compile(template, { filename: pathToTemplate,

variable in class name jade

北城以北 提交于 2019-11-30 03:12:51
I can't set a variable name in a class in jade: .flag_#{ session.locale } #{ session.locale } I have: <div class="flag_" >en</div> And I'd like to have <div class="flag_en" >en</div> Thanks Try this (have not tested): div(class="flag_#{ session.locale }") session.locale As for pug@2.0.0-alpha3 works this way: div(class="flag_" + session.locale) session.locale Here's another approach: mixin formButton(text, type, extra_classes) - var default_classes = 'btn btn-primary' if extra_classes - var classes = default_classes + ' ' + extra_classes else - var classes = default_classes if type button

AngularJS/Jade Error: Argument 'MyController' is not a function, got undefined (MEAN)

早过忘川 提交于 2019-11-30 03:05:24
问题 I know variations of this question have already been asked several times, but I've tried several suggested solutions for other OPs, haven't been able to resolve this, and would appreciate some clarification. I'm working with the basic mean todo list app (http://www.mean.io/). After implementing a simple controller I'm running into the "Error: Argument 'nameOfMyController' is not a function, got undefined." Here's where I'm at: app.js (boilerplate) window.app = angular.module('mean', [

Node says Jade has no method “renderFile”, why?

我是研究僧i 提交于 2019-11-30 03:00:36
问题 I installed jade (npm install jade) and went over to their github page to grab some examples. This is what I wanted to execute: code.jade: - var title = "Things" h1= title ul#users - each user, name in users - if (user.isA == "ferret") li(class: 'user-' + name) #{name} is just a ferret - else li(class: 'user-' + name) #{name} #{user.email} code.js: var jade = require('jade'); var options = { locals: { users: { tj: { age: 23, email: 'tj@vision-media.ca', isA: 'human' }, tobi: { age: 1, email:

nodejs jade conditional extend

半腔热情 提交于 2019-11-30 02:57:16
问题 I would like to make my Jade page extend different layouts, depending on a condition. So my code looks like this: if myConditionVariable extends layout1 else extends layout2 block content p here goes my content! Now this does not work. It seems as if only the last defined extends will be respected, regardless of the conditions. I also tried dynamically defining the templatename, such as extends myLayoutNameVariable and set the myLayoutNameVariable in different manners (express dynamic helper

Multiple Lines for Long Attribute Value in Jade / Pug

蓝咒 提交于 2019-11-30 02:42:36
How do we write a long attribute value over multiple lines in Jade / Pug? SVG paths tend to be really long. We want to write an attribute value over multiple lines to help with readability. For example, Mozilla's tutorial written in HTML is easy to read. Any way to change this: h3 Arcs svg(width="320px", height="320px") path(d="M10 315 L 110 215 A 30 50 0 0 1 162.55 162.45 L 172.55 152.45 A 30 50 -45 0 1 215.1 109.9 L 315 10", stroke="black", fill="green", stroke-width="2", fill-opacity="0.5") into something like this: h3 Arcs svg(width="320px", height="320px") path(d="M10 315 " + "L 110 215 "

How to compile jade templates in to JavaScript functions to use them on client side?

风流意气都作罢 提交于 2019-11-30 01:55:57
问题 I want to use compiled jade templates on client side. How should I compile them to get javascript files ? https://github.com/visionmedia/jade 回答1: Look for proposed solutions in the jade issue 149 discussion. Unfortunately, there is no built-in ready for use option, as I know. 回答2: Yes you can! https://github.com/techpines/asset-rack#jadeasset I just open sourced "asset-rack", a nodejs project that can can precompile jade templates and serve them in the browser as javascript functions. This

Jade checkbox checked attribute unchecked based on conditional (if)

牧云@^-^@ 提交于 2019-11-30 01:42:57
How do I get jade to render the checked attribute of a checkbox based on a conditional? Like these two versions of the HTML checkbox tag: This seems to be the ONLY valid version of unchecked: > <input type="checkbox" name="vehicle" value="Bike"> While this is checked: > <input type="checkbox" name="vehicle" value="Car" checked="checked"> Here is what I've tried so far: This Jade is fine: input(type="checkbox", name="completed", checked=(true===true ? "checked" : "")).checkbox because it renders this: <input type="checkbox" name="completed" checked="checked" class="checkbox"> but this Jade is

Jade templating in Meteor

廉价感情. 提交于 2019-11-30 01:15:05
In the Meteor FAQs http://meteor.com/faq/how-do-i-package-a-new-templating-system there is some information about adding a different (than the default Handlebars) templating system. Jade is the only other example explicitly called out elsewhere in the docs. So is somebody already working on Jade? If not, is it feasible for me to start? Or is it still too early? e.g. : The package API is rapidly changing and isn't documented, so you can't make your own packages just yet. Coming soon. I've been trying to love Handlebars in my current Ember.js project, but for me nothing is as elegant as Jade. We