Sha256: 2fc47d1ac28f7766bdd4c857be1ab6aa49b3f8e88a4b2dbad0fdd9a16f76c47f
Contents?: true
Size: 1.96 KB
Versions: 1
Compression:
Stored size: 1.96 KB
Contents
require 'rack/livereload' require 'middleman-livereload/reactor' module Middleman class LiveReloadExtension < Extension option :host, '0.0.0.0', 'Host to bind LiveReload API server to' option :port, '35729', 'Port to bind the LiveReload API server to' option :apply_js_live, true, 'Apply JS changes live, without reloading' option :apply_css_live, true, 'Apply CSS changes live, without reloading' option :grace_period, 0, 'Time (in seconds) to wait before reloading' option :no_swf, false, 'Disable Flash WebSocket polyfill for browsers that support native WebSockets' def initialize(app, options_hash={}, &block) super return if app.environment != :development @reactor = nil grace_period = options.grace_period port = options.port.to_i host = options.host no_swf = options.no_swf options_hash = options.to_h app.ready do if @reactor @reactor.app = self else @reactor = ::Middleman::LiveReload::Reactor.new(options_hash, self) end files.changed do |file| next if ignore_manager.ignored?(file) sleep(grace_period) if grace_period > 0 sitemap.ensure_resource_list_updated! puts "Changed! #{file}" begin file_url = sitemap.file_to_path(file) file_resource = sitemap.find_resource_by_path(file_url) reload_path = file_resource.destination_path rescue reload_path = "#{Dir.pwd}/#{file}" end @reactor.reload_browser(reload_path) end files.deleted do |file| next if ignore_manager.ignored?(file) sleep(grace_period) if grace_period > 0 sitemap.ensure_resource_list_updated! puts "Deleted! #{file}" @reactor.reload_browser("#{Dir.pwd}/#{file}") end use ::Rack::LiveReload, :port => port, :host => host, :no_swf => no_swf end end end end
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
middleman-livereload-3.2.1 | lib/middleman-livereload/extension_3_1.rb |