Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

initial import

  • Loading branch information...
commit fb86f07da25bf5be81a6c9b78b7c9fc574d0df71 1 parent d1ff416
@flomotlik authored
View
12 .gitmodules
@@ -0,0 +1,12 @@
+[submodule "vendor/em-websocket"]
+ path = vendor/em-websocket
+ url = https://github.com/igrigorik/em-websocket.git
+[submodule "vendor/addressable"]
+ path = vendor/addressable
+ url = https://github.com/sporkmonger/addressable.git
+[submodule "vendor/eventmachine"]
+ path = vendor/eventmachine
+ url = https://github.com/eventmachine/eventmachine.git
+[submodule "vendor/json"]
+ path = vendor/json
+ url = https://github.com/flori/json.git
View
119 plugin/vim-livereload.vim
@@ -0,0 +1,119 @@
+" Exit quickly when already loaded.
+if exists("g:loaded_vim_livereload")
+ finish
+endif
+
+" Exit quicky if running in compatible mode
+if &compatible
+ echohl ErrorMsg
+ echohl none
+ finish
+endif
+
+" Check for Ruby functionality.
+if !has("ruby")
+ echohl ErrorMsg
+ echon "Sorry, Vim-Livereload requires ruby support."
+ finish
+endif
+
+let g:loaded_vim_livereload = "true"
+
+function! Reload_Browser()
+ :ruby reload_browser()
+endfunction
+
+function! Startup()
+ :ruby startup
+endfunction
+
+function! Stop()
+ :ruby stop
+endfunction
+
+augroup livereload
+ autocmd BufWritePost * :call Reload_Browser()
+ autocmd VimEnter * :call Startup()
+ autocmd VimLeave * :call Stop()
+augroup END
+
+command Livereload :call Reload_Browser()
+command StartLivereload :call Startup()
+command StopLivereload :call Stop()
+
+autocmd CursorHold * call Timer()
+autocmd CursorHoldI * call Timer()
+
+function! Timer()
+ :ruby timer
+ call feedkeys("f\e")
+endfunction
+
+ruby << EOF
+dir = File.dirname(__FILE__) + "/../vendor"
+Dir.foreach(dir){|x| $LOAD_PATH.unshift(dir + "/" + x + "/lib")}
+require 'em/pure_ruby'
+require 'json'
+require 'em-websocket'
+
+module Livereload
+ def self.web_sockets
+ @web_sockets ||= []
+ @web_sockets
+ end
+end
+
+def reload_browser
+ name = VIM::Buffer.current.name
+ data = ['refresh', {
+ :path => name,
+ :apply_js_live => @options[:apply_js_live],
+ :apply_css_live => @options[:apply_css_live]
+ }].to_json
+ Livereload.web_sockets.delete_if{|ws| ws.state == :closed}
+ Livereload.web_sockets.each do |ws|
+ ws.send(data) if ws.state == :connected
+ end
+ sleep 1
+end
+
+def startup
+ @options = {
+ :api_version => '1.6',
+ :host => '0.0.0.0',
+ :port => '35729',
+ :apply_js_live => true,
+ :apply_css_live => true,
+ :grace_period => 0
+ }
+ @@web_sockets = []
+ @thread = Thread.new do
+ EventMachine.run do
+ @server = EventMachine.start_server(@options[:host], @options[:port], EventMachine::WebSocket::Connection, {}) do |ws|
+ ws.onopen do
+ begin
+ ws.send "!!ver:#{@options[:api_version]}"
+ Livereload.web_sockets << ws
+ rescue
+ end
+ end
+
+ ws.onmessage do |msg|
+ end
+
+ ws.onclose do
+ Livereload.web_sockets.delete ws
+ end
+ end
+ end
+ end
+end
+
+def stop
+ @thread.kill
+end
+
+def timer
+end
+EOF
+
1  vendor/addressable
@@ -0,0 +1 @@
+Subproject commit 01604a358884cba3e6fc1c836506730ace41443e
1  vendor/em-websocket
@@ -0,0 +1 @@
+Subproject commit ca98c114c474445c08e97166fb85bb79e582fb3a
1  vendor/eventmachine
@@ -0,0 +1 @@
+Subproject commit ba8348847b104b35b6d4b258426a95197ec6d34a
1  vendor/json
@@ -0,0 +1 @@
+Subproject commit c1320061ae68a4695d72ce287373ff1e2e2f0022
Please sign in to comment.
Something went wrong with that request. Please try again.