Permalink
Browse files

Expose Juggernaut gem to Rails asset pipeline

All client-side javascript lives in client/vendor/assets/javascripts.
Generate packaged application.js by leveraging sprockets gem directly.
  • Loading branch information...
1 parent 7a10171 commit 8111c33b33697c40f8af00f2fff8cf66f6c86c15 @duncanbeevers duncanbeevers committed Sep 22, 2011
View
7 Rakefile
@@ -1,11 +1,14 @@
require "tempfile"
require "yui/compressor"
require "fileutils"
+require "sprockets"
APP_PATH = File.expand_path("./public/application.js")
task :build do
- `sprocketize -I public/ public/juggernaut.js > #{APP_PATH}`
+ env = Sprockets::Environment.new
+ env.append_path 'client/vendor/assets/javascripts'
+ File.open(APP_PATH, 'w') { |f| f << env['juggernaut.js'].to_s }
end
task :compress do
@@ -23,4 +26,4 @@ task :compress do
FileUtils.mv(tempfile.path, APP_PATH)
end
-task :default => [:build, :compress]
+task :default => [:build, :compress]
View
6 client/juggernaut.gemspec
@@ -22,7 +22,11 @@ Gem::Specification.new do |s|
"examples/juggernaut_observer.rb",
"examples/roster.rb",
"juggernaut.gemspec",
- "lib/juggernaut.rb"
+ "lib/juggernaut.rb",
+ "lib/juggernaut/rails/engine.rb",
+ "vendor/assets/javascripts/juggernaut.js",
+ "vendor/assets/javascripts/json.js",
+ "vendor/assets/javascripts/socket_io.js"
]
s.homepage = %q{http://github.com/maccman/juggernaut}
s.rdoc_options = ["--charset=UTF-8"]
View
3 client/lib/juggernaut.rb
@@ -1,6 +1,9 @@
require "redis"
require "json"
+# Attempt to provide Engine to Rails
+require "juggernaut/rails/engine"
+
module Juggernaut
EVENTS = [
"juggernaut:subscribe",
View
7 client/lib/juggernaut/rails/engine.rb
@@ -0,0 +1,7 @@
+module Juggernaut
+ begin
+ class Engine < ::Rails::Engine
+ end
+ rescue NameError
+ end
+end
View
0 public/json.js → client/vendor/assets/javascripts/json.js
File renamed without changes.
View
6 public/juggernaut.js → ...t/vendor/assets/javascripts/juggernaut.js
@@ -1,7 +1,7 @@
// For sprockets:
//
-//= require <json>
-//= require <socket_io>
+//= require json
+//= require socket_io
var Juggernaut = function(options){
this.options = options || {};
@@ -136,4 +136,4 @@ Juggernaut.Message.prototype.toJSON = function(){
object[key] = this[key];
}
return(JSON.stringify(object));
-};
+};
View
0 public/socket_io.js → ...nt/vendor/assets/javascripts/socket_io.js
File renamed without changes.

0 comments on commit 8111c33

Please sign in to comment.