如何在没有 Rails 的情况下创建简单的 CoffeeScript 示例

发布于 2024-11-30 03:55:24 字数 638 浏览 0 评论 0原文

我是咖啡脚本的新手。我在 Railscasts.com 上看到了一个 CoffeeScript 视频。从那一集我了解了如何将普通的Js和Jquery转换为coffeescript代码以及coffeescript的用法。

我正在尝试创建一个没有 Rails 的 CoffeeScript 示例。我浏览了 Coffeescript 网站。他们首先安装 Node.js。我尝试在windows和ubuntu中安装node.js,但失败了。我按照这个网站的说明进行操作:

http://howtonode.org/how-to- install-nodejs#ubuntu

对于 ubuntu,当我执行以下命令时,我收到“bash:./configure?:没有这样的文件或目录”错误

./configure

有人可以帮助我创建没有rails的简单coffescript示例吗?

另一件事 - 在 Mac 中“通过 homebrew 的帮助,我可以通过编译和显示 Js 窗口看到 coffescript 代码的编译 js”。 Windows 和 ubuntu 上有可用的选项吗?

I am new to coffeescript. I saw a coffeescript video in Rails casts.com. From that episode I understand how to convert the normal Js and Jquery to coffeescript code and the usage of coffeescript.

I am trying to create a coffeescript example without rails. I wetn through the coffeescript site. They first install Node.js. I tried to install node.js in windows and ubuntu, but I had failures. I followed the instruction as per this site:

http://howtonode.org/how-to-install-nodejs#ubuntu

For ubuntu I got "bash: ./configure?: No such file or directory" error when I execute the following command

./configure

Can anyone help me to create simple coffescript example without rails?

One more thing - In Mac "By the help of homebrew I can see the compiled js of coffescript code through compiled and Display Js window". Are there any options available in windows and ubuntu?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

哥,最终变帅啦 2024-12-07 03:55:24

我敢打赌,在 Ubuntu 上安装 Node.js 最简单的方法是通过 APT:

$ sudo apt-get install nodejs

它可能会得到一些过时的版本,但对于某些测试来说已经足够了。

如果您更喜欢最新版本(这是一个合理的偏好),我敢打赌从 dist 包安装 Node.js 会更容易。只需将其复制并粘贴到终端上即可:

wget http://nodejs.org/dist/node-v0.5.0.tar.gz && \
tar zvxf node-v0.5.0.tar.gz && \
cd node-v0.5.0 && \
./configure && \
make && \
sudo make install

此行将:

  • 使用 wget http://nodejs.org/dist/node-v0.5.0.tar.gz
  • 使用tar zvxf解压下载的源代码node-v0.5.0.tar.gz
  • 使用 cd node-v0.5.0 进入源代码,使用
  • ./configure 设置构建参数,
  • 有效构建使用 make 执行 Node.js
  • 在您的路径中使用 sudo make install 安装构建的 Node.js

&& 表示“执行下一个如果前一个命令成功则命令”(例如wget http://nodejs.org/dist/node-v0.5.0 .tar.gz && tar zvxf node-v0.5.0.tar.gz 表示我们将使用 wget 下载该软件包,并且 成功后,我们将使用 tar 解压下载文件。反斜杠 (\) 允许我们将所有一系列命令分解为多行,因为默认情况下,我们会有一大行:

wget http://nodejs.org/dist/node-v0.5.0.tar.gz && tar zvxf node-v0.5.0.tar.gz && cd node-v0.5.0 && ./configure && make &&  sudo make install

然后,您可以安装 npm 使用这个简单的命令,可以在自己的 npm github 页面 中找到:

$ curl http://npmjs.org/install.sh | sudo sh

使用npm,它将安装 Coffee 太容易了,正如您在 CoffeeScript 页面:

$ npm install coffee-script

现在,只需运行您的测试:

$ coffee
coffee> a = key: 'value'
{ key: 'value' }
coffee> a.key
'value'

看起来工作量很大吗?您可以在语言页面中尝试 CoffeeScript。只需单击“尝试 CoffeeScript”,就会出现一个控制台。

I would bet the easiest way to install Node.js on Ubuntu is through APT:

$ sudo apt-get install nodejs

It probably will get some outdated version but it can be enough for some tests.

If you prefer the latest version (which is a reasonable preference), I bet it would be easier to install Node.js from the dist package. Just copy and paste this on terminal:

wget http://nodejs.org/dist/node-v0.5.0.tar.gz && \
tar zvxf node-v0.5.0.tar.gz && \
cd node-v0.5.0 && \
./configure && \
make && \
sudo make install

This line will:

  • download the latest Node.js source code with wget http://nodejs.org/dist/node-v0.5.0.tar.gz
  • uncompress the downloaded source code with tar zvxf node-v0.5.0.tar.gz
  • enter into the source code with cd node-v0.5.0
  • set the build parameters with ./configure
  • effectively build the Node.js executable with make
  • install the built Node.js in your path with sudo make install

The && means "execute the next command if the previous command succeeds" (for example wget http://nodejs.org/dist/node-v0.5.0.tar.gz && tar zvxf node-v0.5.0.tar.gz means that we will download the package with wget and iff the download succeeds we will unpack the download file with tar. The backslashes (\) are here for allowing us to break all the series of commands in more than one line because, by default, we would have a big line:

wget http://nodejs.org/dist/node-v0.5.0.tar.gz && tar zvxf node-v0.5.0.tar.gz && cd node-v0.5.0 && ./configure && make &&  sudo make install

Then, you can install npm with this simple command, found in the own npm github page:

$ curl http://npmjs.org/install.sh | sudo sh

With npm, it will be too easy to install coffee, as you can see in the CoffeeScript page:

$ npm install coffee-script

Now, just run your tests:

$ coffee
coffee> a = key: 'value'
{ key: 'value' }
coffee> a.key
'value'

Does it look like to much work? You can try CoffeeScript in the language page. Just click in "Try CoffeeScript" and a console will appear to you.

爱本泡沫多脆弱 2024-12-07 03:55:24

出于测试和演示的目的,直接在浏览器中编译 CoffeeScript 可能就足够了。您可以将 CoffeeScript 编译器和您的代码包含在标签中。

但这种方法效率不高,所以请使用它来玩一玩。

请参阅本节了解如何设置:

"text/coffeescript" 脚本标签

祝你好运!

For testing and demo purposes it may be sufficient to have your CoffeeScript compiled directly in browser. You can include the CoffeeScript compiler and your code in a tag.

This method is not efficient though so please use it for playing around.

Please see this section on how to set things up:

"text/coffeescript" Script Tags

Good luck!

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文