【发布时间】:2015-08-21 00:20:40
【问题描述】:
我正在使用 Meteor 制作游戏,我正在尝试使用 S-Grid 创建一个随机大小的网格,我在其中获取 Javascript 中的 columns 变量(实际上是咖啡脚本)并在 Stylus 中访问它们。
我的 .coffee 文件位于 lib 文件夹中,而我的 main.styl 文件位于客户端文件夹中。
random = (num) ->
Math.floor Math.random() * num + 1
@cols = random()
@rows = random()
stylus = require('stylus')
stylus(str)
.set('filename', '../client/main.styl')
.define 'cols', stylus.nodes.unit(@cols)
.define 'rows', stylus.nodes.unit(@rows)
.render (err, css) ->
if (err)
throw err
console.log(css)
return
我在构建应用程序时收到此错误:
node_modules/stylus/node_modules/glob/node_modules/minimatch/node_modules/lru-cache/test/memory-leak.js:1:15: Unexpected token ILLEGAL
node_modules/stylus/node_modules/source-map/test/run-tests.js:1:15: Unexpected token ILLEGAL
node_modules\stylus\node_modules\sax\examples\test.html:1: Can't set DOCTYPE here. (Meteor sets <!DOCTYPE html> for you)
node_modules\stylus\node_modules\sax\LICENSE-W3C.html:1: Can't set DOCTYPE here. (Meteor sets <!DOCTYPE html> for you)
The pure Stylus grid works fine but i can't seem to be able to set the columns through Javascript.
我这样定义我的网格
.grid
grid()
.box
cells(1, @cols)
其中@cols 是来自 javascript 变量的随机数。如果我使用通用数字或使用 Stylus 生成随机数,它可以正常工作,但我需要 JS 变量(我将它用于其他事情)。我不知道如何在 .styl 中制作并在 JS 中访问它。
【问题讨论】:
标签: javascript meteor coffeescript stylus