Coffeebeans for Rails 3.1

레일즈 개발환경은 참으로 살아 숨쉬는 그야말로 개발자로 하여금 지속적으로 공부하게 만드는 것 같다.

레일즈는 개발자 환경을 향상시키기 위해서 모든 역량을 다함에 틀림없다.

아마도 레일즈 3.1 베타1 버젼에는 누락되었지만, 3.1 릴리스 버젼에서는 틀림없이 추가될 것으로 생각된다. Coffee-script와 Coffeebeans. 아예 커피와 이름을 연관지으면서 그들의 개발언어의 연계성을 멋지게 만들어 가고 있다.

어쨌던 레일즈는 점점 더 재밌어 진다.

Rails 3.1 has made quite a splash with its inclusion of CoffeeScript. I for one am very excited about being able to write JavaScript in an easier and more beautiful way. However, when CoffeeScript was added to Rails 3.1 they forgot one very important part, the ability to use it when responding to JavaScript (JS) requests!

In Rails 3.1 it’s incredibly easy to build your application’s JavaScript using CoffeeScript, however if you fire off an AJAX request to your application you can only write your response using regular JavaScript and not CoffeeScript, at least until CoffeeBeans came along.

참조 : https://github.com/markbates/coffeebeans

Installation

Installing CoffeeBeans is simple. In your Rails 3.x project (yes, this works in Rails 3.0.x as well as Rails 3.1) add the following to your Gemfile:

gem 'coffeebeans'

Then run:

$ bundle install

That’s it! CoffeeBeans is now installed and ready to help you make the most of CoffeeScript in your Rails app. Enjoy!

Usage

Usage of CoffeeBeans is incredibly simple. Let’s say you want to respond to a JavaScript (JS) request using CoffeeScript just name your view something like this:

app/views/users/index.js.coffee

That’s it! You’re done. Now you can use CoffeeScript (and ERB) in that file. Nothing else special to do, tweak or change.

But Wait, There’s More!

Act now and we’ll throw in two view helper methods to help make it easy for you to write CoffeeScript in your views as well:

coffee_script_tag

The coffee_script_tag helper method will compile your CoffeeScript code and place it between script tags:

alert 'coffee script is awesome!'

Will generate:

(function() { alert('coffee script is awesome!'); }).call(this);

coffee_script

Alternatively, if you want to place/compile CoffeeScript between script tags that are already on your page, then you can simply use the coffee_script helper to do that.

alert 'coffee script is really awesome!'

Will generate:

(function() {

   alert('coffee script is really awesome!');

}).call(this);

글쓴이: 최효성

외과전문의,웹프로그래밍,컴퓨터 일러스트레이션 / Surgeon, Medical Illustration, Web Programmer

답글 남기기

아래 항목을 채우거나 오른쪽 아이콘 중 하나를 클릭하여 로그 인 하세요:

WordPress.com 로고

WordPress.com의 계정을 사용하여 댓글을 남깁니다. 로그아웃 / 변경 )

Twitter 사진

Twitter의 계정을 사용하여 댓글을 남깁니다. 로그아웃 / 변경 )

Facebook 사진

Facebook의 계정을 사용하여 댓글을 남깁니다. 로그아웃 / 변경 )

Google+ photo

Google+의 계정을 사용하여 댓글을 남깁니다. 로그아웃 / 변경 )

%s에 연결하는 중