Tag: node.js

清单中的ExecJS :: RuntimeError索引错误

当我打开本地主机时 ,我收到此ExecJS错误消息 ,我不知道为什么,一些帮助会很惊人。 我在我的localhost上得到了这个 显示/…/conektec/app/views/layouts/application.html.erb,其中第6行引发: SyntaxError:[stdin]:6:16:意外的换行符(在/…/conektec/app/assets/javascripts/orders.js.coffee中) ActionView::Template::Error (SyntaxError: [stdin]:2:73: unmatched ) (in /Users/hbendev/startups/conektec/conektec/app/assets/javascripts/orders.js.coffee)): 3: 4: Conektec 5: true %> 6: true %> 7: 8: 9: “stripe-key”, :content => ENV[“STRIPE_PUBLIC_KEY”] %> 这是我的orders.js.coffee文件 jQuery -> Stripe.setPublishableKey($(‘meta[name=”stripe-key”]’).attr(‘content’)) payment.setupForm() payment = setupForm: -> $(‘#new_order’).submit -> $(‘input[type=submit]’).attr(‘disabled’, true) Stripe.card.createToken($(‘#new_order’), payment.handleStripeResponse) false handleStripeResponse: (status, response) -> if status == 200 alert(response.id) […]

带有node.js的Ruby子进程

我正在尝试将ruby实例作为我的节点程序的子进程启动。 事实上,一切都很好,但我无法与ruby的STDIN和STDOUT交互。 (当然ruby程序在我的终端上使用我的键盘输入) 所以这是一个我想要工作的简化代码…… simpleproc.js var util = require(‘util’), spawn = require(‘child_process’).spawn, ruby = spawn(‘ruby’, [__dirname + ‘/process.rb’]); ruby.stdout.on(‘data’, function (data) { console.log(‘stdout: ‘ + data); }); ruby.stderr.on(‘data’, function (data) { console.log(‘stderr: ‘ + data); }); ruby.on(‘exit’, function (code) { console.log(‘child process exited with code ‘ + code); }); ruby.stdin.write(“ping\n”); process.rb f = File.new(“process.log”, “w”) […]

使用Watchr自动连接文件

我有一堆JS文件,我分开了,但想自动连接(所以我没有在HTML中定义一堆文件)。 现在,我从Twitter Bootstrap复制了命令。 Makefile文件: scripts: cat scripts/*.js > public/scripts/scripts.js watchScripts: watchr -e “watch(‘scripts/.*\.js’) {system ‘make scripts’}” 但是,我发现watchr非常不一致(在Mac OS X 10.8上) 有时当我保存js文件时,它不会运行make scripts 。 其他时候,确实如此。 有一次,它只是在一次保存后继续运行make scripts 。 有时,它会在最后一次保存后几秒钟运行命令。 难道我做错了什么? 我正在使用node.js而不是Ruby ,所以有任何node.js命令行替代方案吗? 当我尝试在Bootstrap中make watch时,似乎会发生同样的问题。 旁边的问题:我有另一个观察命令: stylus -w -u nib styles/styles.styl -o public/styles 如何在单个Makefile命令中运行两个watch命令? IE make watch将同时.styl文件进行编译,并将.js文件连接起来。 现在我为每个手表命令打开两个终端,但我更喜欢一个。

将方法/变量注入Javascript范围

我希望能够在文件开头使用我没有要求的方法()。 像这样的东西: var contact = require(‘contact’); person = contact.create({ ‘name’: createName() }); 在这里我想使用函数createName(),即使我没有明确地要求它()。 以下是Ruby中的示例: # By extending a class it gets the class methods from the parent: class Section < ActiveRecord::Base belongs_to :document has_many :paragraphs end # By using a block and executing it in an object containing those methods used namespace "admin" do resources […]

为什么一些正则表达式引擎在单个输入字符串中匹配。*两次?

许多正则表达式引擎在单行字符串中匹配.* 两次 ,例如,在执行基于正则表达式的字符串替换时: 根据定义,第一个匹配是整个(单行)字符串,如预期的那样。 在许多引擎中有第二个匹配,即空字符串 ; 也就是说,即使第一个匹配消耗了整个输入字符串, .* 再次匹配,然后匹配输入字符串末尾的空字符串。 注意:要确保只找到一个匹配项,请使用^.* 我的问题是: 这种行为有充分的理由吗? 一旦输入字符串被完全消耗,我就不会期望再次尝试找到匹配项。 除了试验和错误之外,您是否可以从文档/正则表达式方言/标准中收集哪些引擎表现出这种行为? 更新 : revo的有用答案解释了当前行为的方式; 至于潜在的原因 ,请参阅此相关问题 。 表现出行为的语言/平台: # .NET, via PowerShell (behavior also applies to the -replace operator) PS> [regex]::Replace(‘a’, ‘.*’, ‘[$&]’ [a][] # !! Note the *2* matches, first the whole string, then the empty string # Node.js $ node […]