Permalink
Browse files

reload assets/use Turbolinks for template changes

  • Loading branch information...
1 parent 5b75393 commit 9ac341c536c26759c78a79fab860a0715ac4c8c0 @collin collin committed Oct 16, 2012
Showing with 29 additions and 3 deletions.
  1. +1 −0 Gemfile
  2. +2 −0 Gemfile.lock
  3. +18 −1 app/assets/javascripts/application.js
  4. +7 −2 app/controllers/browser_controller.rb
  5. +1 −0 config/application.rb
View
@@ -11,6 +11,7 @@ gem 'redis'
gem 'tusk'
gem 'listen'
gem 'rb-fsevent', '~> 0.9.1'
+gem 'turbolinks'
# Gems used only for assets and not required
# in production environments by default.
View
@@ -134,6 +134,7 @@ GEM
treetop (1.4.10)
polyglot
polyglot (>= 0.3.1)
+ turbolinks (0.5.1)
tusk (1.1.0)
tzinfo (0.3.33)
uglifier (1.3.0)
@@ -158,5 +159,6 @@ DEPENDENCIES
sass-rails!
sprockets-rails!
sqlite3
+ turbolinks
tusk
uglifier (>= 1.0.3)
@@ -13,14 +13,31 @@
//= require jquery
//= require jquery_ujs
//= require_tree .
+//= require turbolinks
jQuery(document).ready(function() {
setTimeout(function() {
var source = new EventSource('/control');
// if we get a reload command, reload the page
source.addEventListener('reload', function(e) {
- window.location.reload();
+ Turbolinks.visit(window.location);
});
+
+ // if we get a reload-styles command, reload the css
+ source.addEventListener('reload-styles', function(e) {
+ var sheets = $("[rel=stylesheet]");
+ sheets.each(function() {
+ var sheet = $(this);
+ var clone = sheet.clone()
+ clone.appendTo(document.head);
+ clone.on('load', function() {
+ setTimeout(20, function() {
+ sheet.remove();
+ });
+ });
+ });
+ });
+
}, 1);
});
@@ -46,7 +46,12 @@ def index
@listener.change do |modified, added, removed|
# When something changes, send an SSE
modified.each do |modification|
- @sse.write({ 'changed' => modification }, :event => 'reload')
+ event = if modification =~ /stylesheets/
+ 'reload-styles'
+ else
+ 'reload'
+ end
+ @sse.write({ 'changed' => modification }, :event => event)
end
end
@listener.start
@@ -85,8 +90,8 @@ def heartbeat
Thread.new do
begin
loop do
+ sleep 5
@sse.write({ 'ping' => Time.now }, :event => 'ping')
- sleep 1
end
rescue IOError
cleanup
View
@@ -11,6 +11,7 @@
module Lolwut
class Application < Rails::Application
+ config.middleware.delete Rack::Lock
# Settings in config/environments/* take precedence over those specified here.
# Application configuration should go into files in config/initializers
# -- all .rb files in that directory are automatically loaded.

0 comments on commit 9ac341c

Please sign in to comment.