Skip to content

Commit

Permalink
switched most views to Haml
Browse files Browse the repository at this point in the history
  • Loading branch information
armandofox committed Sep 9, 2011
1 parent acedabb commit 357ef52
Show file tree
Hide file tree
Showing 24 changed files with 637 additions and 20 deletions.
1 change: 1 addition & 0 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ gem 'rails', '3.0.5'
# gem 'rails', :git => 'git://github.com/rails/rails.git'

gem 'sqlite3'
gem 'haml'

group :test, :development do
gem 'capybara'
Expand Down
41 changes: 41 additions & 0 deletions README
Original file line number Diff line number Diff line change
@@ -1,3 +1,15 @@
== RottenPotatoes for "Engineering Software for Cloud Computing"

This repo tracks the version of the RottenPotatoes teaching app used
with the Fox & Patterson textbook "Engineering Software for Cloud
Computing".

Different branches of the repo correspond to the code developed in
different chapters of the book.

See the book for information on how to use this repo and what the
branches are for.

== Welcome to Rails

Rails is a web-application framework that includes everything needed to create
Expand Down Expand Up @@ -26,6 +38,35 @@ Rails. You can read more about Action Pack in
link:files/vendor/rails/actionpack/README.html.


== Getting Started

NOTE: The steps below are for creating a new app. The initial version
of RottenPotatoes was created with Rails 3.0.5 and Ruby 1.8.7 using the
commands:

* <tt>rails new rottenpotatoes -J -T</tt>
* <tt>rails generate resource movie title:string rating:string released_on:datetime</tt>
* <tt>rails generate cucumber:install</tt>



1. At the command prompt, create a new Rails application:
<tt>rails new myapp</tt> (where <tt>myapp</tt> is the application name)

2. Change directory to <tt>myapp</tt> and start the web server:
<tt>cd myapp; rails server</tt> (run with --help for options)

3. Go to http://localhost:3000/ and you'll see:
"Welcome aboard: You're riding Ruby on Rails!"

4. Follow the guidelines to start developing your application. You can find
the following resources handy:

* The Getting Started Guide: http://guides.rubyonrails.org/getting_started.html
* Ruby on Rails Tutorial Book: http://www.railstutorial.org/



== Getting Started

1. At the command prompt, create a new Rails application:
Expand Down
2 changes: 0 additions & 2 deletions app/controllers/movie_controller.rb

This file was deleted.

47 changes: 47 additions & 0 deletions app/controllers/movies_controller.rb
Original file line number Diff line number Diff line change
@@ -1,2 +1,49 @@
class MoviesController < ApplicationController

def index
@movies = Movie.find(:all, :order => 'released_on')
end

def new
@movie = Movie.new
end

def create
@movie = Movie.new(params[:movie])
if @movie.save
flash[:notice] = "#{@movie.title} added to Rotten Potatoes!"
redirect_to movie_path(@movie)
else
render :action => "new"
end
end

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

def edit
@movie = Movie.find(params[:id])
end

def update
@movie = Movie.find(params[:id])
if @movie.update_attributes(params[:movie])
flash[:notice] = "#{@movie.title} has been updated!"
redirect_to movie_path(@movie)
else
render :action => "edit"
end
end

def destroy
@movie = Movie.find(params[:id])
if @movie.destroy
flash[:notice] = "#{@movie.title} has been deleted!"
else
flash[:error] = "Failed to delete #{@movie.title}!"
end
redirect_to(movies_url)
end

end
2 changes: 0 additions & 2 deletions app/helpers/movie_helper.rb

This file was deleted.

4 changes: 4 additions & 0 deletions app/helpers/movies_helper.rb
Original file line number Diff line number Diff line change
@@ -1,2 +1,6 @@
module MoviesHelper
# Checks if a number is odd:
def oddness(count)
count.odd? ? "odd" : "even"
end
end
35 changes: 35 additions & 0 deletions app/models/movie.rb
Original file line number Diff line number Diff line change
@@ -1,2 +1,37 @@
class Movie < ActiveRecord::Base

@@ratings = ['G', 'PG', 'PG-13', 'R', 'NC-17']
cattr_accessor :ratings

validates_presence_of :title
validates_length_of :description, :minimum => 10
validates_uniqueness_of :title, :message => "already exists in the database"
validates_inclusion_of :rating, :in => Movie.ratings, :message => "is not a valid rating"

# Returns a formatted version of the date:
def release_date
self.released_on.strftime('%B %d, %Y') if self.released_on
end

def self.required_age_for(rating)
{
"G" => 0,
"PG" => 0,
"PG-13" => 13,
"R" => 17,
"NC-17" => 17
}[rating]
end

def appropriate_for_birthdate?(birthdate)
latest_acceptable_time = Movie.required_age_for(self.rating).years.ago
birthdate <= latest_acceptable_time
end

def self.find_all_appropriate_for_birthdate(birthdate)
Movie.all.select do |movie|
movie.appropriate_for_birthdate?(birthdate)
end
end

end
14 changes: 0 additions & 14 deletions app/views/layouts/application.html.erb

This file was deleted.

14 changes: 14 additions & 0 deletions app/views/layouts/application.html.haml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
!!! Strict
%html{'xmlns' => 'http://www.w3.org/1999/xhtml', 'xml:lang' => 'en', 'lang' => 'en'}
%head
%title Rotten Potatoes!
= stylesheet_link_tag 'general'

%body
%h1= link_to 'Rotten Potatoes!', movies_path
#body
- if flash[:notice]
#flash_notice= flash[:notice]
- elsif flash[:error]
#flash_error= flash[:error]
= yield
19 changes: 19 additions & 0 deletions app/views/movies/_edit_form.html.haml
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
- form_for(@movie) do |f|
= f.error_messages
- field_set_tag "Movie Details" do
%ul
%li
= f.label :title, "Movie Title:"
= f.text_field :title
%li
= f.label :rating, "Movie Rating:"
= f.select :rating, options_for_select(Movie.ratings, @movie.rating)
%li
= f.label :released_on, "Release Date:"
= f.date_select :released_on, :start_year => 1939
%li
= f.label :description, "Movie Description:"
= f.text_area :description, :rows => 10
%li
= f.submit((@movie.new_record? ? "Create Movie" : "Update Movie"),
:id => "submit")
16 changes: 16 additions & 0 deletions app/views/movies/_movie_row.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<tbody class="movie_row">
<tr>
<td>
<% form_for(movie) do |f| %>
<%= f.hidden_field :title %>
<%= f.hidden_field :description %>
<%= f.hidden_field :released_on %>
<%= f.hidden_field :rating %>
<%= f.submit "Select" %>
<% end %>
</td>
<td><%= movie.title %></td>
<td><%= movie.rating %></td>
<td><%= movie.release_date %></td>
</tr>
</tbody>
7 changes: 7 additions & 0 deletions app/views/movies/edit.html.haml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
%h2 Editing #{@movie.title}

= render :partial => "edit_form"

%ul#page_nav
%li= link_to 'Cancel', @movie
%li= link_to 'Back to list of movies', movies_path
32 changes: 32 additions & 0 deletions app/views/movies/find.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
<h2>Select Movie</h2>


<table id="movies" summary="List of all the movies.">
<tr>
<th>Select</th>
<th>Movie Title</th>
<th>Rating</th>
<th>Release Date</th>
</tr>
<% @movies.each do |movie| %>
<tr>
<td>
<% form_for(movie) do |f| %>
<%= f.hidden_field :title %>
<%= f.hidden_field :description %>
<%= f.hidden_field :released_on %>
<%= f.hidden_field :rating %>
<%= f.submit "Select" %>
<% end %>
</td>
<td><%= movie.title %></td>
<td><%= movie.rating %></td>
<td><%= movie.release_date %></td>
</tr>
<% end %>
</table>

<ul id="page_nav">
<li>Not what you're looking for? <%= link_to "Search Again!", new_movie_path %></li>
<li>Return to <%= link_to "Movies", movies_path %></li>
</ul>
20 changes: 20 additions & 0 deletions app/views/movies/index.html.haml
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
%h2 All Movies

%table#movies{:summary => 'List of all the movies.'}
%thead
%tr
%th Movie Title
%th Rating
%th Release Date
%th More Info
%tbody
- @movies.each_with_index do |movie,count|
%tr{:class => oddness(count)}
%td= movie.title
%td= movie.rating
%td= movie.release_date
%td= link_to 'More about #{movie.title}', movie

%ul#page_nav
%li= link_to 'Add New Movie Manually', new_movie_path

6 changes: 6 additions & 0 deletions app/views/movies/new.html.haml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
%h2 Add New Movie

= render :partial => "edit_form"

%ul#page_nav
%li link_to 'Back to list of movies', movies_path
10 changes: 10 additions & 0 deletions app/views/movies/show.html.haml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
%h2= @movie.title

%p
Released on #{@movie.release_date}. Rated #{@movie.rating}.
= simple_format(@movie.description)

%ul#page_nav
%li= link_to 'Edit', edit_movie_path(@movie)
%li= link_to 'Delete', movie_path(@movie), :method => :delete, :confirm => "Really delete #{@movie.title}?"
%li= link_to 'Back to list of movies', movies_path
8 changes: 8 additions & 0 deletions config/cucumber.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<%
rerun = File.file?('rerun.txt') ? IO.read('rerun.txt') : ""
rerun_opts = rerun.to_s.strip.empty? ? "--format #{ENV['CUCUMBER_FORMAT'] || 'progress'} features" : "--format #{ENV['CUCUMBER_FORMAT'] || 'pretty'} #{rerun}"
std_opts = "--format #{ENV['CUCUMBER_FORMAT'] || 'progress'} --strict --tags ~@wip"
%>
default: <%= std_opts %> features
wip: --tags @wip:3 --wip features
rerun: <%= rerun_opts %> --format rerun --out rerun.txt --strict --tags ~@wip
5 changes: 4 additions & 1 deletion config/database.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ development:
# Warning: The database defined as "test" will be erased and
# re-generated from your development database when you run "rake".
# Do not set this db to the same as development or production.
test:
test: &test
adapter: sqlite3
database: db/test.sqlite3
pool: 5
Expand All @@ -20,3 +20,6 @@ production:
database: db/production.sqlite3
pool: 5
timeout: 5000

cucumber:
<<: *test
2 changes: 1 addition & 1 deletion db/migrate/20110909213200_create_movies.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ def self.up
create_table :movies do |t|
t.string :title
t.string :rating
t.integer :year
t.datetime :released_on

t.timestamps
end
Expand Down
Loading

0 comments on commit 357ef52

Please sign in to comment.