Skip to content

Instantly share code, notes, and snippets.

@damphyr
Created October 15, 2010 11:42
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save damphyr/628059 to your computer and use it in GitHub Desktop.
Save damphyr/628059 to your computer and use it in GitHub Desktop.
A simple extensible Sinatra application for use as an information radiator
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"
"http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
<meta http-equiv="Content-type" content="text/html; charset=utf-8">
<title><%= title %></title>
<script src="/js/drawing_methods.js"></script>
</head>
<body id="body" onload="<%= drawing_function %>">
<canvas id="canvas" style="border: 1px solid;" width="320" height="400">Canvas support required</canvas>
</body>
</html>
//fills text in the given coordinates.
//if color, or font are null the current color or font of the
//context is used
function printText(msg,x,y,ctx,color,font)
{
if (color != null)
{
ctx.fillStyle= color;
}
if (font!=null)
{
ctx.font=font
}
ctx.fillText(msg,x,y)
}
//Brings up an error message under the title heading
function error(title,msg,timeout)
{
var canvas = document.getElementById('canvas');
var ctx = canvas.getContext('2d');
var width = document.documentElement.clientWidth;
var height = document.documentElement.clientHeight;
canvas.width=width-16
canvas.height=height-23
ctx.save();
//background
ctx.fillStyle = 'black';
ctx.fillRect(0, 0, width, height);
//the title
printText(title,30,50,ctx,'orange',"25pt Sanserif");
//change coordinates to bring 0,0 in the center left
ctx.translate(0, height/2);
//the message
printText(msg,100,0,ctx,"red","20pt Verdana");
//refresh
setTimeout("location.reload(true);",timeout)
}
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"
"http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
<meta http-equiv="Content-type" content="text/html; charset=utf-8">
<title><%= title %></title>
</head>
<body id="body">
<ul>
<% plugins.each do |plug|%>
<li><a href="/<%= plug %>"><%= plug %></a></li>
<% end %>
</ul>
</body>
</html>
$:.unshift File.join(File.dirname(__FILE__),"..")
require 'sinatra'
require 'rake'
#load every file you find in the plugins directory
plugins=FileList["#{File.join(File.dirname(__FILE__),'plugins')}/*.rb"]
plugins.each{ |plugin| require plugin }
module InformationRadiator
class RadiatorApp<Sinatra::Base
PLUGINS = [Plugins::Issues,Plugins::UserTasks,Plugins::Builds,Plugins::Todo]
attr_reader :title,:drawing_function
get '/:plugin' do |plug|
#if there is a parameter, use it to get the plug-in class
#but only if it is in our list
if plug && plugins.include?(plug)
plugin=Plugins.const_get("#{plug}")
else
#get the cookie and use it as an index to get the next plugin
cookie = request.cookies['radiator'].to_i
cookie||= 0
cookie=0 if cookie>=PLUGINS.length
plugin=PLUGINS[cookie]
cookie+=1
cookie=0 if cookie>=PLUGINS.length
response.set_cookie('radiator',cookie)
end
@title="Information Radiator #{plugin}"
@drawing_function=plugin.new(settings.config).drawing_function
erb :canvas
end
get '/info/index' do
erb :index
end
def plugins
@plugins||=[]
PLUGINS.each do |plug|
@plugins<<plug.name.split('::').last
end
return @plugins
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment