-
-
Save yb66/4585772 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'sinatra' | |
require 'haml' | |
class Something | |
def self.all( h= {} ) | |
[] | |
end | |
def self.get( id=1 ) | |
obj = Object.new | |
class << obj | |
def date | |
Time.now | |
end | |
def value | |
"something" | |
end | |
end | |
obj | |
end | |
end | |
configure do | |
enable :inline_templates | |
end | |
helpers do | |
def logged_in? | |
false | |
end | |
end | |
get '/' do | |
if logged_in? | |
@variable = Something.all(:user => current_user.id) | |
@title = "Home" | |
else | |
@variable = Something.all | |
@title = "Home (not logged in)" | |
end | |
haml :home | |
end | |
get '/:id' do |id| | |
@variable = Something.get id | |
@title = "Stuff ##{params[:id]}" | |
haml :show_stuff | |
end | |
__END__ | |
@@layout | |
%html | |
%head | |
%title= @title | |
%body | |
= "@variable = #{@variable.inspect}" | |
= yield | |
@@home | |
%h1 | |
Home | |
@@show_stuff | |
%p | |
="The value for #{@variable.date.strftime('%d %b %Y')} is #{@variable.value}. Do you wish to" | |
%a{:href => "/#{params[:id]}/edit"} change | |
it? |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment