Skip to content

Commit

Permalink
Added shows/blogs
Browse files Browse the repository at this point in the history
  • Loading branch information
Chris committed Jan 18, 2011
1 parent 0c5f019 commit 1b4625a
Show file tree
Hide file tree
Showing 34 changed files with 630 additions and 48 deletions.
2 changes: 2 additions & 0 deletions app/controllers/blogs_controller.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
class BlogsController < ApplicationController
end
19 changes: 17 additions & 2 deletions app/controllers/geronimo_controller.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,22 @@
class GeronimoController < ApplicationController

def index
@latest_front_page_blogpost = Blog.latest_for_frontpage.blogtext
render :layout => false
blog = Blog.latest_for_frontpage
@latest_front_page_blogpost = blog ? blog.blogtext : "Nothing to say"
@next_show = Show.next_show
render :layout => false
end

def shows
@page_name = "Shows"
@upcoming_shows = Show.upcoming_shows
@past_shows = Show.past_shows
render :layout => 'g_application'
end

def blogs
@page_name = "Says Things"
@blogs = Blog.order("created_at DESC")
render :layout => 'g_application'
end
end
13 changes: 9 additions & 4 deletions app/controllers/microposts_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,15 @@ class MicropostsController < ApplicationController
def create
success_message = "Micropost created!"
@micropost = current_user.microposts.build(params[:micropost])
if(Blog.is_blog_post? params[:micropost][:content])
current_user.blogs.create_with_post params[:micropost][:content]
success_message = "Blog created!"
end

if Blog.is_blog_post? params[:micropost][:content]
current_user.blogs.create_with_post params[:micropost][:content]
success_message = "Blog created!"
elsif Show.is_show_post? params[:micropost][:content]
new_show = Show.new_from_post params[:micropost][:content]
new_show.save
success_message = "Show created!"
end

if @micropost.save
redirect_to home_path, :flash => { :success => success_message}
Expand Down
13 changes: 13 additions & 0 deletions app/controllers/shows_controller.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
class ShowsController < ApplicationController

def show
@show = Show.find(params[:id])
end

def destroy
redirect_to root_path unless signed_in?
@show = Show.find(params[:id])
@show.destroy
redirect_to all_shows_path, :flash => { :success => "Micropost deleted!" }
end
end
2 changes: 2 additions & 0 deletions app/helpers/blogs_helper.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
module BlogsHelper
end
2 changes: 2 additions & 0 deletions app/helpers/shows_helper.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
module ShowsHelper
end
82 changes: 82 additions & 0 deletions app/models/show.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
# == Schema Information
# Schema version: 20110113205037
#
# Table name: shows
#
# id :integer not null, primary key
# showtext :text
# showdate :date not null
# created_at :datetime
# updated_at :datetime
#

class Show < ActiveRecord::Base

class << self

def next_show()
Show.where("showdate > ?", DateTime.now.next_day(-1)).order("showdate ASC").first
end

def upcoming_shows()
Show.where("showdate > ?", DateTime.now.next_day(-1)).order("showdate ASC")
end

def past_shows()
Show.where("showdate < ?", Date.today).order("showdate DESC")
end

def new_from_post(post)
Show.new do |show|
if(is_show_post?(post))
show.showdate = get_date(post)
show.showtext = get_show_text post
else
raise "#{post} isn't a show post"
end
end
end

def is_show_post?(post)
post.split()[0] == 'show'
end

def get_date(post)

regexpFormats = [/\d+\/\d+\/\d+/, /\d+-\d+-\d+/, /\d+-\d+/]
formats = ['%m/%d/%Y', '%m/%d/%y', '%m-%d-%Y', '%m-%d-%y', '%m-%d']

show_date = nil

while (not show_date or (show_date < DateTime.now or show_date > DateTime.now.next_year(2))) and formats.size > 0
begin
format = formats.shift(1)[0]
for r_format in regexpFormats
if post =~ r_format
show_date = Date.strptime($~[0], format)
end
end
rescue
puts $!
retry unless formats.size == 0
end
end

if(not show_date)
begin
show_date = Date.parse(post)
rescue
#if has reached here show_date should be nil
end
end

return show_date
end

def get_show_text(post)
post_array = post.split()
post_array.shift(1)
post_array.join(' ')
end
end
end
5 changes: 5 additions & 0 deletions app/views/blogs/_blog.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<div class="blogContainer round">
<article>
<%= blog.blogtext %>
</article>
</div>
5 changes: 5 additions & 0 deletions app/views/geronimo/_blog.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<div class="blogContainer">
<article>
<%= blog.blogtext %>
</article>
</div>
8 changes: 8 additions & 0 deletions app/views/geronimo/blogs.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<div id="BlogsContainer">

<div id="AllBlogs">

<%= render @blogs %>

</div>
</div>
46 changes: 25 additions & 21 deletions app/views/geronimo/index.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,30 @@
<%= stylesheet_link_tag 'geronimo', :media => 'screen' %>
</head>
<body>
<span class="BandImages">
<% if @next_show %>
<div class="NextShow">Next Show: <%= @next_show.showtext %></div>
<div class="AllShows"><%= link_to 'all shows', shows_path%></div>
<% end %>
<span class="CenterImages">
<span class="TriptychContainer">
<span style="background: url('<%= image_path('Kelly.png')%>') no-repeat scroll center center transparent; width: 200px; height: 300px;" class="rounded-img2">
<%= image_tag("Kelly.png", :alt => "Guitarist", :class => "Triptych rounded-img2") %>
</span>
</span>
<span class="TriptychContainer">
<span style="background: url('<%= image_path('Matt.png')%>') no-repeat scroll center center transparent; width: 200px; height: 300px;" class="rounded-img2">
<%= image_tag("Matt.png", :alt => "Drummer", :class => "Triptych rounded-img2") %>
</span>
</span>
<span class="TriptychContainer">
<span style="background: url('<%= image_path('Ben.png')%>') no-repeat scroll center center transparent; width: 200px; height: 300px;" class="rounded-img2">
<%= image_tag("Ben.png", :alt => "Keyboardist", :class => "Triptych rounded-img2") %>
</span>
</span>
</span>
<div class="BandSays">Geronimo says: <article><p><%= @latest_front_page_blogpost%></p><span><%= link_to 'more', blogs_path%></span></article></div>
</span>
<div class="leftside">
<span class="ColumnOne">
<div class="Down">
Expand Down Expand Up @@ -56,27 +80,7 @@
</div>
</span>
</div>
<span class="BandImages">
<div class="NextShow">Next Show January 15th 2011 At Coles</div>
<span class="CenterImages">
<span class="TriptychContainer">
<span style="background: url('<%= image_path('Guitar.png')%>') no-repeat scroll center center transparent; width: 200px; height: 300px;" class="rounded-img2">
<%= image_tag("Guitar.png", :alt => "Guitarist", :class => "Triptych rounded-img2") %>
</span>
</span>
<span class="TriptychContainer">
<span style="background: url('<%= image_path('Drums.png')%>') no-repeat scroll center center transparent; width: 200px; height: 300px;" class="rounded-img2">
<%= image_tag("Drums.png", :alt => "Drummer", :class => "Triptych rounded-img2") %>
</span>
</span>
<span class="TriptychContainer">
<span style="background: url('<%= image_path('Keys.png')%>') no-repeat scroll center center transparent; width: 200px; height: 300px;" class="rounded-img2">
<%= image_tag("Keys.png", :alt => "Keyboardist", :class => "Triptych rounded-img2") %>
</span>
</span>
</span>
<div class="BandSays">Geronimo says: <article><p><%= @latest_front_page_blogpost%></p></article></div>
</span>

<div class="rightside">
<span class="ColumnThree">
<div class="Down DownRight">
Expand Down
13 changes: 13 additions & 0 deletions app/views/geronimo/shows.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<div id="ShowsContainer">
<div class="showsHeader">---------------------Upcoming Shows-----------------------</div>
<div id="UpcomingShows" class="round">

<%= render @upcoming_shows %>
</div>
<div class="showsHeader">---------------------Past Shows---------------------------</div>
<div id="PastShows" class="round">

<%= render @past_shows %>

</div>
</div>
12 changes: 12 additions & 0 deletions app/views/layouts/_g_footer.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<div class="footer">
<nav class="footer">
<ul>
<li><%= link_to "Front", root_path %></li>
<li><%= link_to "Myspace", 'http://www.myspace.com/thegeronimoband' %></li>
<li><%= link_to "Facebook", 'http://www.facebook.com/thegeronimoband' %></li>
<% if signed_in? %>
<li><%= link_to "Sign out", signout_path %></li>
<% end %>
</ul>
</nav>
</div>
1 change: 1 addition & 0 deletions app/views/layouts/_g_header.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
<div class="BandName">Geronimo!</div>
1 change: 1 addition & 0 deletions app/views/layouts/_g_stylesheets.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
<%= stylesheet_link_tag 'geronimo', :media => 'screen' %>
20 changes: 20 additions & 0 deletions app/views/layouts/g_application.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
<!DOCTYPE html>
<html>
<head>
<title>Geronimo!</title>
<%= csrf_meta_tag %>
<%= render 'layouts/g_stylesheets' %>
<%= javascript_include_tag :defaults %>
</head>
<body>
<div class="container">
<div class="PageName"><%= @page_name%></div>
<%= render 'layouts/g_header' %>
<section class="round">
<%= yield %>
</section>
<%= render 'layouts/g_footer' %>
<%= debug(params) if Rails.env.development? %>
</div>
</body>
</html>
13 changes: 13 additions & 0 deletions app/views/shows/_show.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<div>

<span class="show">*&nbsp;<%= show.showtext %></span>


<% if signed_in? %>
<span>
<%= link_to "delete", show, :method => :delete,
:confirm => "You sure?" %>
</span>

<% end %>
</div>
1 change: 1 addition & 0 deletions app/views/shows/show.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
<%= @show.showtext %>
4 changes: 4 additions & 0 deletions config/routes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,16 @@
end
end

resources :blogs, :only => [:destroy]
resources :shows
resources :sessions, :only => [:new, :create, :destroy]
resources :microposts, :only => [:create, :destroy]
resources :relationships, :only => [:create, :destroy]

root :to => "geronimo#index"

match '/blogs', :to => 'geronimo#blogs'
match '/all_shows', :to => 'geronimo#shows'
match '/contact', :to => 'pages#contact'
match '/about', :to => 'pages#about'
match '/help', :to => 'pages#help'
Expand Down
14 changes: 14 additions & 0 deletions db/migrate/20110113205037_create_shows.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
class CreateShows < ActiveRecord::Migration
def self.up
create_table :shows do |t|
t.text :showtext
t.date :showdate, :null => false

t.timestamps
end
end

def self.down
drop_table :shows
end
end
9 changes: 8 additions & 1 deletion db/schema.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
#
# It's strongly recommended to check this file into your version control system.

ActiveRecord::Schema.define(:version => 20110111234559) do
ActiveRecord::Schema.define(:version => 20110113205037) do

create_table "blogs", :force => true do |t|
t.integer "user_id"
Expand Down Expand Up @@ -42,6 +42,13 @@
add_index "relationships", ["follower_id", "followed_id"], :name => "index_relationships_on_follower_id_and_followed_id", :unique => true
add_index "relationships", ["follower_id"], :name => "index_relationships_on_follower_id"

create_table "shows", :force => true do |t|
t.text "showtext"
t.date "showdate", :null => false
t.datetime "created_at"
t.datetime "updated_at"
end

create_table "users", :force => true do |t|
t.string "name"
t.string "email"
Expand Down
Loading

0 comments on commit 1b4625a

Please sign in to comment.