Skip to content

Instantly share code, notes, and snippets.

@vikhyat
Created April 27, 2009 07:00
Show Gist options
  • Save vikhyat/102368 to your computer and use it in GitHub Desktop.
Save vikhyat/102368 to your computer and use it in GitHub Desktop.
sinatra
haml
require './dereferer.rb'
run Sinatra::Application
require 'rubygems'
require 'sinatra'
require 'uri'
enable :inline_templates
# Quick test
get '/' do
haml :index
end
get '/*' do
# Correct http:/something
uri = params[:splat][0].sub('/','//')
@uri = URI.parse uri
# Is the URI valid? Does it have a host?
raise 'Invalid URL' if @uri.host.nil?
# Add a scheme if they didn't give us one
@uri.scheme = 'http' if @uri.scheme.nil?
@url = @uri.to_s
# redirect uri.to_s
haml :redirect
end
error do
@error = request.env['sinatra.error'].to_s
haml :error
end
__END__
@@layout
%html
%head
%title Acies (Derefering service)
%link{ :rel => 'stylesheet', :href => 'http://www.w3.org/StyleSheets/Core/Swiss', :type => 'text/css' }
%body
%h1 Welcome to Acies!
= yield
%div{:style => 'font-size: 0.8em;padding:10px;padding-left:25px'}
Acies is a derefering service | Created by
%a{ :href => 'http://aetus.net/' } Aetus Designs
| Depends upon Javascript
@@index
%div{:style => 'padding:15px;'}
%form{ :onsubmit => 'window.location.href += document.forms[0].elements[0].value;return false;' }
Enter your favorite URL:
%input{ :type => 'text', :name => 'url' }
%input{ :type => 'button', :value => 'go!', :onclick => 'window.location.href += document.forms[0].elements[0].value' }
@@redirect
:javascript
uri = '#{@uri}';
function redirect(url) {
window.location.href = url;
}
setTimeout("redirect('" + uri + "')", 5000);
%div{:style => 'padding:15px;'}
Redirecting to
%a{ :href => @uri }
= @uri
@@error
%div{:style => 'padding:15px;'}
Sorry, there was an error -
= @error
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment