玉有条件的意外令牌非法

时间:2015-07-19 07:35:43

标签: pug

我用express,node和jade构建一个小应用程序。我试图让这个工作:

var Adapter = require('socket.io-adapter');

module.exports = CustomAdapter;

function CustomAdapter(nsp) {
  Adapter.call(this, nsp);
};

CustomAdapter.prototype = Object.create(Adapter.prototype);
CustomAdapter.prototype.constructor = CustomAdapter;

CustomAdapter.prototype.broadcast = function(packet, opts){
  var rooms = opts.rooms || [];
  var except = opts.except || [];
  var flags = opts.flags || {};
  var packetOpts = {
    preEncoded: true,
    volatile: flags.volatile,
    compress: flags.compress
  };
  var ids = {};
  var self = this;
  var socket;

  packet.nsp = this.nsp.name;
  this.encoder.encode(packet, function(encodedPackets) {
    if (rooms.length) {
      for (var i = 0; i < rooms.length; i++) {
        var room = self.rooms[rooms[i]];
        if (!room) continue;
        for (var id in room) {
          if (room.hasOwnProperty(id)) {
            if (~except.indexOf(id)) continue;
            socket = self.nsp.connected[id];
            if (socket) {
              ids[id] = ids[id] || 0;
              if(++ids[id] === rooms.length){
                socket.packet(encodedPackets, packetOpts);
              }
            }
          }
        }
      }
    } else {
      for (var id in self.sids) {
        if (self.sids.hasOwnProperty(id)) {
          if (~except.indexOf(id)) continue;
          socket = self.nsp.connected[id];
          if (socket) socket.packet(encodedPackets, packetOpts);
        }
      }
    }
  });
};

我尝试运行上面的内容并在行上发出错误:

var io = require('socket.io')(server, {
  adapter: require('./CustomAdapter')
});

Function()

处的意外标记ILLEGAL

有关正在发生的事情的任何想法?顺便说一句,一切都是缩进的。谢谢!

1 个答案:

答案 0 :(得分:1)

变化

unless #{user.email} == "someemail@gmail.com"

unless user.email == "someemail@gmail.com"

运行它

$ cat test.jade && jade test.jade && cat test.html
- var user={fullName:'me',email:'me@here.org'}
if user
  p Welcome, #{user.fullName} 
  p
  .div(style={position: 'absolute', right: '150px', top: '75px'})
    unless user.email == "someemail@gmail.com"
      a.btn.btn-primary(href="/upload") Upload New Schedule
      br
    br
    a.btn.btn-primary(href="/logout") Logout
  rendered test.html

<p>Welcome, me </p><p></p><div style="position:absolute;right:150px;top:75px" class="div"><a href="/upload" class="btn btn-primary">Upload New Schedule</a><br/><br/><a href="/logout" class="btn btn-primary">Logout</a></div>

您必须确保定义了用户,否则将始终呈现条件部分