Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Add some basic panda placeholder functionality

  • Loading branch information...
commit 320085014d6bed24d669dce5a8ede07f7589d553 1 parent 3e25321
Matt Van Horn authored
View
3  Gemfile
@@ -3,7 +3,8 @@ source 'http://rubygems.org'
gem 'rails', '3.1.1'
gem 'pg'
gem 'thin'
-gem "haml-rails"
+gem 'haml-rails'
+gem 'rmagick'
# Gems used only for assets and not required
# in production environments by default.
View
26 Gemfile.lock
@@ -97,19 +97,20 @@ GEM
rake (0.9.2.2)
rdoc (3.12)
json (~> 1.4)
- rspec (2.7.0)
- rspec-core (~> 2.7.0)
- rspec-expectations (~> 2.7.0)
- rspec-mocks (~> 2.7.0)
- rspec-core (2.7.1)
- rspec-expectations (2.7.0)
+ rmagick (2.13.1)
+ rspec (2.8.0)
+ rspec-core (~> 2.8.0)
+ rspec-expectations (~> 2.8.0)
+ rspec-mocks (~> 2.8.0)
+ rspec-core (2.8.0)
+ rspec-expectations (2.8.0)
diff-lcs (~> 1.1.2)
- rspec-mocks (2.7.0)
- rspec-rails (2.7.0)
- actionpack (~> 3.0)
- activesupport (~> 3.0)
- railties (~> 3.0)
- rspec (~> 2.7.0)
+ rspec-mocks (2.8.0)
+ rspec-rails (2.8.1)
+ actionpack (>= 3.0)
+ activesupport (>= 3.0)
+ railties (>= 3.0)
+ rspec (~> 2.8.0)
sass (3.1.12)
sass-rails (3.1.5)
actionpack (~> 3.1.0)
@@ -144,6 +145,7 @@ DEPENDENCIES
jquery-rails
pg
rails (= 3.1.1)
+ rmagick
rspec-rails
sass-rails (~> 3.1.4)
thin
View
BIN  app/assets/images/attribution/1.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
View
BIN  app/assets/images/attribution/2.jpg
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
View
BIN  app/assets/images/attribution/3.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
View
BIN  app/assets/images/attribution/4.jpg
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
View
BIN  app/assets/images/attribution/5.jpg
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
View
BIN  app/assets/images/attribution/6.jpg
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
View
BIN  app/assets/images/panda.jpg
Deleted file not rendered
View
BIN  app/assets/images/panda.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
View
BIN  app/assets/images/pandas/Grosser_Panda.JPG
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
View
BIN  app/assets/images/pandas/cliff_1066.jpg
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
View
BIN  app/assets/images/pandas/kevin_dooley.jpg
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
View
BIN  app/assets/images/pandas/rick_weiss.jpg
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
View
BIN  app/assets/images/pandas/rick_weiss2.jpg
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
View
BIN  app/assets/images/pandas/rick_weiss3.jpg
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
View
41 app/controllers/pandas_controller.rb
@@ -0,0 +1,41 @@
+require 'RMagick'
+
+class PandasController < ApplicationController
+
+ MAX_WIDTH = 4000
+ MAX_HEIGHT = 3000
+
+ before_filter :request_precheck
+
+ def color
+ image = PandaPicker.new.get_color_image( @width, @height )
+ deliver(image) and return
+ end
+
+ def grayscale
+ image = PandaPicker.new.get_grayscale_image( @width, @height )
+ deliver(image) and return
+ end
+
+ protected
+
+ def deliver(image)
+ if image == nil
+ render :text => "Unknown error occurred", :status => 500
+ else
+ send_data image.to_blob, :type => 'image/png', :disposition => 'inline'
+ end
+ end
+
+ def request_precheck
+
+ @width = params[:width].to_i
+ @height = params[:height].to_i
+
+ if @width > MAX_WIDTH or @height > MAX_HEIGHT
+ return false
+ end
+
+ return true
+ end
+end
View
2  app/models/panda_picker.rb
@@ -10,7 +10,7 @@ def self.preload_pics
puts "Preloading pics"
start_time = Time.now
images = []
- dir = Rails.root.join('app', 'assets', 'images', 'pandas')
+ dir = Rails.root.join('public', 'assets', 'pandas')
Dir.entries( dir ).collect{ |f| f if f =~ /\.jpg/ }.compact.each do |pic|
mag = Magick::Image.read( "#{dir}/#{pic}" ).first
p = Pic.new( mag, mag.columns, mag.rows )
View
42 app/views/pages/attribution.html.haml
@@ -0,0 +1,42 @@
+.container
+ %h1 Photographers:
+ %ul
+ %li.panda
+ = image_tag('attribution/1.png', :size => '150x150')
+ .photographer
+ = link_to "J. Patrick Fischer", "http://en.wikipedia.org/wiki/File:Grosser_Panda.JPG"
+ .license
+ %a{:href => "http://creativecommons.org/licenses/by-sa/3.0/deed.en"}
+ Attribution
+ Share Alike
+ 3.0 Unported
+ %li.panda
+ = image_tag('attribution/2.jpg', :size => '150x150')
+ .photographer
+ = link_to "Kevin Dooley", "http://www.flickr.com/photos/pagedooley/5402340884/"
+ .license
+ <a href="http://creativecommons.org/licenses/by/2.0/deed.en" rel="license cc:license">Some rights reserved</a>
+ %li.panda
+ = image_tag('attribution/3.png', :size => '150x150')
+ .photographer
+ = link_to "Cliff1066", "http://www.flickr.com/photos/nostri-imago/3582031004/"
+ .license
+ <a href="http://creativecommons.org/licenses/by/2.0/deed.en" rel="license cc:license">Some rights reserved</a>
+ %li.panda
+ = image_tag('attribution/4.jpg', :size => '150x150')
+ .photographer
+ = link_to "Rick Weiss", "http://www.flickr.com/photos/26049404@N05/5661176303/"
+ .license
+ <a href="http://creativecommons.org/licenses/by/2.0/deed.en" rel="license cc:license">Some rights reserved</a>
+ %li.panda
+ = image_tag('attribution/5.jpg', :size => '150x150')
+ .photographer
+ = link_to "Rick Weiss", "http://www.flickr.com/photos/26049404@N05/5661740276/"
+ .license
+ <a href="http://creativecommons.org/licenses/by/2.0/deed.en" rel="license cc:license">Some rights reserved</a>
+ %li.panda
+ = image_tag('attribution/6.jpg', :size => '150x150')
+ .photographer
+ = link_to "Rick Weiss", "http://www.flickr.com/photos/26049404@N05/5661160665"
+ .license
+ <a href="http://creativecommons.org/licenses/by/2.0/deed.en" rel="license cc:license">Some rights reserved</a>
View
12 app/views/pages/home.html.haml
@@ -1,4 +1,4 @@
-#container
+.container
#content
%header
%h1 placepanda
@@ -13,8 +13,14 @@
%p Like this: http://placepanda.com/200/300 or: http://placepanda.com/g/200/300
#pandapics
- = image_tag('panda.jpg')
+ = image_tag('panda.png')
%footer
- %p Made by Matt Van Horn, inspired by placekitten
+ %p
+ Made by Matt Van Horn, inspired by Mark James &amp;
+ = link_to "placekitten.com", "http://placekitten.com"
+ with code liberally borrowed from
+ = link_to "placedog.com", "http://github.com/JGaudette/PlaceDog"
+ for the purposes of
+ =link_to "the blog post here", "http://www.mattvanhorn.com/2012/01/07/heroku-cedar-assets-ruby-1-9/"
View
3  config/routes.rb
@@ -1,3 +1,6 @@
Placepanda::Application.routes.draw do
root :to => 'pages#home'
+ match '/:width/:height', :to => 'pandas#color'
+ match '/g/:width/:height', :to => 'pandas#grayscale'
+ match '/attribution', :to => 'pages#attribution'
end
View
7 spec/controllers/pandas_controller_spec.rb
@@ -0,0 +1,7 @@
+require 'spec_helper'
+
+describe PandasController do
+ it "does something" do
+ pending "I pretty much lifted all this code from github.com/JGaudette/PlaceDog and have not written tests for it yet"
+ end
+end
View
12 spec/routing/panda_routing_spec.rb
@@ -0,0 +1,12 @@
+require 'spec_helper'
+
+describe "Pandda Routing" do
+
+ it "routes the color img requests correctly" do
+ { :get => "/1616/1000" }.should route_to(:controller => "pandas", :action => "color", :width => '1616', :height => '1000')
+ end
+ it "routes the grayscale img requests correctly" do
+ { :get => "g/1616/1000" }.should route_to(:controller => "pandas", :action => "grayscale", :width => '1616', :height => '1000')
+ end
+
+end
Please sign in to comment.
Something went wrong with that request. Please try again.