我正在使用 Yeoman 创建一个生成器,它又使用 underscore.js 模板。
在给定的文件中,我有以下代码:
var
<% _.each(requires, function(require) { %>
<% if(require.shouldApply) { %>
<%= _.camelize(require.name) %> = require('<%= require.name %>'),
<% } %>
<% }); %>
mongoose = require('mongoose'),
Schema = mongoose.Schema;
鉴于require.shouldApply
有时是错误的,我不希望产生空行。
因此,例如,对于输入,requires: [{shouldApply: false, name: 'zoo'}, {shouldApply: false, name: 'foo'}, {shouldApply: true, name: 'bar'}]
我得到以下信息:
var
zoo = require('zoo'), //note that the line below is blank
bar = require('bar'), //I don't want the blank line above
mongoose = require('mongoose'),
Schema = mongoose.Schema;
有谁知道如何防止 underscore.js 模板创建这些不需要的空行?