Sha256: 0683ea982050764fc526dab02551cda556a87a787174b54a7f7fa796722034f3

Contents?: true

Size: 929 Bytes

Versions: 1

Compression:

Stored size: 929 Bytes

Contents

require 'guard/compat/plugin'

module Guard
  class LiveReload < Plugin
    require 'guard/livereload/websocket'
    require 'guard/livereload/reactor'
    require 'guard/livereload/snippet'

    attr_accessor :reactor, :options

    def initialize(options = {})
      super

      js_path = File.expand_path('../../../js/livereload.js.erb', __FILE__)
      @options = {
        host:           '0.0.0.0',
        port:           '35729',
        apply_css_live: true,
        override_url:   false,
        grace_period:   0,
        js_template: js_path
      }.merge(options)

      js_path = @options[:js_template]
      @options[:livereload_js_path] = Snippet.new(js_path, @options).path
    end

    def start
      @reactor = Reactor.new(options)
    end

    def stop
      reactor.stop
    end

    def run_on_modifications(paths)
      sleep options[:grace_period]
      reactor.reload_browser(paths)
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
guard-livereload-2.5.0 lib/guard/livereload.rb