Permalink
Browse files

checkpoint

  • Loading branch information...
1 parent 696f0fb commit 486df0a4899cc2e03ad0532bc8bfda3871b8f989 @datapimp committed Mar 16, 2013
Showing with 2,756 additions and 25 deletions.
  1. +2 −1 code_sync.gemspec
  2. +13 −2 lib/assets/javascripts/code_sync/client/index.coffee
  3. +6 −2 lib/assets/javascripts/code_sync/client/util.coffee
  4. 0 lib/assets/javascripts/code_sync/editor/index.coffee
  5. +24 −1 lib/code_sync.rb
  6. +7 −2 lib/code_sync/cli.rb
  7. +23 −0 lib/code_sync/command_runner.rb
  8. +6 −4 lib/code_sync/publisher.rb
  9. +36 −10 lib/code_sync/server.rb
  10. +39 −0 lib/code_sync/sprockets_adapter.rb
  11. +21 −3 lib/code_sync/watcher.rb
  12. +21 −0 lib/middleman_extension.rb
  13. +14 −0 site/.gitignore
  14. +12 −0 site/Gemfile
  15. +149 −0 site/Gemfile.lock
  16. +69 −0 site/config.rb
  17. BIN site/source/app/assets/images/background.png
  18. BIN site/source/app/assets/images/middleman.png
  19. +1 −0 site/source/app/assets/javascripts/all.js
  20. +55 −0 site/source/app/assets/stylesheets/all.css
  21. +375 −0 site/source/app/assets/stylesheets/normalize.css
  22. +1 −0 site/source/index.html.haml
  23. +21 −0 site/source/layouts/layout.haml
  24. +14 −0 spec/support/dummy_middleman/.gitignore
  25. +5 −0 spec/support/dummy_middleman/Gemfile
  26. +100 −0 spec/support/dummy_middleman/Gemfile.lock
  27. +77 −0 spec/support/dummy_middleman/config.rb
  28. BIN spec/support/dummy_middleman/source/images/background.png
  29. BIN spec/support/dummy_middleman/source/images/middleman.png
  30. +10 −0 spec/support/dummy_middleman/source/index.html.erb
  31. +1 −0 spec/support/dummy_middleman/source/javascripts/all.js
  32. +19 −0 spec/support/dummy_middleman/source/layouts/layout.erb
  33. +55 −0 spec/support/dummy_middleman/source/stylesheets/all.css
  34. +375 −0 spec/support/dummy_middleman/source/stylesheets/normalize.css
  35. +15 −0 spec/support/dummy_rails/.gitignore
  36. +38 −0 spec/support/dummy_rails/Gemfile
  37. +112 −0 spec/support/dummy_rails/Gemfile.lock
  38. +261 −0 spec/support/dummy_rails/README.rdoc
  39. +7 −0 spec/support/dummy_rails/Rakefile
  40. BIN spec/support/dummy_rails/app/assets/images/rails.png
  41. +15 −0 spec/support/dummy_rails/app/assets/javascripts/application.js
  42. +13 −0 spec/support/dummy_rails/app/assets/stylesheets/application.css
  43. +3 −0 spec/support/dummy_rails/app/controllers/application_controller.rb
  44. +2 −0 spec/support/dummy_rails/app/helpers/application_helper.rb
  45. 0 spec/support/dummy_rails/app/mailers/.gitkeep
  46. 0 spec/support/dummy_rails/app/models/.gitkeep
  47. +14 −0 spec/support/dummy_rails/app/views/layouts/application.html.erb
  48. +4 −0 spec/support/dummy_rails/config.ru
  49. +62 −0 spec/support/dummy_rails/config/application.rb
  50. +6 −0 spec/support/dummy_rails/config/boot.rb
  51. +25 −0 spec/support/dummy_rails/config/database.yml
  52. +5 −0 spec/support/dummy_rails/config/environment.rb
  53. +37 −0 spec/support/dummy_rails/config/environments/development.rb
  54. +67 −0 spec/support/dummy_rails/config/environments/production.rb
  55. +37 −0 spec/support/dummy_rails/config/environments/test.rb
  56. +7 −0 spec/support/dummy_rails/config/initializers/backtrace_silencers.rb
  57. +15 −0 spec/support/dummy_rails/config/initializers/inflections.rb
  58. +5 −0 spec/support/dummy_rails/config/initializers/mime_types.rb
  59. +7 −0 spec/support/dummy_rails/config/initializers/secret_token.rb
  60. +8 −0 spec/support/dummy_rails/config/initializers/session_store.rb
  61. +14 −0 spec/support/dummy_rails/config/initializers/wrap_parameters.rb
  62. +5 −0 spec/support/dummy_rails/config/locales/en.yml
  63. +58 −0 spec/support/dummy_rails/config/routes.rb
  64. +7 −0 spec/support/dummy_rails/db/seeds.rb
  65. +2 −0 spec/support/dummy_rails/doc/README_FOR_APP
  66. 0 spec/support/dummy_rails/lib/assets/.gitkeep
  67. 0 spec/support/dummy_rails/lib/tasks/.gitkeep
  68. 0 spec/support/dummy_rails/log/.gitkeep
  69. +26 −0 spec/support/dummy_rails/public/404.html
  70. +26 −0 spec/support/dummy_rails/public/422.html
  71. +25 −0 spec/support/dummy_rails/public/500.html
  72. 0 spec/support/dummy_rails/public/favicon.ico
  73. +241 −0 spec/support/dummy_rails/public/index.html
  74. +5 −0 spec/support/dummy_rails/public/robots.txt
  75. +6 −0 spec/support/dummy_rails/script/rails
  76. 0 spec/support/dummy_rails/test/fixtures/.gitkeep
  77. 0 spec/support/dummy_rails/test/functional/.gitkeep
  78. 0 spec/support/dummy_rails/test/integration/.gitkeep
  79. +12 −0 spec/support/dummy_rails/test/performance/browsing_test.rb
  80. +13 −0 spec/support/dummy_rails/test/test_helper.rb
  81. 0 spec/support/dummy_rails/test/unit/.gitkeep
  82. 0 spec/support/dummy_rails/vendor/assets/javascripts/.gitkeep
  83. 0 spec/support/dummy_rails/vendor/assets/stylesheets/.gitkeep
  84. 0 spec/support/dummy_rails/vendor/plugins/.gitkeep
  85. BIN spec/support/{site → dummy_static}/.DS_Store
  86. BIN spec/support/{site → dummy_static}/app/.DS_Store
  87. BIN spec/support/{site → dummy_static}/app/assets/.DS_Store
  88. 0 spec/support/{site → dummy_static}/app/assets/javascripts/manifest.coffee
  89. 0 spec/support/{site → dummy_static}/app/assets/javascripts/spec_application_javascript.coffee
  90. 0 spec/support/{site → dummy_static}/app/assets/stylesheets/spec_application_stylesheet.css.scss
  91. 0 spec/support/{site → dummy_static}/lib/assets/javascripts/spec_library_javascript.coffee
  92. 0 spec/support/{site → dummy_static}/lib/assets/stylesheets/spec_library_stylesheet.css.scss
  93. 0 spec/support/{site → dummy_static}/vendor/assets/javascripts/spec_vendor_javascript.js
  94. 0 spec/support/{site → dummy_static}/vendor/assets/stylesheets/spec_vendor_stylesheets.css
View
@@ -2,7 +2,7 @@ $:.push File.expand_path("../lib", __FILE__)
require 'code_sync/version'
Gem::Specification.new do |s|
- s.name = "code sync"
+ s.name = "code_sync"
s.version = CodeSync::Version
s.platform = Gem::Platform::RUBY
s.authors = ["Jonathan Soeder"]
@@ -12,6 +12,7 @@ Gem::Specification.new do |s|
s.description = ""
s.add_dependency 'faye'
+ s.add_dependency 'thin'
s.add_dependency 'listen'
s.add_dependency 'sprockets'
@@ -5,9 +5,20 @@
root = @
-if typeof(CodeSync) isnt "undefined"
+if typeof(exports) isnt "undefined"
CodeSync = exports
else
CodeSync = root.CodeSync = {}
-CodeSync.VERSION = "0.0.1"
+CodeSync.VERSION = "0.0.4"
+
+class CodeSync.Client
+ constructor: ()->
+
+ CodeSync.util.loadScript "http://localhost:9295/faye/client.js", ()=>
+ if Faye?
+ @socket = new Faye.Client("http://localhost:9295/faye")
+ console.log "Subscribing on ", @socket
+ @socket.subscribe "/code-sync", ()=>
+ console.log "Received Message", arguments
+
@@ -14,15 +14,19 @@ CodeSync.util.loadScript = (url, options={}, callback) ->
head= document.getElementsByTagName('head')[0];
script = document.createElement("script")
- script.url = url
+ script.src = url
script.type = "text/javascript"
that = @
onLoad = ()->
if typeof(callback) is "function"
callback.call(that, url, options, script)
- head.removeChild(script)
+ try
+ head.removeChild(script)
+ catch e
+ true
+
loaded[url] = true
if options.once is true && loaded[url]
View
@@ -1,4 +1,4 @@
-$:.unshift File.dirname(__FILE__)
+$:.unshift File.dirname(__FILE__)
module CodeSync
require 'code_sync/version'
@@ -7,4 +7,27 @@ module CodeSync
require 'code_sync/temp_asset'
require 'code_sync/sprockets_adapter'
require 'code_sync/watcher'
+ require 'code_sync/command_runner'
+ require 'middleman_extension'
+
+ def self.gem_assets_root
+ File.join(File.dirname(__FILE__), '..')
+ end
+end
+
+# When using outside of Rails.
+# Allows for using Rails asset pipline gems.
+unless defined? Rails
+ module Rails
+ def self.env
+ Class.new do
+ def test?
+ false
+ end
+ end.new
+ end
+
+ class Engine
+ end
+ end
end
View
@@ -44,8 +44,9 @@ 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, faye:)
+ server = CodeSync::Server.new(root: Dir.pwd())
+ watcher = CodeSync::Watcher.new(root: Dir.pwd(), assets: server.assets, faye: server.faye)
+ runner = CodeSync::CommandRunner.new(client: server.faye.get_client, assets: server.assets)
fork do
server.start(9295)
@@ -55,6 +56,10 @@ def start
watcher.start()
end
+ fork do
+ runner.start()
+ end
+
Process.waitpid
end
@@ -0,0 +1,23 @@
+module CodeSync
+ class CommandRunner
+ attr_accessor :client,
+ :assets
+
+ def initialize options={}
+ @client, @assets = options.values_at(:client, :assets)
+ end
+
+ def start
+ puts "Starting Command Runner"
+ client = @client
+
+ EM.run {
+ puts "Subscribing to code-sync commands channel"
+ client.subscribe("/code-sync/commands") do |command|
+ puts "Received Code Sync Command"
+ puts command.inspect
+ end
+ }
+ end
+ end
+end
View
@@ -2,21 +2,23 @@ module CodeSync
class Publisher
attr_reader :client, :url
- def initialize url
- @url = url
+ def initialize options={}
+ @url, @client = options.values_at(:url, :client)
end
def client
+ @client = nil if @client && !@client.is_a?(::Faye::Client)
@client ||= ::Faye::Client.new(url)
end
def shutdown
EM.stop
end
- def publish channel, message
+ def publish channel="/code-sync", message="{status:'ok'}"
+ binding.pry
+ puts "Publishing to #{ channel } #{ message.length }"
EM.run do
- client = ::Faye::Client.new(url)
pub = client.publish( channel, message )
pub.callback { EM.stop }
pub.errback { EM.stop }
View
@@ -1,32 +1,58 @@
require 'thin'
require 'faye'
+require 'rack'
+require 'json'
module CodeSync
class Server
- attr_accessor :assets
+ attr_accessor :assets,
+ :faye,
+ :root
+
def initialize options={}
- @assets = CodeSync::SprocketsAdapter.new(root:Dir.pwd())
+ @assets = options[:assets] || CodeSync::SprocketsAdapter.new(root:Dir.pwd())
+ @root = options[:root]
Faye::WebSocket.load_adapter('thin')
@faye = Faye::RackAdapter.new(mount:"/faye",timeout:25)
+
+ faye.add_extension(FayeMonitor.new)
end
def start port=9295
assets = @assets.env
faye = @faye
+
+ app = Rack::URLMap.new "/assets" => assets, "/" => faye, "/info" => ServerInfo.new(sprockets:assets)
+ Rack::Server.start(app:app,:Port=>9295,:server=>'thin')
+ end
+ class Middleware
- Thin::Server.start('0.0.0.0', port) do
- map "/assets" do
- run assets
- end
+ end
- map "/" do
- run faye
- end
+ class FayeMonitor
+ def incoming(message,callback)
+ puts "Received incoming message"
+ puts message.inspect
+ callback.call(message)
end
- end
+
+ end
+
+ class ServerInfo
+ attr_accessor :faye, :sprockets
+
+ def initialize options={}
+ @sprockets = options[:sprockets]
+ @faye = options[:faye]
+ end
+
+ def call(env)
+ [200, {"Content-Type" => "application/json"}, JSON.generate(paths:sprockets.paths)]
+ end
+ end
end
end
@@ -1,6 +1,37 @@
require 'sprockets'
+require 'coffee-script'
+require 'sass'
module CodeSync
+ class AssetPipelineGems
+ TestPaths = %w{
+ assets
+ app/assets
+ lib/assets
+ vendor/assets
+ }
+
+ def self.gems
+ return @gems if !@gems.nil?
+
+ gems = ::Gem::Specification.latest_specs
+
+ gems.select! do |gemspec|
+ base = gemspec.full_gem_path
+ TestPaths.detect {|folder| File.exists?(File.join(base,folder))}
+ end
+ end
+
+ def self.paths
+ paths = gems.flat_map do |gemspec|
+ base = gemspec.full_gem_path
+ TestPaths.map {|folder| File.join(base, folder)}
+ end
+
+ paths.select {|dir| File.exists?(dir) }
+ end
+ end
+
class SprocketsAdapter
attr_accessor :env, :options
@@ -35,15 +66,23 @@ def tmpdir
@tmpdir ||= Dir.tmpdir
end
+ def append_gem_paths
+ AssetPipelineGems.paths.each {|path| env.append_path(path) }
+ end
+
def append_temporary_path
env.prepend_path(tmpdir)
end
def append_asset_paths base_path=nil
base_path ||= env.root
+ append_gem_paths
+
env.append_path tmpdir
+ env.append_path CodeSync.gem_assets_root
+
%w{lib vendor app}.each do |base|
path = File.join(env.root, base, 'assets')
View
@@ -8,10 +8,13 @@ class Watcher
def initialize(options={})
@options = options
- @notifier = Publisher.new(options[:url] || "//localhost:9295/faye")
- @assets = SprocketsAdapter.new(root: Dir.pwd())
@id = rand(36**36).to_s(36).slice(0,8)
+ faye = options[:faye]
+
+ @notifier ||= Publisher.new(client: faye, url: "http://localhost:9295/faye")
+ @assets ||= SprocketsAdapter.new(root: Dir.pwd())
+
@listener = Listen.to(assets_directory)
.filter(options[:filter] || /(\.coffee|\.css|\.jst|\.mustache)/)
.latency(options[:latency] || 1)
@@ -39,7 +42,6 @@ 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: #{ $! }"
@@ -61,6 +63,22 @@ def change_payload_for paths
def start
@listener.start
end
+
+ def status
+ {
+ root: Dir.pwd(),
+ is_rails: rails?,
+ is_middleman: middleman?
+ }
+ end
+
+ def rails?
+ false
+ end
+
+ def middleman?
+ false
+ end
end
View
@@ -0,0 +1,21 @@
+if defined?(Middleman)
+ require "middleman-core"
+ require "middleman-more"
+
+
+ module CodeSync::MiddlemanExtension
+ class << self
+ def registered app
+ puts "CodeSync"
+ app.send :include, InstanceMethods
+ end
+ end
+ module InstanceMethods
+ end
+ end
+
+ Middleman::Extensions.register(:code_sync) do
+ require 'code_sync'
+ CodeSync::MiddlemanExtension
+ end
+end
View
@@ -0,0 +1,14 @@
+# See http://help.github.com/ignore-files/ for more about ignoring files.
+#
+# If you find yourself ignoring temporary files generated by your text editor
+# or operating system, you probably want to add a global ignore instead:
+# git config --global core.excludesfile ~/.gitignore_global
+
+# Ignore bundler config
+/.bundle
+
+# Ignore the build directory
+/build
+
+# Ignore Sass' cache
+/.sass-cache
Oops, something went wrong.

0 comments on commit 486df0a

Please sign in to comment.