public
Fork of jessesielaff/red
Description: Red writes like Ruby and runs like JavaScript.
Homepage:
Clone URL: git://github.com/julius/red.git
red /
name age message
file .gitignore Tue Aug 18 06:23:57 -0700 2009 Added nbproject [Hendrik]
file License.txt Sun Oct 12 13:48:16 -0700 2008 Version 4.0 released. [jessesielaff]
file Manifest.txt Fri Nov 07 23:05:57 -0800 2008 Cleaned up gem files. [jessesielaff]
file README.rdoc Mon Oct 05 05:07:26 -0700 2009 More Readme cleanup [julius]
file Rakefile Fri Nov 07 23:05:57 -0800 2008 Cleaned up gem files. [jessesielaff]
directory bin/ Mon Apr 27 18:14:48 -0700 2009 .red-extension removed in favour of .rb [julius]
directory config/ Thu Nov 06 09:17:02 -0800 2008 Updated to latest versions of rake, hoe, and ne... [jessesielaff]
directory lib/ Tue Oct 27 09:14:38 -0700 2009 removed the reserved js-word final [julius]
directory spec/ Wed Nov 05 12:35:56 -0800 2008 removed rspec stubs, added redspec specs [trek]
README.rdoc

Red converts Ruby to Javascript

This is my personal fork of the Ruby Red Project. github.com/jessesielaff/red

Getting started

simple.rb:

  require 'red_query'

  Document.ready? do
    Document.query('#someDiv').html('hello ruby!!')
  end

You need Red and red_query (github.com/julius/red_query) for this to work. Compile it with:

  ruby -I$RED_DIR/lib/ $RED_DIR/bin/red -I$RED_QUERY_DIR/ -o simple.js simple

Whats different in my fork?

There are a lot of fixes to make more advanced Ruby code run. One Example is calling ‘super’ over more than two levels of inheritance. Many additions and changes are made to make Red fit better into real world scenarios

Include folders, set output file

Here is an example for compilation

  ruby -I$RED_DIR/lib/ $RED_DIR/bin/red -I../red_query/ -Ilib -I. -Iapp -o public/js/mycode.js red/mycode

This will compile the file "red/mycode.rb" and will write the output to "public/js/mycode.js" "require"-Statements in Red code will search in all directories marked by -I<dir> (after ../bin/red)

Super private Code

Its nice to reuse code in the frontend and in the backend. E.g.

  class User
    def valid_email?(email)
      ...
    end
  end

You can also save classes by mixing in some backend only code.

  class User
    def valid_email?(email)
      ...
    end

    def login(email, password)
      top_secret_stuff(email)
      screwed_up_backend_code(email, password)
    end
  end

You might not want to let Red reveal the login method to hackers. Lets invent some Syntax.

  class User
    def valid_email?(email)
      ...
    end

        server_side

    def login(email, password)
      top_secret_stuff(email)
      screwed_up_backend_code(email, password)
    end
  end

The method login and everything after server_side will be ignored by my Red customization.

Redshift != Red

I excluded Redshift from my Red version. I believe Red should only have Compilation functionality and it should be open for any kind of Framework, which does DOM-Access etc. I personally started one based on jQuery: github.com/julius/red_query

The original Red

You can learn more about the great original, gem installable Red on github.com/jessesielaff/red/wikis

MIT License

Copyright © 2008 Jesse Sielaff

  Permission is hereby granted, free of charge, to any person obtaining
  a copy of this software and associated documentation files (the
  'Software'), to deal in the Software without restriction, including
  without limitation the rights to use, copy, modify, merge, publish,
  distribute, sublicense, and/or sell copies of the Software, and to
  permit persons to whom the Software is furnished to do so, subject to
  the following conditions:

  The above copyright notice and this permission notice shall be
  included in all copies or substantial portions of the Software.

  THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
  EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
  MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
  IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
  CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
  TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
  SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.