Permalink
Browse files

Using thin to wrap multiple rack processes for the CodeSync::Server. …

…Made Sprockets::Environment and Faye available on same server
  • Loading branch information...
1 parent 3be7c36 commit 781aa4ee85e3da4bfc52356510f3d134672a44c4 @datapimp committed Mar 12, 2013
Showing with 76 additions and 7 deletions.
  1. +2 −0 Gemfile
  2. +29 −0 Gemfile.lock
  3. +1 −1 lib/code_sync/cli.rb
  4. +29 −3 lib/code_sync/server.rb
  5. +8 −1 lib/code_sync/watcher.rb
  6. +6 −0 readme.md
  7. +1 −2 spec/support/site/app/assets/javascripts/manifest.coffee
View
@@ -7,6 +7,8 @@ gem "haml"
gem "ejs"
gem "coffee-script"
gem "haml_assets"
+gem "thin"
+gem "faye"
group :development, :test do
gem 'rspec'
View
@@ -1,17 +1,38 @@
GEM
remote: https://rubygems.org/
specs:
+ addressable (2.3.3)
coderay (1.0.9)
coffee-script (2.2.0)
coffee-script-source
execjs
coffee-script-source (1.6.1)
+ cookiejar (0.3.0)
+ daemons (1.1.9)
diff-lcs (1.2.1)
ejs (1.1.1)
+ em-http-request (1.0.3)
+ addressable (>= 2.2.3)
+ cookiejar
+ em-socksify
+ eventmachine (>= 1.0.0.beta.4)
+ http_parser.rb (>= 0.5.3)
+ em-socksify (0.2.1)
+ eventmachine (>= 1.0.0.beta.4)
+ eventmachine (1.0.1)
execjs (1.4.0)
multi_json (~> 1.0)
fakeredis (0.4.1)
redis (~> 3.0.0)
+ faye (0.8.9)
+ cookiejar (>= 0.3.0)
+ em-http-request (>= 0.3.0)
+ eventmachine (>= 0.12.0)
+ faye-websocket (>= 0.4.0)
+ rack (>= 1.0.0)
+ yajl-ruby (>= 1.0.0)
+ faye-websocket (0.4.7)
+ eventmachine (>= 0.12.0)
growl (1.0.3)
guard (1.6.2)
listen (>= 0.6.0)
@@ -31,6 +52,7 @@ GEM
haml
tilt
hike (1.2.1)
+ http_parser.rb (0.5.3)
listen (0.7.3)
lumberjack (1.0.2)
method_source (0.8.1)
@@ -59,8 +81,13 @@ GEM
rack (~> 1.0)
tilt (~> 1.1, != 1.3.0)
terminal-table (1.4.5)
+ thin (1.5.0)
+ daemons (>= 1.0.9)
+ eventmachine (>= 0.12.6)
+ rack (>= 1.0.0)
thor (0.17.0)
tilt (1.3.5)
+ yajl-ruby (1.1.0)
PLATFORMS
ruby
@@ -69,6 +96,7 @@ DEPENDENCIES
coffee-script
ejs
fakeredis
+ faye
growl
guard
guard-bundler
@@ -81,3 +109,4 @@ DEPENDENCIES
rspec
sass
sprockets
+ thin
View
@@ -45,7 +45,7 @@ def help(meth = nil, subcommand = false)
desc "start", "Starts this shit"
def start
server = CodeSync::Server.new(root: Dir.pwd())
- watcher = CodeSync::Watcher.new(root: Dir.pwd(), assets: server.assets)
+ watcher = CodeSync::Watcher.new(root: Dir.pwd(), assets: server.assets, faye:)
fork do
server.start(9295)
View
@@ -1,14 +1,40 @@
+require 'thin'
+require 'faye'
+
module CodeSync
- class Server < Faye::RackAdapter
+ class Server
attr_accessor :assets
def initialize options={}
- super
@assets = CodeSync::SprocketsAdapter.new(root:Dir.pwd())
+
+ Faye::WebSocket.load_adapter('thin')
+ @faye = Faye::RackAdapter.new(mount:"/faye",timeout:25)
end
def start port=9295
- listen(port)
+ assets = @assets.env
+ faye = @faye
+
+
+ Thin::Server.start('0.0.0.0', port) do
+ map "/assets" do
+ run assets
+ end
+
+ map "/" do
+ run faye
+ end
+ end
end
end
end
+
+ # Thin::Server.start('0.0.0.0', 3000) do
+ # use Rack::CommonLogger
+ # use Rack::ShowExceptions
+ # map "/lobster" do
+ # use Rack::Lint
+ # run Rack::Lobster.new
+ # end
+ # end
View
@@ -39,6 +39,7 @@ def notify modified, added, removed
puts "Detected changes in #{ (modified + added).inspect }"
begin
payload = change_payload_for(modified + added)
+ puts payload.inspect
notifier.publish("/code-sync", payload)
rescue e
puts "Error publishing payload: #{ $! }"
@@ -47,7 +48,13 @@ def notify modified, added, removed
def change_payload_for paths
paths.inject({}) do |memo, path|
- binding.pry
+ if asset = assets.find_asset(path)
+ memo[asset.logical_path] = {
+ name: asset.logical_path,
+ path: asset.digest_path,
+ source: asset.to_s
+ }
+ end
end
end
View
@@ -1,3 +1,9 @@
+CodeSync is a utility which live reloads asset pipeline assets in their running browser sessions, and an
+in-browser IDE which allows you to edit your pre-compiled assets (coffeescript, sass, etc) in the browser
+and save them to disk.
+
+### TODO / In Progress
+
- Sync asset pipeline changes with browser
- File system watcher to detect changes to asset pipeline
@@ -1,5 +1,4 @@
#= require "spec_vendor_javascript"
#= require "spec_library_javascript"
#= require "spec_application_javascript"
-
-console.log "What up!"
+console.log "What up"

0 comments on commit 781aa4e

Please sign in to comment.