Sha256: 21bcbfd952fe8e3104a2ef0384ee0a210978d59bb48c3f1b894e4bdfe1ea1934
Contents?: true
Size: 1.96 KB
Versions: 1
Compression:
Stored size: 1.96 KB
Contents
# render_execjs # Render executable JavaScript within Rails. ## Installation ## Add `render_execjs` to your `Gemfile` gem 'render_execjs', '~> 0.0.1' # gem 'coffee-script' # Uncomment this line if you'd like to render executable CoffeeScript Run the `render_execjs:install` generator to create the optional configuration initializer file rails generate render_execjs:install ## Usage ## In your controller: render execjs: "return 'some JavaScript';" It also supports CoffeeScript! render execcs: "return 'some CoffeeScript'" That's it! Note that it will render whatever is returned from JavaScript. ## Why would I want to render JavaScript from Rails? ## Make sure that you're logged into your Twitter, now click on this link: [http://twitter.com/tazsingh](http://twitter.com/tazsingh) Notice how it loads your Twitter first, then the page that you've requested? It has to initialize the JavaScript environment before it can render the page you've requested. A solution to this, in Rails, is to use something like Mustache to render the same structure but with different logic; thus giving the browser the page you've requested as the base to initialize from. However this means duplication of logic. Wouldn't it be nice to write logic and structure once, using a pretty templating system, that works on both client and server? This is the problem that `render_execjs` is attempting to solve. Note that this is an experiment and suggestions are welcome! ## Testing ## `render_execjs` currently uses [Appraisal](https://github.com/thoughtbot/appraisal) to test against multiple versions of Rails. Install it with: `rake appraisal:install` Now you can run: rake appraisal spec # To run specs against both Rails 3.1 and 3.2 rake appraisal:rails31 spec # To test against Rails 3.1 rake appraisal:rails32 spec # To test against Rails 3.2 Note that the testing system is currently undergoing an overhaul, so the above will change. ## License ## MIT
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
render_execjs-0.0.2 | README.md |