Class: Jekyll::Reload::Server
- Inherits:
-
EventMachine::WebSocket::Connection
- Object
- EventMachine::WebSocket::Connection
- Jekyll::Reload::Server
- Extended by:
- Forwardable::Extended
- Defined in:
- lib/jekyll/reload/server.rb
Constant Summary collapse
- PATH =
"/livereload.js"
Instance Method Summary collapse
-
#asset?(path) ⇒ Boolean
–.
-
#dispatch(data) ⇒ Object
–.
-
#do_200 ⇒ Object
–.
-
#do_404 ⇒ Object
–.
-
#do_jekyll_asset_200(path) ⇒ Object
– Serve from Jekyll-Assets.
Instance Method Details
#asset?(path) ⇒ Boolean
–
66 67 68 69 70 |
# File 'lib/jekyll/reload/server.rb', line 66 def asset?(path) return false unless path.query CGI.parse(path.query).key?("sha") && path.path == PATH end |
#dispatch(data) ⇒ Object
–
19 20 21 22 23 24 25 26 27 |
# File 'lib/jekyll/reload/server.rb', line 19 def dispatch(data) parser = Http::Parser.new.tap { |o| o << data } return super if parser.http_method != "GET" \ || parser.upgrade? path = URI.parse(parser.request_url) return do_jekyll_asset_200(path) if asset?(path) path.path == PATH ? do_200 : do_404 end |
#do_200 ⇒ Object
–
58 59 60 61 62 63 |
# File 'lib/jekyll/reload/server.rb', line 58 def do_200 content = Pathutil.new(__dir__).join("vendor", "livereload.js") complete_with(content, { status: 200, }) end |
#do_404 ⇒ Object
–
51 52 53 54 55 |
# File 'lib/jekyll/reload/server.rb', line 51 def do_404 complete_with(err_content, { status: 404, }) end |
#do_jekyll_asset_200(path) ⇒ Object
Note:
You can override our vendor’d LiveReload.js with your own, if you put it in your ‘_assets/js` folder.
– Serve from Jekyll-Assets. –
35 36 37 38 39 40 41 42 43 44 45 46 47 48 |
# File 'lib/jekyll/reload/server.rb', line 35 def do_jekyll_asset_200(path) sha = CGI.parse(path.query).fetch("sha").first content = Pathutil.new(jekyll.in_dest_dir(jekyll.sprockets.prefix_url)) content = content.join(path.path). content = content.sub_ext("-#{sha}.js") if content.in_path?(jekyll.in_dest_dir) complete_with(content, { status: 200, }) else do_404 end end |