Class: Jekyll::Reload::Reactor
- Inherits:
-
Object
- Object
- Jekyll::Reload::Reactor
- Extended by:
- Forwardable::Extended
- Defined in:
- lib/jekyll/reload/reactor.rb
Instance Attribute Summary collapse
-
#jekyll ⇒ Object
readonly
Returns the value of attribute jekyll.
-
#wsc ⇒ Object
readonly
Returns the value of attribute wsc.
Instance Method Summary collapse
-
#initialize(jekyll) ⇒ Reactor
constructor
–.
-
#paths ⇒ Object
–.
-
#reload ⇒ Object
–.
-
#running? ⇒ Boolean
–.
-
#start ⇒ Object
–.
-
#stop ⇒ Object
–.
Constructor Details
#initialize(jekyll) ⇒ Reactor
–
18 19 20 |
# File 'lib/jekyll/reload/reactor.rb', line 18 def initialize(jekyll) @jekyll, @wsc = jekyll, [] end |
Instance Attribute Details
#jekyll ⇒ Object (readonly)
Returns the value of attribute jekyll.
11 12 13 |
# File 'lib/jekyll/reload/reactor.rb', line 11 def jekyll @jekyll end |
#wsc ⇒ Object (readonly)
Returns the value of attribute wsc.
11 12 13 |
# File 'lib/jekyll/reload/reactor.rb', line 11 def wsc @wsc end |
Instance Method Details
#paths ⇒ Object
–
68 69 70 71 |
# File 'lib/jekyll/reload/reactor.rb', line 68 def paths (jekyll.pages + jekyll.posts.docs + jekyll.documents) .uniq.map(&:path) end |
#reload ⇒ Object
–
54 55 56 57 58 59 60 61 62 63 64 65 |
# File 'lib/jekyll/reload/reactor.rb', line 54 def reload Jekyll.logger.debug("Reloader: ", "reloaded at #{Time.now}") paths.map do |v| @wsc.each do |sv| sv.send(JSON.dump({ liveCSS: true, command: "reload", path: v, })) end end end |
#running? ⇒ Boolean
–
30 31 32 |
# File 'lib/jekyll/reload/reactor.rb', line 30 def running? @thread&.alive? end |
#start ⇒ Object
–
35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 |
# File 'lib/jekyll/reload/reactor.rb', line 35 def start Thread.abort_on_exception = true @thread = Thread.new do EventMachine.run do o = { jekyll: jekyll, } a = jekyll.config["reloader"].values_at("host", "port") Jekyll.logger.info("Reloader at: ", "http://#{a[0]}:#{a[1]}") EventMachine.start_server(a[0], a[1], Server, o) do |w| w.onclose { |_| disconnect(w) } w.onopen { |v| connect(w, v) } end end end end |
#stop ⇒ Object
–
23 24 25 26 27 |
# File 'lib/jekyll/reload/reactor.rb', line 23 def stop @thread&.kill Jekyll.logger.debug("Reloader:", "stopped") end |