Skip to content

Commit

Permalink
support CoffeeScript
Browse files Browse the repository at this point in the history
put CoffeeScript in {project_path}/coffeescripts/{something}.coffee
and the javascript url will be
/{compass.config.javscript_dirs}/{something}.js
  • Loading branch information
tka committed Mar 20, 2012
1 parent 4389d8f commit 1b7c541
Show file tree
Hide file tree
Showing 57 changed files with 3,962 additions and 14 deletions.
22 changes: 22 additions & 0 deletions lib/ruby/common/coffee-script-2.2.0/LICENSE
@@ -0,0 +1,22 @@
Copyright (c) 2010 Joshua Peek

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.
43 changes: 43 additions & 0 deletions lib/ruby/common/coffee-script-2.2.0/README.md
@@ -0,0 +1,43 @@
Ruby CoffeeScript
=================

Ruby CoffeeScript is a bridge to the official CoffeeScript compiler.

CoffeeScript.compile File.read("script.coffee")


Installation
------------

gem install coffee-script

*Note: This compiler library has replaced the original CoffeeScript
compiler that was written in Ruby.*


Dependencies
------------

This library depends on the `coffee-script-source` gem which is
updated any time a new version of CoffeeScript is released. (The
`coffee-script-source` gem's version number is synced with each
official CoffeeScript release.) This way you can build against
different versions of CoffeeScript by requiring the correct version of
the `coffee-script-source` gem.

In addition, you can use this library with unreleased versions of
CoffeeScript by setting the `COFFEESCRIPT_SOURCE_PATH` environment
variable:

export COFFEESCRIPT_SOURCE_PATH=/path/to/coffee-script/extras/coffee-script.js

### JSON

The `json` library is also required but is not explicitly stated as a
gem dependency. If you're on Ruby 1.8 you'll need to install the
`json` or `json_pure` gem. On Ruby 1.9, `json` is included in the
standard library.

### ExecJS

The [ExecJS](https://github.com/sstephenson/execjs) library is used to automatically choose the best JavaScript engine for your platform. Check out its [README](https://github.com/sstephenson/execjs/blob/master/README.md) for a complete list of supported engines.
1 change: 1 addition & 0 deletions lib/ruby/common/coffee-script-2.2.0/lib/coffee-script.rb
@@ -0,0 +1 @@
require 'coffee_script'
60 changes: 60 additions & 0 deletions lib/ruby/common/coffee-script-2.2.0/lib/coffee_script.rb
@@ -0,0 +1,60 @@
require 'execjs'
require 'coffee_script/source'

module CoffeeScript
EngineError = ExecJS::RuntimeError
CompilationError = ExecJS::ProgramError

module Source
def self.path
@path ||= ENV['COFFEESCRIPT_SOURCE_PATH'] || bundled_path
end

def self.path=(path)
@contents = @version = @bare_option = @context = nil
@path = path
end

def self.contents
@contents ||= File.read(path)
end

def self.version
@version ||= contents[/CoffeeScript Compiler v([\d.]+)/, 1]
end

def self.bare_option
@bare_option ||= contents.match(/noWrap/) ? 'noWrap' : 'bare'
end

def self.context
@context ||= ExecJS.compile(contents)
end
end

class << self
def engine
end

def engine=(engine)
end

def version
Source.version
end

# Compile a script (String or IO) to JavaScript.
def compile(script, options = {})
script = script.read if script.respond_to?(:read)

if options.key?(:bare)
elsif options.key?(:no_wrap)
options[:bare] = options[:no_wrap]
else
options[:bare] = false
end

Source.context.call("CoffeeScript.compile", script, options)
end
end
end

Large diffs are not rendered by default.

@@ -0,0 +1,7 @@
module CoffeeScript
module Source
def self.bundled_path
File.expand_path("../coffee-script.js", __FILE__)
end
end
end
21 changes: 21 additions & 0 deletions lib/ruby/common/execjs-1.3.0/LICENSE
@@ -0,0 +1,21 @@
Copyright (c) 2011 Sam Stephenson
Copyright (c) 2011 Josh Peek

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.
47 changes: 47 additions & 0 deletions lib/ruby/common/execjs-1.3.0/README.md
@@ -0,0 +1,47 @@
ExecJS
======

ExecJS lets you run JavaScript code from Ruby. It automatically picks
the best runtime available to evaluate your JavaScript program, then
returns the result to you as a Ruby object.

ExecJS supports these runtimes:

* [therubyracer](https://github.com/cowboyd/therubyracer) - Google V8
embedded within Ruby
* [therubyrhino](https://github.com/cowboyd/therubyrhino) - Mozilla
Rhino embedded within JRuby
* [Johnson](https://github.com/jbarnette/johnson) - Mozilla
SpiderMonkey embedded within Ruby
* [Mustang](https://github.com/nu7hatch/mustang) - Mustang V8
embedded within Ruby
* [Node.js](http://nodejs.org/)
* Apple JavaScriptCore - Included with Mac OS X
* [Mozilla SpiderMonkey](http://www.mozilla.org/js/spidermonkey/)
* [Microsoft Windows Script Host](http://msdn.microsoft.com/en-us/library/9bbdkx3k.aspx) (JScript)

A short example:

require "execjs"
ExecJS.eval "'red yellow blue'.split(' ')"
# => ["red", "yellow", "blue"]

A longer example, demonstrating how to invoke the CoffeeScript compiler:

require "execjs"
require "open-uri"
source = open("http://jashkenas.github.com/coffee-script/extras/coffee-script.js").read

context = ExecJS.compile(source)
context.call("CoffeeScript.compile", "square = (x) -> x * x", :bare => true)
# => "var square;\nsquare = function(x) {\n return x * x;\n};"

# Installation

$ gem install execjs

# License

Copyright (c) 2011 Sam Stephenson and Josh Peek.

Released under the MIT license. See `LICENSE` for details.
6 changes: 6 additions & 0 deletions lib/ruby/common/execjs-1.3.0/lib/execjs.rb
@@ -0,0 +1,6 @@
require "execjs/module"
require "execjs/runtimes"

module ExecJS
self.runtime ||= Runtimes.autodetect
end
23 changes: 23 additions & 0 deletions lib/ruby/common/execjs-1.3.0/lib/execjs/disabled_runtime.rb
@@ -0,0 +1,23 @@
module ExecJS
class DisabledRuntime
def name
"Disabled"
end

def exec(source)
raise Error, "ExecJS disabled"
end

def eval(source)
raise Error, "ExecJS disabled"
end

def compile(source)
raise Error, "ExecJS disabled"
end

def available?
true
end
end
end

0 comments on commit 1b7c541

Please sign in to comment.