pug

Compile mixin to JS in JADE

风格不统一 提交于 2019-12-11 10:27:05
问题 When trying to compile this JADE mixin (from their official docs) mixin pets(pets) ul.pets - each pet in pets li= pet into JavaScript using jade --client --no-debug pets.jade I get this output, which, as far as I can tell, doesn't actually do anything: function template(locals) { var buf = []; var jade_mixins = {}; var jade_interp; ;return buf.join(""); } Is this a bug in the JADE compiler or am I doing something wrong? I was expecting it to compile it into something like function pets(pets)

transfer data from jade to jquery and vice versa

不打扰是莪最后的温柔 提交于 2019-12-11 10:18:50
问题 My index.js file: res.render('index', {data:{'hello':'world'}}); my jade file: p #{data} script(src="/javascripts/app.js") This prints the value json object. now on my app.js file console.log(data); gives an error saying data is undefined. How can I access the data which was passed from my index.js file in my javascript file. 回答1: In your index.js file: res.render('index', {data:JSON.stringify({'hello':'world'})}); in your Jade Template: script(type="text/javascript"). var data = !{data};

Warning: Unexpected block “scripts” Jade

谁说我不能喝 提交于 2019-12-11 09:57:40
问题 I wrote a jade file as shown below: extends layout block content h1= title p Welcome 123 to #{title} block scripts script(src='/socket.io/socket.io.js') script(src='/javascripts/client.js') However when I run I get the following Warning: Warning: Unexpected block "scripts" This block is never used. This warning will be an error in v2.0.0 My Package.json file has jade version ~1.9.0 However this works when Jade version is ~1.8.2 What could be the problem? 回答1: You should add the line: block

Warning: missing space before text for line 20 of jade file

核能气质少年 提交于 2019-12-11 09:51:43
问题 I get Warning: missing space before text for line 20 of jade file for this code: Any ideas? doctype html html(ng-app="fooApp") head title Foo script(language='javascript', src='bower_components/angular/angular.js', type='text/javascript') script(language='javascript', src='bower_components/requirejs/require.js', type='text/javascript', data-main='js/Main.js') script(language='javascript', src='http://cdn.peerjs.com/0.3/peer.js', type='text/javascript') script(language='javascript', src='bower

Variables, global objects, and console.log in jade

半世苍凉 提交于 2019-12-11 09:08:05
问题 I've created an app with the express framework, which comes with jade as its templating engine. While playing around with jade, I've set up what I feel to be a simple test: In Node I am passing an object to the jade template on render res.render('index', { title: 'Express', docs:"is jade cool?"}); , and in the template I'm trying to call the values like so: h1= title p Hi! p Welcome to #{title} p #{docs} - console.log(docs) script(type='text/javascript'). console.log(docs); What I've found is

Express / Jade / Pug: Calling a javascript object's functions

浪尽此生 提交于 2019-12-11 08:05:17
问题 While I can pass an object's data, I don't know how to pass/call an object's functions. route.js: router.get('/', function(req, res, next) { let test = {}; // passing an object called test test.hello = function() { //the test object has a method I want to console.log('hello'); //call on the browser } res.render('home.jade', { test:test }); On the .jade page: //- let test = !{test}; //renders as [object Object] let test = !{JSON.stringify(test, null, 4)}; //renders empty obj test.hello();

jQuery toggleClass only works for a split second, then it reverts back to how it previously was

守給你的承諾、 提交于 2019-12-11 06:17:07
问题 So this is my first question ever on stackoverflow, sorry if I ask this poorly or have failed to find the answer elsewhere. I am using a simple toggleClass jQuery function to add a class called .slide-out that gives the whole body a left: 30% value. If I manually add the class it works properly. But if I use the toggleClass function to add the class it slides the whole body over 30% just like I expected but immediately moves the body back to its normal position. It sort of flashes and appears

Pug template isn't rendering raw HTML passed to it

假装没事ソ 提交于 2019-12-11 04:39:02
问题 I have a pug template that is rendered and shown to the user when a button is clicked on my web page. I have an issue with pug rendering HTML tags as part raw text instead of parsing the text and adding it as a DOM node. My pug template looks like: p #{object.property} so trying to interpolate an HTML string into the template. The property contains an HTML string that looks like: <p>Here is some text I'm trying to render</p> I have tried just using #{object.property} to strange rendering

Workaround to dynamic includes in Pug/Jade

别等时光非礼了梦想. 提交于 2019-12-11 04:26:49
问题 I understand that Pug does not support dynamic includes or extends in templates. Ie extend path/to/template works but not extend #{dynamic_path_to_template} Is there a workaround (however convoluted) that will allow the same goal of modifying the template used by a view at runtime Context : My use case is that I am developing an npm module and the template being used to extend other views is located inside the module. After the module is published and installed, the path will be defined (ie.

socket.io and express server not receiving emit from client

好久不见. 提交于 2019-12-11 04:18:35
问题 The console logs "connection to socket made," so it seems to be connecting, but no events seem to be triggered, even on 'disconnect' inside io.on in the server. "socket.on" doesn't seem to be working SERVER SIDE var server = app.listen(app.get('port'), () => { console.log('%s App is running at http://localhost:%d in %s mode', chalk.green('✓'), app.get('port'), app.get('env')); console.log(' Press CTRL-C to stop\n'); }); var io = socket(server); io.on('connection', function(socket){ console