小编mat*_*ers的帖子

使用ExecJS从Rails应用程序调用Node.js脚本

我有一个需要运行节点脚本的rails应用程序.我想使用ExecJS gem是从rails应用程序运行js最干净的方法.然而,到目前为止,ExecJS使用起来非常令人沮丧.

这是我需要运行的脚本:

// Generated by CoffeeScript 1.7.1
(function() {
  var PDFDocument, doc, fs;
  fs = require("fs");
  PDFDocument = require('pdfkit');
  doc = new PDFDocument;
  doc.pipe(fs.createWriteStream('output.pdf'));
  doc.addPage().fontSize(25).text('Here is some vector graphics...', 100, 100);
  doc.save().moveTo(100, 150).lineTo(100, 250).lineTo(200, 250).fill("#FF3300");
  doc.scale(0.6).translate(470, -380).path('M 250,75 L 323,301 131,161 369,161 177,301 z').fill('red', 'even-odd').restore();
  doc.addPage().fillColor("blue").text('Here is a link!', 100, 100).underline(100, 100, 160, 27, {
    color: "#0000FF"
  }).link(100, 100, 160, 27, 'http://google.com/');
  doc.end();
}).call(this)
Run Code Online (Sandbox Code Playgroud)

从我的rails控制台,我试试这个:

[2] pry(main)> file = File.open('test.js').read
[3] pry(main)> ExecJS.eval(file)
ExecJS::ProgramError: TypeError: undefined is not a …
Run Code Online (Sandbox Code Playgroud)

javascript ruby ruby-on-rails node.js execjs

11
推荐指数
1
解决办法
2986
查看次数

什么时候需要Scala Semicolons

我被困在一台锁定的电脑上工作.但我正在尝试练习我的scala.我正在使用Ideone.com,因为我甚至无法安装scalac ...

无论如何这不是编译:

class DPt(var name: String, var x: Double, var y: Double){

        def print = println("DPt; name: " + name + " x: " + x + " y: " + y)
}


object Main {
  def main(args: Array[String]) {
        val pt0 = new DPt("Joe", 1.0, 1.0)
        println("checking generated accessor: " + pt0.x)
        pt0 print
        pt0.x_=(3.0)
        pt0 print
  }
}
Run Code Online (Sandbox Code Playgroud)

我从Ideone.com scala编译器收到此消息:

Main.scala:12: error: Unit does not take parameters
    pt0 print
            ^
one error found
spoj: The program compiled …
Run Code Online (Sandbox Code Playgroud)

jvm scala postfix-notation

3
推荐指数
1
解决办法
2645
查看次数