public
Last active

loading_notice

  • Download Gist
loading_notice.template.rb
Ruby
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66
#
# prove of concept application for loading_notice rails-plugin (http://github.com/thomd/loading_notice)
#
# usage:
# rails loading-notice-demo -m http://gist.github.com/156145.txt
#
 
 
# loading_notice plugin
plugin 'loading_notice', :git => 'git://github.com/thomd/loading_notice.git'
rake('loading_notice:install')
 
 
# generators
run "rm public/index.html"
generate :controller, 'time'
route "map.root :controller => 'time'"
 
 
# generate time controller
file "app/controllers/time_controller.rb", <<-HTML
class TimeController < ApplicationController
 
def index
end
 
def now
render :text => current_time
end
 
def now_delayed
sleep 2
render :text => current_time
end
 
private
 
def current_time
"<p>Time is <em>#{DateTime.now.to_s}</em> now.</p>"
end
end
HTML
 
 
# generate layout template
file "app/views/layouts/time.html.erb", <<-HTML
<!DOCTYPE html>
<html>
<head>
<title>Proof of Concept 'loading_notice'</title>
<%= javascript_include_tag :defaults, 'loading_notice' %>
<%= stylesheet_link_tag 'loading_notice' %>
</head>
<body>
<%= yield %>
</body>
</html>
HTML
 
 
# generate index view
file "app/views/time/index.html.erb", <<-HTML
<%= link_to_remote "get time", :update => "times", :url => {:controller => "time", :action => "now"}, :position => "after" %> |
<%= link_to_remote "get time 2 seconds delayed", :update => "times", :url => {:controller => "time", :action => "now_delayed"}, :position => "after" %>
<div id="times"></div>
HTML

Please sign in to comment on this gist.

Something went wrong with that request. Please try again.