Tag: coffeescript

CoffeeScript覆盖基types,更改值

我有一个重写CoffeeScript中的主要types的函数,但是这个函数的返回值,我想改变自己。 String::replaceAll = (what, to) -> regexPattern = new RegExp(what, "g") this.replace regexPattern, to 现在我必须这样使用它: test = test.replaceAll "sth", "sth2" 我想用这种方式来使用它: test.replaceAll "sth", "sth2" # only, without assigning (this = this.replace regexPattern,为#不起作用)

当我想运行Coffeescript cake命令时,为什么最终运行CakePHP的cake命令?

我正在尝试在Ubuntu 12.04上首次运行给givenwhenthen节点模块,并按照其运行故事标题下列出的设置说明进行操作。 我已经在/~/node_modules/givenwhenthen/examples/添加了任务test:acceptance我的cakefile,如下所示: task 'test:acceptance', 'Runs the acceptance tests', (options = {}) -> givenwhenthen.runner.runStories(options) 当我从同一个目录运行cake时,我得到如下path: CakePHP v2.2.2 Console App: examples Path: /home/kyoob/node_modules/givenwhenthen/examples/ Root: /home/kyoob/node_modules/givnwhenthen Core: /usr/share/php/cakephp/lib 我没有看到test:acceptance “可用壳”下的test:acceptance ,我根本没有看到“可用任务”部分。 应该在这里列出吗? 当我运行cake test:acceptance从这个目录cake test:acceptance这里是我得到的消息: Shell class Test:acceptanceShell could not be found. #0 /usr/share/php/cakephp/lib/Cake/Console/ShellDispatcher.php(191): ShellDispatcher->_getShell('test:acceptance') #1 /usr/share/php/cakephp/lib/Cake/Console/ShellDispatcher.php(69): ShellDispatcher->dispatch() #2 /usr/share/php/cakephp/lib/Cake/Console/cake.php(43): ShellDispatcher::run(Array) #3 {main} 我已经尝试了和没有sudo相同的效果。 我是编译CoffeeScript文件的新手,所以我担心这是我的一个菜鸟错误。 我想从错误的目录编译? 我错过了什么明显的东西?

templateDatavariables返回未定义的帮助函数(docpad.coffeeconfiguration文件)

这是我的configuration文件 。 docpadConfig = { templateData: site: title: 'hello docpad' getTitle: -> @site.title getString: -> 'just a string' } # Export the DocPad Configuration module.exports = docpadConfig 当我做title= site.title时候,从一个玉石的布局,它呈现的确定。 当我尝试调用helper函数title= getTitle() ,控制台输出: error: An error occured: ReferenceError: /Volumes/Data/project/am/lab/docpad/hello_docpad/src/layouts/default.html.jade:21 19| 20| //- Our site title and description > 21| title= getTitle() 22| 23| //- Output DocPad […]

如何构build一个Cakefile来运行node.js

目前,我正在通过“ 在24小时内自学Node.js ”的方式,我希望尽可能在CoffeeScript而不是JavaScript中执行尽可能多的代码。 安装coffee-script和node 。 我还是新来的蛋糕开发系统 – 有人可以指示我如何把Cakefile加载到一个简单的服务器,如server.coffee为了运行演示代码?

使用vim和CoffeeScript进行节点检查

我在npm的帮助下按以下方式安装了node-inspector: npm install –prefix /home/uqmlore1/apps/node_modules -g node-inspector 现在,我只是想知道这个插件是否适用于节点检查器。 如果是的话,可以把以下命令集成到Vim中? node-inspector & coffee –nodejs –debug app.coffee & google-chrome http://127.0.0.1:8080/debug?port=5858 & google-chrome http://127.0.0.1:3000 &

用Node.js + CoffeeScript + MySQL做几个相关的插入

我有一个函数,它将一个URL和一个标题插入到我的数据库的表“url”中。 这个函数获取MySQL分配的id。 我会在下面解释我需要什么。 # Creates a URL in the database. create_url = (url, title) -> connection.connect print_err connection.query "INSERT IGNORE INTO url SET ?", {urlName: url, urlTitle: title}, (err, result) -> throw err if err inserted_id = result.insertId 在我调用create_url之后,我想调用我的另一个函数,它插入到表'dailyUrl'中。 create_daily_url = (url) -> connection.query "INSERT IGNORE INTO dailyUrl SET ?", {url: url}, (err, result) -> […]

Node.js`request.get`:将主体存储在variables中

我是Node.js的新手,非常抱歉,可能是一个愚蠢的问题… 这是我的代码: #!/usr/bin/env coffee –bare # 3rd party request = require('request') request.defaults({'encoding': 'utf8'}) module.exports.fetchDepartments = fetchDepartments fetchDepartments = (url) -> _body = '' getHandler = (error, response, body) -> util.debug "HTTP response code: #{response.statusCode}" if error util.error error else _body = body request.get(url, getHandler) _body console.log fetchDepartments('https://ntst.umd.edu/soc/') 控制台正在打印对util.debug()的调用,但似乎_body仍然是一个空string。 如何从HTTP响应存储HTML?!?

更新:用户错误 – TYPO! grunt-contrib-coffee错误查找文件并写入目的地

在我的Gruntfile.js中,我将咖啡任务configuration为如此,并在src/目录中存在一个script.coffee文件: coffee: { dist: { files: [{ /* FIX: exapand: true, */ expand: true, cwd: 'src/', src: '**/*.coffee', dest: 'lib/', ext: '.js' }] } } 运行grunt coffee ,出现以下错误 : Running "coffee:dist" (coffee) task >> Source file "script.coffee" not found. >> Destination (lib/) not written because compiled files were empty. script.coffee的内容是testingcoffeescriptconfiguration的一些代码,并且在我从命令行运行coffee -c script.coffee时完美地编译。 script.coffeelogging: # A […]

Node.js:如何在ECT模板中打印URL的一部分

下面是app.js. ECT文件是基于path加载的。 var http = require('http'); var ECT = require('ect'); var renderer = ECT({ root : __dirname + '/views' }); var data = { title : 'Hello, world!', size : 'XXL' }; var product = renderer.render('product.ect', data); var about = renderer.render('about.ect', data); var anypath = renderer.render('anypath.ect', data); var server = http.createServer(function(req, res) { var params; […]

在Node中parsingJSON API

我正在为外部API构build一个节点包装器,并且在parsingJSON响应时遇到问题。 以下代码提出请求: https = require "https" querystring = require "querystring" API_HOST = "api.lob.com" API_PATH = "/v1" startResponseHandler = (req, cb) -> if typeof cb isnt "function" then console.log "Error: callback needs to be a function!" req.on 'response', (res) -> response = '' res.setEncoding 'utf8' res.on 'data', (stream) -> response += stream res.on 'end', () -> […]