2014-09-30 03:04:07 -07:00
|
|
|
# Camping is a great small framework.
|
|
|
|
Camping.goes :StargateRando
|
|
|
|
|
|
|
|
# This holds all our constant data.
|
|
|
|
module StargateRando::Data
|
|
|
|
SERIES_SHORT_NAMES = ['SG-1', 'SGA', 'SGU']
|
|
|
|
SERIES_NAMES = { 'SG-1' => 'Stargate SG-1', 'SGA' => 'Stargate Atlantis', 'SGU' => 'Stargate Universe'}
|
|
|
|
SEASONS_PER_SERIES = { 'SG-1' => 10, 'SGA' => 5, 'SGU' => 2}
|
|
|
|
end
|
|
|
|
|
|
|
|
# This holds our (currently there's only one) controllers.
|
|
|
|
module StargateRando::Controllers
|
|
|
|
class Index < R '/'
|
|
|
|
def get
|
|
|
|
chosen_series_id = Data::SERIES_SHORT_NAMES[rand(3)]
|
|
|
|
@series = Data::SERIES_NAMES[chosen_series_id]
|
|
|
|
num_seasons = Data::SEASONS_PER_SERIES[chosen_series_id]
|
|
|
|
chosen_season = 1 + rand(num_seasons)
|
|
|
|
|
|
|
|
# SG-1 has a couple of seasons of length 22 and one of length 21 so we need to handle that.
|
|
|
|
case chosen_series_id
|
|
|
|
when 'SG-1'
|
|
|
|
case chosen_season
|
|
|
|
when 1
|
|
|
|
num_episodes = 21
|
|
|
|
when 2..7
|
|
|
|
num_episodes = 22
|
|
|
|
else
|
|
|
|
num_episodes = 20
|
|
|
|
end
|
|
|
|
else
|
|
|
|
num_episodes = 20
|
|
|
|
end
|
|
|
|
|
|
|
|
chosen_episode = 1 + rand(num_episodes)
|
|
|
|
|
|
|
|
@episode_code = "#{chosen_season}x#{chosen_episode}"
|
|
|
|
render :results
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
# This holds our views. Markaby is pretty swagtacular.
|
|
|
|
module StargateRando::Views
|
|
|
|
def layout
|
|
|
|
html do
|
|
|
|
head do
|
|
|
|
title { "Stargate Episode Randomizer" }
|
2014-09-30 13:15:58 -07:00
|
|
|
meta :name => "viewport", :content => "width=device-width, user-scalable=no"
|
2014-09-30 03:04:07 -07:00
|
|
|
link :rel => "stylesheet", :href => "http://fonts.googleapis.com/css?family=Ubuntu:400,700", :type => "text/css"
|
2014-09-30 03:15:52 -07:00
|
|
|
link :rel => "stylesheet", :href => "main.css", :type => "text/css"
|
2014-09-30 03:04:07 -07:00
|
|
|
end
|
|
|
|
|
|
|
|
body { self << yield }
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def results
|
|
|
|
h1 "You should watch #{@series}: #{@episode_code}"
|
2014-09-30 03:26:51 -07:00
|
|
|
button :onclick => "document.location.reload()", :id => "reload" do
|
|
|
|
"Get a new episode"
|
|
|
|
end
|
2014-09-30 03:04:07 -07:00
|
|
|
end
|
|
|
|
|
2014-09-30 13:15:58 -07:00
|
|
|
end
|