├── .gitignore ├── Gemfile ├── History.txt ├── README.md ├── Rakefile ├── lib ├── sproutcore-coffeescript.rb └── sproutcore-coffeescript │ ├── builders │ └── coffeescript.rb │ ├── buildtasks │ ├── build.rake │ └── manifest.rake │ ├── models │ └── manifest_entry.rb │ └── version.rb └── sproutcore-coffeescript.gemspec /.gitignore: -------------------------------------------------------------------------------- 1 | *.gem 2 | .bundle 3 | Gemfile.lock 4 | pkg/* 5 | -------------------------------------------------------------------------------- /Gemfile: -------------------------------------------------------------------------------- 1 | source "http://rubygems.org" 2 | gemspec 3 | -------------------------------------------------------------------------------- /History.txt: -------------------------------------------------------------------------------- 1 | == 0.1.5 2 | 3 | - Moved files to sproutcore-coffeescript directory, so the files never get required by sproutcore itself instead of the original sproutcore files 4 | 5 | 6 | == 0.1.4 7 | 8 | - FIX: coffeescript test files are not loaded into application anymore 9 | - coffeescript generated javascript are now prefixed with semicolon, because Sproutcore sometimes doesn't put semicolons at the end of javascript files and coffeescript generated javascript is wrapped in parentheses, so joining such files results in unexpected behaviour 10 | - coffeescript builder now reuses all functionality of javascript builder 11 | 12 | 13 | == 0.1.3 14 | 15 | - sc_require '...' is now matched even without parentheses 16 | 17 | 18 | == 0.1.1 19 | 20 | - sc_super is now replaced with arguments.callee.base.apply same as in javascript 21 | 22 | 23 | == 0.1.0 24 | 25 | - coffeescript files get translated to javascript 26 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | SproutCore + CoffeeScript 2 | ========================= 3 | 4 | This ruby gem adds support for CoffeeScript files in SproutCore projects. 5 | 6 | 7 | Usage 8 | ----- 9 | 10 | Install the gem 11 | 12 | gem install sproutcore-coffeescript 13 | 14 | Add to the top of the Buildfile in the root of your project: 15 | 16 | begin 17 | gem "sproutcore-coffeescript", "~> 0.1.4" 18 | require "sproutcore-coffeescript" 19 | rescue LoadError 20 | puts "sproutcore-coffeescript not installed, please run:\n\n gem install sproutcore-coffeescript\n\n" 21 | exit 22 | end 23 | 24 | Use .coffee instead of .js. Enjoy. 25 | 26 | 27 | Disclaimer 28 | ---------- 29 | 30 | This gem monkey-patches SproutCore build tools on several places, which is ugly and can break with any future update of SproutCore. Also, I doubt I have covered all places in the build tools where javascript files are handled. It is not unlikely it won't work properly in all situations. You've been warned. 31 | 32 | Having said that, I use this gem in my applications and it works for me. If you find a bug, [let me know](https://github.com/bobes/sproutcore-coffeescript/issues). 33 | 34 | 35 | Acknowledgment 36 | -------------- 37 | 38 | First version of the code was taken from [Brandon Dimcheff](https://github.com/bdimcheff)'s 39 | fork of Abbot [here](https://github.com/bdimcheff/abbot/commit/b46596db3a8fae1b7e91deda1650eeca163375a7), 40 | updated to SproutCore 1.5 and packaged as a separate gem. 41 | -------------------------------------------------------------------------------- /Rakefile: -------------------------------------------------------------------------------- 1 | require "bundler" 2 | Bundler::GemHelper.install_tasks 3 | -------------------------------------------------------------------------------- /lib/sproutcore-coffeescript.rb: -------------------------------------------------------------------------------- 1 | dir = File.dirname(__FILE__) + "/sproutcore-coffeescript" 2 | 3 | require dir + "/builders/coffeescript" 4 | require dir + "/models/manifest_entry" 5 | 6 | SC.builtin_project.buildfile.load!(dir + "/buildtasks/build.rake") 7 | SC.builtin_project.buildfile.load!(dir + "/buildtasks/manifest.rake") 8 | -------------------------------------------------------------------------------- /lib/sproutcore-coffeescript/builders/coffeescript.rb: -------------------------------------------------------------------------------- 1 | module SC 2 | 3 | class Builder::CoffeeScript < Builder::JavaScript 4 | 5 | def self.build(entry, dst_path) 6 | new(entry).build(dst_path) 7 | end 8 | 9 | def readlines(src_path) 10 | ";" + ::CoffeeScript.compile(super) 11 | rescue NameError 12 | begin 13 | require "coffee-script" 14 | retry 15 | rescue LoadError => e 16 | raise "Cannot compile #{entry.source_path} because coffeescript is not installed. Please install coffeescript to continue." 17 | end 18 | end 19 | end 20 | end 21 | -------------------------------------------------------------------------------- /lib/sproutcore-coffeescript/buildtasks/build.rake: -------------------------------------------------------------------------------- 1 | namespace :build do 2 | 3 | desc "builds a single coffeescript file" 4 | build_task :coffeescript do |task, env| 5 | SC::Builder::CoffeeScript.build env[:entry], env[:dst_path] 6 | end 7 | end 8 | -------------------------------------------------------------------------------- /lib/sproutcore-coffeescript/buildtasks/manifest.rake: -------------------------------------------------------------------------------- 1 | namespace :manifest do 2 | 3 | # here we're adding behaviour to an existing task 4 | # we need to 'unhide' *.coffee entries 5 | task :hide_buildfiles do |task, env| 6 | manifest = env[:manifest] 7 | manifest.entries(:hidden => true).each do |entry| 8 | entry.hidden = false if entry[:ext] == "coffee" 9 | end 10 | end 11 | 12 | namespace :prepare_build_tasks do 13 | 14 | desc "scans for coffeescript files, annotates them and prepares combined entries for each output target" 15 | task :coffeescript => :setup do |task, env| 16 | manifest = env[:manifest] 17 | config = CONFIG 18 | 19 | entries = manifest.entries.select do |e| 20 | e.original? && e[:ext] == "coffee" 21 | end 22 | 23 | entries.each do |entry| 24 | entry = manifest.add_transform entry, 25 | :lazy_instantiation => config[:lazy_instantiation], 26 | :notify_onload => !config[:combine_javascript], 27 | :filename => ["source", entry[:filename]].join("/"), 28 | :build_path => File.join(manifest[:build_root], 'source', entry[:filename]), 29 | :url => [manifest[:url_root], "source", entry[:filename]].join("/"), 30 | :build_task => "build:coffeescript", 31 | :resource => "javascript", 32 | :ext => "js", 33 | :entry_type => :javascript 34 | entry.discover_build_directives! 35 | end 36 | end 37 | 38 | # inject :coffeescript as a :javascript dependency, so we don't have to replace :all 39 | task :javascript => :coffeescript 40 | end 41 | end 42 | -------------------------------------------------------------------------------- /lib/sproutcore-coffeescript/models/manifest_entry.rb: -------------------------------------------------------------------------------- 1 | SC::ManifestEntry.send :remove_const, :BUILD_DIRECTIVES_REGEX 2 | SC::ManifestEntry::BUILD_DIRECTIVES_REGEX = /(sc_require|require|sc_resource)[\( ]\s*(['"])(.+)['"]/ 3 | -------------------------------------------------------------------------------- /lib/sproutcore-coffeescript/version.rb: -------------------------------------------------------------------------------- 1 | module Sproutcore 2 | module CoffeeScript 3 | VERSION = "0.1.5" 4 | end 5 | end 6 | -------------------------------------------------------------------------------- /sproutcore-coffeescript.gemspec: -------------------------------------------------------------------------------- 1 | # -*- encoding: utf-8 -*- 2 | $:.push File.expand_path("../lib", __FILE__) 3 | require "sproutcore-coffeescript/version" 4 | 5 | Gem::Specification.new do |s| 6 | s.name = "sproutcore-coffeescript" 7 | s.version = Sproutcore::CoffeeScript::VERSION 8 | s.platform = Gem::Platform::RUBY 9 | s.authors = ["Vladimír Bobeš Tužinský"] 10 | s.email = ["vladimir.tuzinsky@gmail.com"] 11 | s.homepage = "https://github.com/bobes/sproutcore-coffeescript" 12 | s.summary = %q{SproutCore + CoffeeScript in love} 13 | s.description = %q{Adds support for CoffeeScript to SproutCore} 14 | 15 | s.files = `git ls-files`.split("\n") 16 | s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n") 17 | s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) } 18 | s.require_paths = ["lib"] 19 | 20 | s.add_dependency "sproutcore" 21 | s.add_dependency "coffee-script" 22 | end 23 | --------------------------------------------------------------------------------