Skip to content

Commit

Permalink
added picture dump
Browse files Browse the repository at this point in the history
  • Loading branch information
universaL committed May 2, 2008
1 parent 45139d0 commit ff38962
Show file tree
Hide file tree
Showing 72 changed files with 9,060 additions and 48 deletions.
57 changes: 11 additions & 46 deletions app/controllers/pastes_controller.rb
Original file line number Diff line number Diff line change
@@ -1,35 +1,17 @@
class PastesController < ApplicationController
# GET /pastes
# GET /pastes.xml
def index
@pastes = Paste.find(:all, :order => "id DESC")

respond_to do |format|
format.html # index.html.erb
format.xml { render :xml => @pastes }
end
end

# GET /pastes/1
# GET /pastes/1.xml
def show
@paste = Paste.find(params[:id])

respond_to do |format|
format.html # show.html.erb
format.xml { render :xml => @paste }
end
end

# GET /pastes/new
# GET /pastes/new.xml
def new
@paste = Paste.new

respond_to do |format|
format.html # new.html.erb
format.xml { render :xml => @paste }
end
end

# GET /pastes/1/edit
Expand All @@ -38,48 +20,31 @@ def edit
end

# POST /pastes
# POST /pastes.xml
def create
@paste = Paste.new(params[:paste])

respond_to do |format|
if @paste.save
flash[:notice] = 'Paste was successfully created.'
format.html { redirect_to(@paste) }
format.xml { render :xml => @paste, :status => :created, :location => @paste }
else
format.html { render :action => "new" }
format.xml { render :xml => @paste.errors, :status => :unprocessable_entity }
end
if @paste.save
flash[:notice] = 'Paste was successfully created.'
redirect_to(@paste)
else
render :action => "new"
end
end

# PUT /pastes/1
# PUT /pastes/1.xml
def update
@paste = Paste.find(params[:id])

respond_to do |format|
if @paste.update_attributes(params[:paste])
flash[:notice] = 'Paste was successfully updated.'
format.html { redirect_to(@paste) }
format.xml { head :ok }
else
format.html { render :action => "edit" }
format.xml { render :xml => @paste.errors, :status => :unprocessable_entity }
end
if @paste.update_attributes(params[:paste])
flash[:notice] = 'Paste was successfully updated.'
redirect_to(@paste)
else
render :action => "edit"
end
end

# DELETE /pastes/1
# DELETE /pastes/1.xml
def destroy
@paste = Paste.find(params[:id])
@paste.destroy

respond_to do |format|
format.html { redirect_to(pastes_url) }
format.xml { head :ok }
end
redirect_to(pastes_url)
end
end
28 changes: 28 additions & 0 deletions app/controllers/pictures_controller.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
class PicturesController < ApplicationController
# GET /pictures
def index
@pictures = Picture.find(:all, :order => "id DESC", :conditions => "parent_id is NULL")
end

# GET /pictures/new
def new
@picture = Picture.new
end

def create
@picture = Picture.new(params[:picture])
if @picture.save
flash[:notice] = 'Picture was successfully created.'
redirect_to pictures_url
else
render :action => :new
end
end

# DELETE /pictures/1
def destroy
@picture = Picture.find(params[:id])
@picture.destroy
redirect_to(pictures_url)
end
end
30 changes: 30 additions & 0 deletions app/helpers/pictures_helper.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
module PicturesHelper

def pictures_to_trs(pictures, cols)
html = ""
i = 0
while i < pictures.length
links = "<tr class=\"odd\">\n"
html << "<tr>\n"
i.upto i+cols-1 do |j|
if picture = pictures[j]
html << " <td>"
html << link_to(image_tag(picture.public_filename(:thumb)), picture.public_filename)
html << "</td>\n"
links << " <td>"
links << link_to('Delete', picture, :confirm => 'Are you sure?', :method => :delete)
links << "</td>\n"
else
html << " <td></td>"
links << " <td></td>"
end
end
html << "</tr>\n"
links << "</tr>\n"
html << links
i += cols
end
html
end
alias_method :p2trs, :pictures_to_trs
end
7 changes: 7 additions & 0 deletions app/models/picture.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
class Picture < ActiveRecord::Base
has_attachment :content_type => :image,
:storage => :file_system,
:max_size => 2.megabytes,
:thumbnails => { :thumb => '150x150>' }
validates_as_attachment
end
27 changes: 27 additions & 0 deletions app/views/layouts/application.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
<meta http-equiv="content-type" content="text/html;charset=UTF-8" />
<title><%= controller.controller_name %>: <%= controller.action_name %></title>
<%= stylesheet_link_tag 'scaffold' %>
<%- %w{active4d all_hallows_eve amy blackboard brilliance_black brilliance_dull cobalt dawn eiffel espresso_libre idle iplastic lazy mac_classic magicwb_amiga pastels_on_dark spacecadet sunburst twilight zenburnesque}.each do |theme| -%>
<%= require_syntax_css theme%>
<%- end -%>
<%= javascript_include_tag :defaults %>
</head>
<body>

<p style="color: green"><%= flash[:notice] %></p>
<%= yield %>
<table>
<tfoot>
<tr>
<td><%= link_to_unless_current 'Pastes', pastes_path %></td>
<td><%= link_to_unless_current 'Pictures', pictures_path %></td>
</tr>
</tfoot>
</table>
</body>
</html>
11 changes: 11 additions & 0 deletions app/views/pictures/index.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<table>
<thead>
<tr>
<th colspan="4"><h1>Pictures</h1></th>
<th><%= link_to 'New picture', new_picture_path %></th>
</tr>
</thead>
<tbody>
<%= p2trs @pictures, 5 %>
</tbody>
</table>
22 changes: 22 additions & 0 deletions app/views/pictures/new.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
<table>
<thead>
<tr>
<th><h1>New Picture</h1></th>
</tr>
</thead>
<tbody>
<%- unless @picture.errors.empty? -%>
<tr><td><%= error_messages_for :picture %></td></tr>
<%- end -%>
<tr>
<td>
<% form_for(:picture, :url => pictures_path,
:html => { :multipart => true }) do |f| -%>
<%= f.label :uploaded_data, "Upload A picture" %><br/>
<%= f.file_field :uploaded_data %><br/>
<%= submit_tag 'Create' %>
<% end -%>
</td>
</tr>
</tbody>
</table>
14 changes: 14 additions & 0 deletions config/amazon_s3.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
development:
bucket_name: appname_development
access_key_id:
secret_access_key:

test:
bucket_name: appname_test
access_key_id:
secret_access_key:

production:
bucket_name: appname
access_key_id:
secret_access_key:
3 changes: 3 additions & 0 deletions config/routes.rb
Original file line number Diff line number Diff line change
@@ -1,11 +1,14 @@
ActionController::Routing::Routes.draw do |map|
map.login '/login', :controller => 'sessions', :action => 'new'
map.logout '/logout', :controller => 'sessions', :action => 'destroy'

map.resource :session

map.resources :pastes
map.root :controller => "pastes"

map.resources :pictures

# The priority is based upon order of creation: first created -> highest priority.

# Sample of regular route:
Expand Down
Binary file modified db/development.sqlite3
Binary file not shown.
18 changes: 18 additions & 0 deletions db/migrate/003_create_pictures.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
class CreatePictures < ActiveRecord::Migration
def self.up
create_table :pictures do |t|
t.column :parent_id, :integer
t.column :content_type, :string
t.column :filename, :string
t.column :thumbnail, :string
t.column :size, :integer
t.column :width, :integer
t.column :height, :integer
t.timestamps
end
end

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

ActiveRecord::Schema.define(:version => 2) do
ActiveRecord::Schema.define(:version => 3) do

create_table "pastes", :force => true do |t|
t.text "code"
Expand All @@ -18,6 +18,18 @@
t.datetime "updated_at"
end

create_table "pictures", :force => true do |t|
t.integer "parent_id"
t.string "content_type"
t.string "filename"
t.string "thumbnail"
t.integer "size"
t.integer "width"
t.integer "height"
t.datetime "created_at"
t.datetime "updated_at"
end

create_table "users", :force => true do |t|
t.string "login"
t.string "email"
Expand Down
Binary file added db/test.sqlite3
Binary file not shown.
Loading

0 comments on commit ff38962

Please sign in to comment.