Permalink
Browse files

Add some basic panda placeholder functionality

  • Loading branch information...
Matt Van Horn
Matt Van Horn committed Jan 9, 2012
1 parent 3e25321 commit 320085014d6bed24d669dce5a8ede07f7589d553
View
@@ -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
@@ -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
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
View
Deleted file not rendered
View
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@@ -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
@@ -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 )
@@ -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>
@@ -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
@@ -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
@@ -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
@@ -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

0 comments on commit 3200850

Please sign in to comment.