Sha256: 7a232d29a45e7d688b10ce9e80cbc86ca8a7c39b8b2f5d73a88a19d777b144ce
Contents?: true
Size: 1.03 KB
Versions: 1
Compression:
Stored size: 1.03 KB
Contents
require 'sinatra/base' require 'sinatra/liveviews/version' require_relative './liveviews/page-websocket' require_relative '../sequel/sequel-extensions' module LivePages def live(url, options = {}, &block) method_name = _method_name 'LIVE', url _register_callback method_name, &block end def _method_name(verb, url) "#{verb} #{url}".to_sym end def _register_callback(method_name, &block) self.send :define_method, method_name, &block end def self.registered(app) app.get '/sinatra/liveviews/ws' do return 'websockets only' if !request.websocket? request.websocket do |ws| PageWebSocket.new ws, { :app => self, :url => params[:url] || request.referrer } end end app.get '/sinatra/liveviews.js' do folder = File.join File.dirname(__FILE__), './js/' js = ['extensions.js', 'socket.js', 'live-pages.js'].map do |file| path = File.join folder, file File.read path end return 200, {'Content-type' => 'text/javascript'}, js.join("\n") end end end module Sinatra register LivePages end
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
sinatra-liveviews-0.5.0 | lib/sinatra/liveviews.rb |