guard-livereload 1.4.0 → 2.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/.gitignore +4 -0
- data/.travis.yml +14 -0
- data/Gemfile +15 -0
- data/Guardfile +5 -0
- data/{LICENSE → LICENSE.txt} +4 -2
- data/README.md +12 -10
- data/Rakefile +5 -0
- data/guard-livereload.gemspec +27 -0
- data/lib/guard/livereload.rb +9 -13
- data/lib/guard/livereload/reactor.rb +45 -42
- data/lib/guard/livereload/version.rb +1 -1
- data/lib/guard/livereload/websocket.rb +19 -9
- data/spec/lib/guard/livereload/reactor_spec.rb +38 -0
- data/spec/lib/guard/livereload_spec.rb +116 -0
- data/spec/spec_helper.rb +12 -0
- metadata +51 -25
    
        checksums.yaml
    CHANGED
    
    | @@ -1,7 +1,7 @@ | |
| 1 1 | 
             
            ---
         | 
| 2 2 | 
             
            SHA1:
         | 
| 3 | 
            -
              metadata.gz:  | 
| 4 | 
            -
              data.tar.gz:  | 
| 3 | 
            +
              metadata.gz: ab55273f33cc3c7e781a2dba0b05f0e66ea41d53
         | 
| 4 | 
            +
              data.tar.gz: e91580608a62cccc55055c42c66b9010aca13eaa
         | 
| 5 5 | 
             
            SHA512:
         | 
| 6 | 
            -
              metadata.gz:  | 
| 7 | 
            -
              data.tar.gz:  | 
| 6 | 
            +
              metadata.gz: 97de5a60a9985358cb3127256b6fa0ceafc6b757eda56f1952f36401a5e9bfd72f4f9ad37712d2631ed593e7c858144ac935923eb403b0af1817ed9f9d17b87a
         | 
| 7 | 
            +
              data.tar.gz: bfe045f49ed9b314b0b40a6be3ba9d0e5bebd4999e321a888d0b4285f5f66c0e5988289a1610d2f899af2aa95879d362c1a2e376304505c37221a29630ef1d13
         | 
    
        data/.gitignore
    ADDED
    
    
    
        data/.travis.yml
    ADDED
    
    
    
        data/Gemfile
    ADDED
    
    
    
        data/Guardfile
    ADDED
    
    
    
        data/{LICENSE → LICENSE.txt}
    RENAMED
    
    | @@ -1,4 +1,6 @@ | |
| 1 | 
            -
            Copyright (c)  | 
| 1 | 
            +
            Copyright (c) 2013 Thibaud Guillaume-Gentil
         | 
| 2 | 
            +
             | 
| 3 | 
            +
            MIT License
         | 
| 2 4 |  | 
| 3 5 | 
             
            Permission is hereby granted, free of charge, to any person obtaining
         | 
| 4 6 | 
             
            a copy of this software and associated documentation files (the
         | 
| @@ -17,4 +19,4 @@ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND | |
| 17 19 | 
             
            NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
         | 
| 18 20 | 
             
            LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
         | 
| 19 21 | 
             
            OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
         | 
| 20 | 
            -
            WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
         | 
| 22 | 
            +
            WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
         | 
    
        data/README.md
    CHANGED
    
    | @@ -1,4 +1,6 @@ | |
| 1 | 
            -
            # Guard::LiveReload | 
| 1 | 
            +
            # Guard::LiveReload
         | 
| 2 | 
            +
             | 
| 3 | 
            +
            [](http://badge.fury.io/rb/guard-livereload) [](http://travis-ci.org/guard/guard-livereload) [](https://gemnasium.com/guard/guard-livereload) [](https://codeclimate.com/github/guard/guard-livereload) [](https://coveralls.io/r/guard/guard-livereload)
         | 
| 2 4 |  | 
| 3 5 | 
             
            LiveReload guard allows to automatically reload your browser when 'view' files are modified.
         | 
| 4 6 |  | 
| @@ -20,7 +22,7 @@ Add it to your Gemfile (inside development group): | |
| 20 22 |  | 
| 21 23 | 
             
            ``` ruby
         | 
| 22 24 | 
             
            group :development do
         | 
| 23 | 
            -
              gem 'guard-livereload'
         | 
| 25 | 
            +
              gem 'guard-livereload', require: false
         | 
| 24 26 | 
             
            end
         | 
| 25 27 | 
             
            ```
         | 
| 26 28 |  | 
| @@ -34,12 +36,12 @@ Use [rack-livereload](https://github.com/johnbintz/rack-livereload) or install [ | |
| 34 36 |  | 
| 35 37 | 
             
            ## Usage
         | 
| 36 38 |  | 
| 37 | 
            -
            Please read [Guard usage doc]( | 
| 39 | 
            +
            Please read [Guard usage doc](https://github.com/guard/guard#readme) and [rack-livereload how it works readme section](https://github.com/johnbintz/rack-livereload#readme) or [LiveReload extension usage doc](http://github.com/mockko/livereload#readme)
         | 
| 38 40 |  | 
| 39 41 | 
             
            ## Guardfile
         | 
| 40 42 |  | 
| 41 43 | 
             
            You can adapt your 'view' files like you want.
         | 
| 42 | 
            -
            Please read [Guard doc]( | 
| 44 | 
            +
            Please read [Guard doc](https://github.com/guard/guard#readme) for more info about Guardfile DSL.
         | 
| 43 45 |  | 
| 44 46 | 
             
            ``` ruby
         | 
| 45 47 | 
             
            guard 'livereload' do
         | 
| @@ -65,14 +67,14 @@ end | |
| 65 67 | 
             
            Available options:
         | 
| 66 68 |  | 
| 67 69 | 
             
            ``` ruby
         | 
| 68 | 
            -
            : | 
| 69 | 
            -
            : | 
| 70 | 
            -
            : | 
| 71 | 
            -
            : | 
| 72 | 
            -
            : | 
| 70 | 
            +
            host: '127.3.3.1'     # default '0.0.0.0'
         | 
| 71 | 
            +
            port: '12345'         # default '35729'
         | 
| 72 | 
            +
            apply_css_live: false # default true
         | 
| 73 | 
            +
            override_url: false   # default false
         | 
| 74 | 
            +
            grace_period: 0.5     # default 0 (seconds)
         | 
| 73 75 | 
             
            ```
         | 
| 74 76 |  | 
| 75 | 
            -
            See [LiveReload configuration doc]( | 
| 77 | 
            +
            See [LiveReload configuration doc](https://github.com/mockko/livereload#readme) for more info about those options.
         | 
| 76 78 |  | 
| 77 79 | 
             
            ## Development
         | 
| 78 80 |  | 
    
        data/Rakefile
    ADDED
    
    
| @@ -0,0 +1,27 @@ | |
| 1 | 
            +
            # coding: utf-8
         | 
| 2 | 
            +
            lib = File.expand_path('../lib', __FILE__)
         | 
| 3 | 
            +
            $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
         | 
| 4 | 
            +
            require 'guard/livereload/version'
         | 
| 5 | 
            +
             | 
| 6 | 
            +
            Gem::Specification.new do |s|
         | 
| 7 | 
            +
              s.name         = "guard-livereload"
         | 
| 8 | 
            +
              s.version      = Guard::LiveReloadVersion::VERSION
         | 
| 9 | 
            +
              s.author       = 'Thibaud Guillaume-Gentil'
         | 
| 10 | 
            +
              s.email        = 'thibaud@thibaud.me'
         | 
| 11 | 
            +
              s.summary      = 'Guard plugin for livereload'
         | 
| 12 | 
            +
              s.description  = "Guard::LiveReload automatically reloads your browser when 'view' files are modified."
         | 
| 13 | 
            +
              s.homepage     = 'https://rubygems.org/gems/guard-livereload'
         | 
| 14 | 
            +
              s.license      = "MIT"
         | 
| 15 | 
            +
             | 
| 16 | 
            +
              s.files        = `git ls-files`.split($/)
         | 
| 17 | 
            +
              s.test_files   = s.files.grep(%r{^spec/})
         | 
| 18 | 
            +
              s.require_path = 'lib'
         | 
| 19 | 
            +
             | 
| 20 | 
            +
              s.add_dependency 'guard',        '~> 2.0'
         | 
| 21 | 
            +
              s.add_dependency 'em-websocket', '~> 0.5'
         | 
| 22 | 
            +
              s.add_dependency 'multi_json',   '~> 1.8'
         | 
| 23 | 
            +
             | 
| 24 | 
            +
              s.add_development_dependency 'bundler', '>= 1.3.5'
         | 
| 25 | 
            +
              s.add_development_dependency 'rake'
         | 
| 26 | 
            +
              s.add_development_dependency 'rspec'
         | 
| 27 | 
            +
            end
         | 
    
        data/lib/guard/livereload.rb
    CHANGED
    
    | @@ -1,26 +1,22 @@ | |
| 1 1 | 
             
            require 'guard'
         | 
| 2 | 
            -
            require 'guard/ | 
| 2 | 
            +
            require 'guard/plugin'
         | 
| 3 3 |  | 
| 4 4 | 
             
            module Guard
         | 
| 5 | 
            -
              class LiveReload <  | 
| 5 | 
            +
              class LiveReload < Plugin
         | 
| 6 6 | 
             
                require 'guard/livereload/websocket'
         | 
| 7 7 | 
             
                require 'guard/livereload/reactor'
         | 
| 8 8 |  | 
| 9 9 | 
             
                attr_accessor :reactor, :options
         | 
| 10 10 |  | 
| 11 | 
            -
                 | 
| 12 | 
            -
                # = Guard methods =
         | 
| 13 | 
            -
                # =================
         | 
| 14 | 
            -
             | 
| 15 | 
            -
                def initialize(watchers = [], options = {})
         | 
| 11 | 
            +
                def initialize(options = {})
         | 
| 16 12 | 
             
                  super
         | 
| 17 13 | 
             
                  @options = {
         | 
| 18 | 
            -
                    : | 
| 19 | 
            -
                    : | 
| 20 | 
            -
                    : | 
| 21 | 
            -
                    : | 
| 22 | 
            -
                    : | 
| 23 | 
            -
                  }. | 
| 14 | 
            +
                    host:           '0.0.0.0',
         | 
| 15 | 
            +
                    port:           '35729',
         | 
| 16 | 
            +
                    apply_css_live: true,
         | 
| 17 | 
            +
                    override_url:   false,
         | 
| 18 | 
            +
                    grace_period:   0
         | 
| 19 | 
            +
                  }.merge(options)
         | 
| 24 20 | 
             
                end
         | 
| 25 21 |  | 
| 26 22 | 
             
                def start
         | 
| @@ -8,7 +8,7 @@ module Guard | |
| 8 8 | 
             
                  def initialize(options)
         | 
| 9 9 | 
             
                    @web_sockets = []
         | 
| 10 10 | 
             
                    @options     = options
         | 
| 11 | 
            -
                    @thread      =  | 
| 11 | 
            +
                    @thread      = Thread.new { _start_reactor }
         | 
| 12 12 | 
             
                  end
         | 
| 13 13 |  | 
| 14 14 | 
             
                  def stop
         | 
| @@ -18,58 +18,61 @@ module Guard | |
| 18 18 | 
             
                  def reload_browser(paths = [])
         | 
| 19 19 | 
             
                    UI.info "Reloading browser: #{paths.join(' ')}"
         | 
| 20 20 | 
             
                    paths.each do |path|
         | 
| 21 | 
            -
                      data =  | 
| 22 | 
            -
             | 
| 23 | 
            -
                        :path     => "#{Dir.pwd}/#{path}",
         | 
| 24 | 
            -
                        :liveCSS  => @options[:apply_css_live]
         | 
| 25 | 
            -
                      }
         | 
| 26 | 
            -
                      if options[:override_url] && File.exist?(path)
         | 
| 27 | 
            -
                        data[:overrideURL] = '/' + path
         | 
| 28 | 
            -
                      end
         | 
| 29 | 
            -
                      UI.debug data
         | 
| 21 | 
            +
                      data = _data(path)
         | 
| 22 | 
            +
                      UI.debug(data)
         | 
| 30 23 | 
             
                      web_sockets.each { |ws| ws.send(MultiJson.encode(data)) }
         | 
| 31 24 | 
             
                    end
         | 
| 32 25 | 
             
                  end
         | 
| 33 26 |  | 
| 34 27 | 
             
                private
         | 
| 35 28 |  | 
| 36 | 
            -
                  def  | 
| 37 | 
            -
                     | 
| 38 | 
            -
                       | 
| 39 | 
            -
                       | 
| 40 | 
            -
             | 
| 41 | 
            -
             | 
| 42 | 
            -
             | 
| 43 | 
            -
             | 
| 44 | 
            -
             | 
| 45 | 
            -
             | 
| 46 | 
            -
             | 
| 47 | 
            -
                                :protocols  => ['http://livereload.com/protocols/official-7'],
         | 
| 48 | 
            -
                                :serverName => 'guard-livereload'
         | 
| 49 | 
            -
                              })
         | 
| 50 | 
            -
                              @web_sockets << ws
         | 
| 51 | 
            -
                            rescue
         | 
| 52 | 
            -
                              UI.errror $!
         | 
| 53 | 
            -
                              UI.errror $!.backtrace
         | 
| 54 | 
            -
                            end
         | 
| 55 | 
            -
                          end
         | 
| 56 | 
            -
             | 
| 57 | 
            -
                          ws.onmessage do |msg|
         | 
| 58 | 
            -
                            msg = MultiJson.decode(msg)
         | 
| 59 | 
            -
                            if msg['command'] == 'url'
         | 
| 60 | 
            -
                              UI.info "Browser URL: #{msg['url']}"
         | 
| 61 | 
            -
                            end
         | 
| 62 | 
            -
                          end
         | 
| 29 | 
            +
                  def _data(path)
         | 
| 30 | 
            +
                    data = {
         | 
| 31 | 
            +
                      command: 'reload',
         | 
| 32 | 
            +
                      path:    "#{Dir.pwd}/#{path}",
         | 
| 33 | 
            +
                      liveCSS: options[:apply_css_live]
         | 
| 34 | 
            +
                    }
         | 
| 35 | 
            +
                    if options[:override_url] && File.exist?(path)
         | 
| 36 | 
            +
                      data[:overrideURL] = '/' + path
         | 
| 37 | 
            +
                    end
         | 
| 38 | 
            +
                    data
         | 
| 39 | 
            +
                  end
         | 
| 63 40 |  | 
| 64 | 
            -
             | 
| 65 | 
            -
             | 
| 66 | 
            -
             | 
| 67 | 
            -
             | 
| 68 | 
            -
                         | 
| 41 | 
            +
                  def _start_reactor
         | 
| 42 | 
            +
                    EventMachine.epoll
         | 
| 43 | 
            +
                    EventMachine.run do
         | 
| 44 | 
            +
                      EventMachine.start_server(options[:host], options[:port], WebSocket, {}) do |ws|
         | 
| 45 | 
            +
                        ws.onopen    { _connect(ws) }
         | 
| 46 | 
            +
                        ws.onclose   { _disconnect(ws) }
         | 
| 47 | 
            +
                        ws.onmessage { |msg| _print_message(msg) }
         | 
| 69 48 | 
             
                      end
         | 
| 49 | 
            +
                      UI.info "LiveReload is waiting for a browser to connect."
         | 
| 70 50 | 
             
                    end
         | 
| 71 51 | 
             
                  end
         | 
| 72 52 |  | 
| 53 | 
            +
                  def _connect(ws)
         | 
| 54 | 
            +
                    UI.info "Browser connected."
         | 
| 55 | 
            +
                    ws.send MultiJson.encode(
         | 
| 56 | 
            +
                      command:    'hello',
         | 
| 57 | 
            +
                      protocols:  ['http://livereload.com/protocols/official-7'],
         | 
| 58 | 
            +
                      serverName: 'guard-livereload'
         | 
| 59 | 
            +
                    )
         | 
| 60 | 
            +
                    @web_sockets << ws
         | 
| 61 | 
            +
                  rescue
         | 
| 62 | 
            +
                    UI.error $!
         | 
| 63 | 
            +
                    UI.error $!.backtrace
         | 
| 64 | 
            +
                  end
         | 
| 65 | 
            +
             | 
| 66 | 
            +
                  def _disconnect(ws)
         | 
| 67 | 
            +
                    UI.info "Browser disconnected."
         | 
| 68 | 
            +
                    @web_sockets.delete(ws)
         | 
| 69 | 
            +
                  end
         | 
| 70 | 
            +
             | 
| 71 | 
            +
                  def _print_message(message)
         | 
| 72 | 
            +
                    message = MultiJson.decode(message)
         | 
| 73 | 
            +
                    UI.info "Browser URL: #{message['url']}" if message['command'] == 'url'
         | 
| 74 | 
            +
                  end
         | 
| 75 | 
            +
             | 
| 73 76 | 
             
                end
         | 
| 74 77 | 
             
              end
         | 
| 75 78 | 
             
            end
         | 
| @@ -1,28 +1,36 @@ | |
| 1 1 | 
             
            require 'eventmachine'
         | 
| 2 2 | 
             
            require 'em-websocket'
         | 
| 3 | 
            -
            require  | 
| 3 | 
            +
            require 'http/parser'
         | 
| 4 4 |  | 
| 5 5 | 
             
            module Guard
         | 
| 6 6 | 
             
              class LiveReload
         | 
| 7 7 | 
             
                class WebSocket < EventMachine::WebSocket::Connection
         | 
| 8 | 
            -
             | 
| 8 | 
            +
             | 
| 9 | 
            +
                  def dispatch(data)
         | 
| 9 10 | 
             
                    parser = Http::Parser.new
         | 
| 10 11 | 
             
                    parser << data
         | 
| 11 12 | 
             
                    if parser.http_method != 'GET' || parser.upgrade?
         | 
| 12 13 | 
             
                      super #pass the request to websocket
         | 
| 13 14 | 
             
                    elsif parser.request_path == '/livereload.js'
         | 
| 14 | 
            -
                       | 
| 15 | 
            +
                      _serve_file(_livereload_js_file)
         | 
| 15 16 | 
             
                    elsif File.exist?(parser.request_path[1..-1])
         | 
| 16 | 
            -
                       | 
| 17 | 
            +
                      _serve_file(parser.request_path[1..-1]) # Strip leading slash
         | 
| 17 18 | 
             
                    else
         | 
| 18 | 
            -
                      send_data | 
| 19 | 
            +
                      send_data("HTTP/1.1 404 Not Found\r\nContent-Type: text/plain\r\nContent-Length: 13\r\n\r\n404 Not Found")
         | 
| 19 20 | 
             
                      close_connection_after_writing
         | 
| 20 21 | 
             
                    end
         | 
| 21 22 | 
             
                  end
         | 
| 22 23 |  | 
| 23 | 
            -
                   | 
| 24 | 
            +
                  private
         | 
| 25 | 
            +
             | 
| 26 | 
            +
                  def _serve_file(path)
         | 
| 24 27 | 
             
                    UI.debug "Serving file #{path}"
         | 
| 25 | 
            -
                     | 
| 28 | 
            +
                    send_data "HTTP/1.1 200 OK\r\nContent-Type: #{_content_type(path)}\r\nContent-Length: #{File.size path}\r\n\r\n"
         | 
| 29 | 
            +
                    stream_file_data(path).callback { close_connection_after_writing }
         | 
| 30 | 
            +
                  end
         | 
| 31 | 
            +
             | 
| 32 | 
            +
                  def _content_type(path)
         | 
| 33 | 
            +
                    case File.extname(path)
         | 
| 26 34 | 
             
                    when '.css' then 'text/css'
         | 
| 27 35 | 
             
                    when '.js' then 'application/ecmascript'
         | 
| 28 36 | 
             
                    when '.gif' then 'image/gif'
         | 
| @@ -30,8 +38,10 @@ module Guard | |
| 30 38 | 
             
                    when '.png' then 'image/png'
         | 
| 31 39 | 
             
                    else; 'text/plain'
         | 
| 32 40 | 
             
                    end
         | 
| 33 | 
            -
             | 
| 34 | 
            -
             | 
| 41 | 
            +
                  end
         | 
| 42 | 
            +
             | 
| 43 | 
            +
                  def _livereload_js_file
         | 
| 44 | 
            +
                    File.expand_path("../../../../js/livereload.js", __FILE__)
         | 
| 35 45 | 
             
                  end
         | 
| 36 46 |  | 
| 37 47 | 
             
                end
         | 
| @@ -0,0 +1,38 @@ | |
| 1 | 
            +
            require 'spec_helper'
         | 
| 2 | 
            +
             | 
| 3 | 
            +
            describe Guard::LiveReload::Reactor do
         | 
| 4 | 
            +
              let(:paths) { %w[stylesheets/layout.css stylesheets/style.css] }
         | 
| 5 | 
            +
              before { Guard::UI.stub(:info) }
         | 
| 6 | 
            +
             | 
| 7 | 
            +
              describe "#reload_browser(paths = [])" do
         | 
| 8 | 
            +
                it "displays a message" do
         | 
| 9 | 
            +
                  expect(Guard::UI).to receive(:info).with("Reloading browser: stylesheets/layout.css stylesheets/style.css")
         | 
| 10 | 
            +
                  new_live_reactor.reload_browser(paths)
         | 
| 11 | 
            +
                end
         | 
| 12 | 
            +
             | 
| 13 | 
            +
                it "each web socket receives send with data containing default options for each path modified" do
         | 
| 14 | 
            +
                  reactor = new_live_reactor
         | 
| 15 | 
            +
                  paths.each do |path|
         | 
| 16 | 
            +
                    reactor.web_sockets.each do |ws|
         | 
| 17 | 
            +
                      expect(ws).to receive(:send).with(MultiJson.encode(['refresh', path: "#{Dir.pwd}/#{path}", apply_js_live: true, apply_css_live: true]))
         | 
| 18 | 
            +
                    end
         | 
| 19 | 
            +
                  end
         | 
| 20 | 
            +
                  reactor.reload_browser(paths)
         | 
| 21 | 
            +
                end
         | 
| 22 | 
            +
             | 
| 23 | 
            +
                it "each web socket receives send with data containing custom options for each path modified" do
         | 
| 24 | 
            +
                  reactor = new_live_reactor(apply_css_live: false, apply_js_live: false)
         | 
| 25 | 
            +
                  paths.each do |path|
         | 
| 26 | 
            +
                    reactor.web_sockets.each do |ws|
         | 
| 27 | 
            +
                      expect(ws).to receive(:send).with(MultiJson.encode(['refresh', path: "#{Dir.pwd}/#{path}", apply_js_live: false, apply_css_live: false]))
         | 
| 28 | 
            +
                    end
         | 
| 29 | 
            +
                  end
         | 
| 30 | 
            +
                  reactor.reload_browser(paths)
         | 
| 31 | 
            +
                end
         | 
| 32 | 
            +
              end
         | 
| 33 | 
            +
             | 
| 34 | 
            +
            end
         | 
| 35 | 
            +
             | 
| 36 | 
            +
            def new_live_reactor(options = {})
         | 
| 37 | 
            +
              Guard::LiveReload::Reactor.new({ api_version: '1.6', host: '0.0.0.0', port: '35729', apply_js_live: true, apply_css_live: true, grace_period: 0 }.merge(options))
         | 
| 38 | 
            +
            end
         | 
| @@ -0,0 +1,116 @@ | |
| 1 | 
            +
            require 'spec_helper'
         | 
| 2 | 
            +
             | 
| 3 | 
            +
            describe Guard::LiveReload do
         | 
| 4 | 
            +
              let(:plugin) { Guard::LiveReload.new }
         | 
| 5 | 
            +
              let(:reactor) { double(Guard::LiveReload::Reactor) }
         | 
| 6 | 
            +
              before { plugin.stub(:reactor) { reactor } }
         | 
| 7 | 
            +
             | 
| 8 | 
            +
              describe "#initialize" do
         | 
| 9 | 
            +
                describe ":host option" do
         | 
| 10 | 
            +
                  it "is '0.0.0.0' by default" do
         | 
| 11 | 
            +
                    plugin = Guard::LiveReload.new
         | 
| 12 | 
            +
                    expect(plugin.options[:host]).to eq '0.0.0.0'
         | 
| 13 | 
            +
                  end
         | 
| 14 | 
            +
             | 
| 15 | 
            +
                  it "can be set to '127.3.3.1'" do
         | 
| 16 | 
            +
                    plugin = Guard::LiveReload.new(host: '127.3.3.1')
         | 
| 17 | 
            +
                    expect(plugin.options[:host]).to eq '127.3.3.1'
         | 
| 18 | 
            +
                  end
         | 
| 19 | 
            +
                end
         | 
| 20 | 
            +
             | 
| 21 | 
            +
                describe ":port option" do
         | 
| 22 | 
            +
                  it "is '35729' by default" do
         | 
| 23 | 
            +
                    plugin = Guard::LiveReload.new
         | 
| 24 | 
            +
                    expect(plugin.options[:port]).to eq '35729'
         | 
| 25 | 
            +
                  end
         | 
| 26 | 
            +
             | 
| 27 | 
            +
                  it "can be set to '12345'" do
         | 
| 28 | 
            +
                    plugin = Guard::LiveReload.new(port: '12345')
         | 
| 29 | 
            +
                    expect(plugin.options[:port]).to eq '12345'
         | 
| 30 | 
            +
                  end
         | 
| 31 | 
            +
                end
         | 
| 32 | 
            +
             | 
| 33 | 
            +
                describe ":apply_css_live option" do
         | 
| 34 | 
            +
                  it "is true by default" do
         | 
| 35 | 
            +
                    plugin = Guard::LiveReload.new
         | 
| 36 | 
            +
                    expect(plugin.options[:apply_css_live]).to be_true
         | 
| 37 | 
            +
                  end
         | 
| 38 | 
            +
             | 
| 39 | 
            +
                  it "can be set to false" do
         | 
| 40 | 
            +
                    plugin = Guard::LiveReload.new(apply_css_live: false)
         | 
| 41 | 
            +
                    expect(plugin.options[:apply_css_live]).to be_false
         | 
| 42 | 
            +
                  end
         | 
| 43 | 
            +
                end
         | 
| 44 | 
            +
             | 
| 45 | 
            +
                describe ":override_url option" do
         | 
| 46 | 
            +
                  it "is false by default" do
         | 
| 47 | 
            +
                    plugin = Guard::LiveReload.new
         | 
| 48 | 
            +
                    expect(plugin.options[:override_url]).to be_false
         | 
| 49 | 
            +
                  end
         | 
| 50 | 
            +
             | 
| 51 | 
            +
                  it "can be set to false" do
         | 
| 52 | 
            +
                    plugin = Guard::LiveReload.new(override_url: true)
         | 
| 53 | 
            +
                    expect(plugin.options[:override_url]).to be_true
         | 
| 54 | 
            +
                  end
         | 
| 55 | 
            +
                end
         | 
| 56 | 
            +
             | 
| 57 | 
            +
                describe ":grace_period option" do
         | 
| 58 | 
            +
                  it "is 0 by default" do
         | 
| 59 | 
            +
                    plugin = Guard::LiveReload.new
         | 
| 60 | 
            +
                    expect(plugin.options[:grace_period]).to eq 0
         | 
| 61 | 
            +
                  end
         | 
| 62 | 
            +
             | 
| 63 | 
            +
                  it "can be set to 0.5" do
         | 
| 64 | 
            +
                    plugin = Guard::LiveReload.new(grace_period: 0.5)
         | 
| 65 | 
            +
                    expect(plugin.options[:grace_period]).to eq 0.5
         | 
| 66 | 
            +
                  end
         | 
| 67 | 
            +
                end
         | 
| 68 | 
            +
              end
         | 
| 69 | 
            +
             | 
| 70 | 
            +
              describe "#start" do
         | 
| 71 | 
            +
                it "creates reactor with default options" do
         | 
| 72 | 
            +
                  plugin = Guard::LiveReload.new
         | 
| 73 | 
            +
                  expect(Guard::LiveReload::Reactor).to receive(:new).with(
         | 
| 74 | 
            +
                    host:           '0.0.0.0',
         | 
| 75 | 
            +
                    port:           '35729',
         | 
| 76 | 
            +
                    apply_css_live: true,
         | 
| 77 | 
            +
                    override_url:   false,
         | 
| 78 | 
            +
                    grace_period:  0
         | 
| 79 | 
            +
                  )
         | 
| 80 | 
            +
                  plugin.start
         | 
| 81 | 
            +
                end
         | 
| 82 | 
            +
             | 
| 83 | 
            +
                it "creates reactor with given options" do
         | 
| 84 | 
            +
                  plugin = Guard::LiveReload.new(host: '127.3.3.1', port: '12345', apply_css_live: false, override_url: true, grace_period: 1)
         | 
| 85 | 
            +
                  expect(Guard::LiveReload::Reactor).to receive(:new).with(
         | 
| 86 | 
            +
                    host:           '127.3.3.1',
         | 
| 87 | 
            +
                    port:           '12345',
         | 
| 88 | 
            +
                    apply_css_live: false,
         | 
| 89 | 
            +
                    override_url:   true,
         | 
| 90 | 
            +
                    grace_period:   1
         | 
| 91 | 
            +
                  )
         | 
| 92 | 
            +
                  plugin.start
         | 
| 93 | 
            +
                end
         | 
| 94 | 
            +
              end
         | 
| 95 | 
            +
             | 
| 96 | 
            +
              describe "#stop" do
         | 
| 97 | 
            +
                it "stops the reactor" do
         | 
| 98 | 
            +
                  expect(reactor).to receive(:stop)
         | 
| 99 | 
            +
                  plugin.stop
         | 
| 100 | 
            +
                end
         | 
| 101 | 
            +
              end
         | 
| 102 | 
            +
             | 
| 103 | 
            +
              describe "#run_on_changes" do
         | 
| 104 | 
            +
                it "reloads browser" do
         | 
| 105 | 
            +
                  expect(reactor).to receive(:reload_browser).with(['foo'])
         | 
| 106 | 
            +
                  plugin.run_on_changes(['foo'])
         | 
| 107 | 
            +
                end
         | 
| 108 | 
            +
             | 
| 109 | 
            +
                it "can wait 0.5 seconds before reloading the browser" do
         | 
| 110 | 
            +
                  expect(reactor).to receive(:reload_browser).with(['foo'])
         | 
| 111 | 
            +
                  expect(plugin).to receive(:sleep).with(0.5)
         | 
| 112 | 
            +
                  plugin.options[:grace_period] = 0.5
         | 
| 113 | 
            +
                  plugin.run_on_changes(['foo'])
         | 
| 114 | 
            +
                end
         | 
| 115 | 
            +
              end
         | 
| 116 | 
            +
            end
         | 
    
        data/spec/spec_helper.rb
    ADDED
    
    | @@ -0,0 +1,12 @@ | |
| 1 | 
            +
            require 'coveralls'
         | 
| 2 | 
            +
            Coveralls.wear!
         | 
| 3 | 
            +
             | 
| 4 | 
            +
            require 'rspec'
         | 
| 5 | 
            +
            require 'guard/livereload'
         | 
| 6 | 
            +
            ENV["GUARD_ENV"] = 'test'
         | 
| 7 | 
            +
             | 
| 8 | 
            +
            RSpec.configure do |config|
         | 
| 9 | 
            +
              config.color_enabled = true
         | 
| 10 | 
            +
              config.filter_run focus: true
         | 
| 11 | 
            +
              config.run_all_when_everything_filtered = true
         | 
| 12 | 
            +
            end
         | 
    
        metadata
    CHANGED
    
    | @@ -1,59 +1,73 @@ | |
| 1 1 | 
             
            --- !ruby/object:Gem::Specification
         | 
| 2 2 | 
             
            name: guard-livereload
         | 
| 3 3 | 
             
            version: !ruby/object:Gem::Version
         | 
| 4 | 
            -
              version:  | 
| 4 | 
            +
              version: 2.0.0
         | 
| 5 5 | 
             
            platform: ruby
         | 
| 6 6 | 
             
            authors:
         | 
| 7 7 | 
             
            - Thibaud Guillaume-Gentil
         | 
| 8 8 | 
             
            autorequire: 
         | 
| 9 9 | 
             
            bindir: bin
         | 
| 10 10 | 
             
            cert_chain: []
         | 
| 11 | 
            -
            date: 2013- | 
| 11 | 
            +
            date: 2013-10-06 00:00:00.000000000 Z
         | 
| 12 12 | 
             
            dependencies:
         | 
| 13 13 | 
             
            - !ruby/object:Gem::Dependency
         | 
| 14 14 | 
             
              name: guard
         | 
| 15 15 | 
             
              requirement: !ruby/object:Gem::Requirement
         | 
| 16 16 | 
             
                requirements:
         | 
| 17 | 
            -
                - -  | 
| 17 | 
            +
                - - ~>
         | 
| 18 18 | 
             
                  - !ruby/object:Gem::Version
         | 
| 19 | 
            -
                    version:  | 
| 19 | 
            +
                    version: '2.0'
         | 
| 20 20 | 
             
              type: :runtime
         | 
| 21 21 | 
             
              prerelease: false
         | 
| 22 22 | 
             
              version_requirements: !ruby/object:Gem::Requirement
         | 
| 23 23 | 
             
                requirements:
         | 
| 24 | 
            -
                - -  | 
| 24 | 
            +
                - - ~>
         | 
| 25 25 | 
             
                  - !ruby/object:Gem::Version
         | 
| 26 | 
            -
                    version:  | 
| 26 | 
            +
                    version: '2.0'
         | 
| 27 27 | 
             
            - !ruby/object:Gem::Dependency
         | 
| 28 28 | 
             
              name: em-websocket
         | 
| 29 29 | 
             
              requirement: !ruby/object:Gem::Requirement
         | 
| 30 30 | 
             
                requirements:
         | 
| 31 | 
            -
                - -  | 
| 31 | 
            +
                - - ~>
         | 
| 32 32 | 
             
                  - !ruby/object:Gem::Version
         | 
| 33 | 
            -
                    version: 0.5 | 
| 33 | 
            +
                    version: '0.5'
         | 
| 34 34 | 
             
              type: :runtime
         | 
| 35 35 | 
             
              prerelease: false
         | 
| 36 36 | 
             
              version_requirements: !ruby/object:Gem::Requirement
         | 
| 37 37 | 
             
                requirements:
         | 
| 38 | 
            -
                - -  | 
| 38 | 
            +
                - - ~>
         | 
| 39 39 | 
             
                  - !ruby/object:Gem::Version
         | 
| 40 | 
            -
                    version: 0.5 | 
| 40 | 
            +
                    version: '0.5'
         | 
| 41 41 | 
             
            - !ruby/object:Gem::Dependency
         | 
| 42 42 | 
             
              name: multi_json
         | 
| 43 43 | 
             
              requirement: !ruby/object:Gem::Requirement
         | 
| 44 44 | 
             
                requirements:
         | 
| 45 45 | 
             
                - - ~>
         | 
| 46 46 | 
             
                  - !ruby/object:Gem::Version
         | 
| 47 | 
            -
                    version: '1. | 
| 47 | 
            +
                    version: '1.8'
         | 
| 48 48 | 
             
              type: :runtime
         | 
| 49 49 | 
             
              prerelease: false
         | 
| 50 50 | 
             
              version_requirements: !ruby/object:Gem::Requirement
         | 
| 51 51 | 
             
                requirements:
         | 
| 52 52 | 
             
                - - ~>
         | 
| 53 53 | 
             
                  - !ruby/object:Gem::Version
         | 
| 54 | 
            -
                    version: '1. | 
| 54 | 
            +
                    version: '1.8'
         | 
| 55 55 | 
             
            - !ruby/object:Gem::Dependency
         | 
| 56 56 | 
             
              name: bundler
         | 
| 57 | 
            +
              requirement: !ruby/object:Gem::Requirement
         | 
| 58 | 
            +
                requirements:
         | 
| 59 | 
            +
                - - '>='
         | 
| 60 | 
            +
                  - !ruby/object:Gem::Version
         | 
| 61 | 
            +
                    version: 1.3.5
         | 
| 62 | 
            +
              type: :development
         | 
| 63 | 
            +
              prerelease: false
         | 
| 64 | 
            +
              version_requirements: !ruby/object:Gem::Requirement
         | 
| 65 | 
            +
                requirements:
         | 
| 66 | 
            +
                - - '>='
         | 
| 67 | 
            +
                  - !ruby/object:Gem::Version
         | 
| 68 | 
            +
                    version: 1.3.5
         | 
| 69 | 
            +
            - !ruby/object:Gem::Dependency
         | 
| 70 | 
            +
              name: rake
         | 
| 57 71 | 
             
              requirement: !ruby/object:Gem::Requirement
         | 
| 58 72 | 
             
                requirements:
         | 
| 59 73 | 
             
                - - '>='
         | 
| @@ -82,22 +96,31 @@ dependencies: | |
| 82 96 | 
             
                    version: '0'
         | 
| 83 97 | 
             
            description: Guard::LiveReload automatically reloads your browser when 'view' files
         | 
| 84 98 | 
             
              are modified.
         | 
| 85 | 
            -
            email:
         | 
| 86 | 
            -
            - thibaud@thibaud.me
         | 
| 99 | 
            +
            email: thibaud@thibaud.me
         | 
| 87 100 | 
             
            executables: []
         | 
| 88 101 | 
             
            extensions: []
         | 
| 89 102 | 
             
            extra_rdoc_files: []
         | 
| 90 103 | 
             
            files:
         | 
| 104 | 
            +
            - .gitignore
         | 
| 105 | 
            +
            - .travis.yml
         | 
| 106 | 
            +
            - Gemfile
         | 
| 107 | 
            +
            - Guardfile
         | 
| 108 | 
            +
            - LICENSE.txt
         | 
| 109 | 
            +
            - README.md
         | 
| 110 | 
            +
            - Rakefile
         | 
| 111 | 
            +
            - guard-livereload.gemspec
         | 
| 112 | 
            +
            - js/livereload.js
         | 
| 113 | 
            +
            - lib/guard/livereload.rb
         | 
| 91 114 | 
             
            - lib/guard/livereload/reactor.rb
         | 
| 92 115 | 
             
            - lib/guard/livereload/templates/Guardfile
         | 
| 93 116 | 
             
            - lib/guard/livereload/version.rb
         | 
| 94 117 | 
             
            - lib/guard/livereload/websocket.rb
         | 
| 95 | 
            -
            - lib/guard/livereload.rb
         | 
| 96 | 
            -
            -  | 
| 97 | 
            -
            -  | 
| 98 | 
            -
             | 
| 99 | 
            -
             | 
| 100 | 
            -
             | 
| 118 | 
            +
            - spec/lib/guard/livereload/reactor_spec.rb
         | 
| 119 | 
            +
            - spec/lib/guard/livereload_spec.rb
         | 
| 120 | 
            +
            - spec/spec_helper.rb
         | 
| 121 | 
            +
            homepage: https://rubygems.org/gems/guard-livereload
         | 
| 122 | 
            +
            licenses:
         | 
| 123 | 
            +
            - MIT
         | 
| 101 124 | 
             
            metadata: {}
         | 
| 102 125 | 
             
            post_install_message: 
         | 
| 103 126 | 
             
            rdoc_options: []
         | 
| @@ -112,11 +135,14 @@ required_rubygems_version: !ruby/object:Gem::Requirement | |
| 112 135 | 
             
              requirements:
         | 
| 113 136 | 
             
              - - '>='
         | 
| 114 137 | 
             
                - !ruby/object:Gem::Version
         | 
| 115 | 
            -
                  version:  | 
| 138 | 
            +
                  version: '0'
         | 
| 116 139 | 
             
            requirements: []
         | 
| 117 | 
            -
            rubyforge_project:  | 
| 118 | 
            -
            rubygems_version: 2. | 
| 140 | 
            +
            rubyforge_project: 
         | 
| 141 | 
            +
            rubygems_version: 2.1.3
         | 
| 119 142 | 
             
            signing_key: 
         | 
| 120 143 | 
             
            specification_version: 4
         | 
| 121 | 
            -
            summary: Guard  | 
| 122 | 
            -
            test_files: | 
| 144 | 
            +
            summary: Guard plugin for livereload
         | 
| 145 | 
            +
            test_files:
         | 
| 146 | 
            +
            - spec/lib/guard/livereload/reactor_spec.rb
         | 
| 147 | 
            +
            - spec/lib/guard/livereload_spec.rb
         | 
| 148 | 
            +
            - spec/spec_helper.rb
         |