class Hyla::Commands::Reload
Constants
- DEFAULT_OPTIONS
Attributes
options[R]
thread[R]
web_sockets[R]
Public Class Methods
new()
click to toggle source
# File lib/hyla/commands/reload.rb, line 17 def initialize() end
Public Instance Methods
process(options)
click to toggle source
# File lib/hyla/commands/reload.rb, line 20 def process(options) @options = DEFAULT_OPTIONS.clone.merge(options) @Websocket ||= Hyla::WebSocket _start end
reload_browser(paths = [])
click to toggle source
# File lib/hyla/commands/reload.rb, line 26 def reload_browser(paths = []) Hyla.logger2.info "Reloading browser: #{paths.join(' ')}" paths.each do |path| Hyla.logger2.info(path) data = _data(path) Hyla.logger2.info(">> Data received : #{data}") @@web_sockets.each { |ws| ws.send(MultiJson.encode(data)) } end end
reload_browser2(paths = [])
click to toggle source
# File lib/hyla/commands/reload.rb, line 36 def reload_browser2(paths = []) Hyla.logger2.info "Reloading browser: #{paths.join(' ')}" paths.each do |path| Hyla.logger2.info(path) data = 'hyla/development/' Hyla.logger2.info(">> Data received : #{data}") @@web_sockets.each { |ws| ws.send(MultiJson.encode(data)) } end end
Private Instance Methods
_connect(ws)
click to toggle source
# File lib/hyla/commands/reload.rb, line 84 def _connect(ws) Hyla.logger2.info "Browser connected." ws.send MultiJson.encode( command: 'hello', protocols: ['http://livereload.com/protocols/official-7'], serverName: 'guard-livereload' ) @@web_sockets << ws rescue Hyla.logger2.error $! Hyla.logger2.error $!.backtrace end
_data(path)
click to toggle source
# File lib/hyla/commands/reload.rb, line 56 def _data(path) # TODO Improve that # path: "#{Dir.pwd}/#{path}", data = { command: 'reload', path: "#{path}", liveCSS: @options[:apply_css_live] } if options[:override_url] && File.exist?(path) data[:overrideURL] = '/' + path end data end
_disconnect(ws)
click to toggle source
# File lib/hyla/commands/reload.rb, line 97 def _disconnect(ws) Hyla.logger2.info "Browser disconnected." @@web_sockets.delete(ws) end
_print_message(message)
click to toggle source
# File lib/hyla/commands/reload.rb, line 102 def _print_message(message) message = MultiJson.decode(message) Hyla.logger2.info "Browser URL: #{message['url']}" if message['command'] == 'url' end
_start()
click to toggle source
# File lib/hyla/commands/reload.rb, line 48 def _start _start_reactor end
_start_reactor()
click to toggle source
# File lib/hyla/commands/reload.rb, line 72 def _start_reactor Hyla.logger2.info "LiveReload is waiting for a browser to connect." EventMachine.epoll EventMachine.run do EventMachine.start_server(@options[:host], @options[:port], @Websocket, {}) do |ws| ws.onopen { _connect(ws) } ws.onclose { _disconnect(ws) } ws.onmessage { |msg| _print_message(msg) } end end end
_stop()
click to toggle source
# File lib/hyla/commands/reload.rb, line 52 def _stop thread.kill end