Module: Roda::RodaPlugins::LiveReload
- Defined in:
- lib/roda/plugins/live_reload.rb
Overview
The live_reload plugin provides a chunked-body endpoint and injects a long-polling JavaScript function just before the closing body tag.
plugin :live_reload
route do |r|
r.live_reload
end
Plugin Options
The following plugin options are supported:
- :watch
-
Array of folders to watch. Defaults to
assets,views
Defined Under Namespace
Modules: RequestMethods, ResponseMethods
Class Method Summary collapse
-
.configure(app, opts = {}) ⇒ Object
:nodoc:.
-
.listeners ⇒ Object
:nodoc:.
-
.load_dependencies(app, opts = {}) ⇒ Object
:nodoc:.
-
.mutex ⇒ Object
:nodoc:.
-
.synchronize ⇒ Object
:nodoc:.
Class Method Details
.configure(app, opts = {}) ⇒ Object
:nodoc:
98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 |
# File 'lib/roda/plugins/live_reload.rb', line 98 def self.configure(app, opts = {}) # :nodoc: watch = opts.delete(:watch) || ["assets", "views"] puts "Watching #{watch} for changes" listener = Listen.to(*watch) do |modified, added, removed| puts "Changes", modified, added, removed LiveReload.listeners.each do |writer| writer.puts "Changes" end end listener.start end |
.listeners ⇒ Object
:nodoc:
90 91 92 |
# File 'lib/roda/plugins/live_reload.rb', line 90 def self.listeners # :nodoc: @listeners ||= [] end |
.load_dependencies(app, opts = {}) ⇒ Object
:nodoc:
94 95 96 |
# File 'lib/roda/plugins/live_reload.rb', line 94 def self.load_dependencies(app, opts = {}) # :nodoc: app.plugin :streaming end |
.mutex ⇒ Object
:nodoc:
82 83 84 |
# File 'lib/roda/plugins/live_reload.rb', line 82 def self.mutex # :nodoc: @mutex ||= Mutex.new end |
.synchronize ⇒ Object
:nodoc:
86 87 88 |
# File 'lib/roda/plugins/live_reload.rb', line 86 def self.synchronize # :nodoc: mutex.synchronize { yield } end |