diff --git a/Gemfile b/Gemfile index d40e7b65fb1235fce1ec324887796319e2e04ea9..6221af125569b79cd8211844fda431bd7d1be78e 100644 --- a/Gemfile +++ b/Gemfile @@ -3,31 +3,40 @@ source 'http://gemcutter.org' gem 'rails', '3.0.0.beta4' gem 'bundler', '0.9.26' -gem 'mongo_mapper', :git => "http://github.com/BadMinus/mongomapper.git" -gem 'devise', :git => "http://github.com/BadMinus/devise.git" -gem 'jnunemaker-validatable', :git => "http://github.com/BadMinus/validatable.git" + +gem 'thin' + +#Security +gem 'gpgme' +gem 'devise', :git => 'http://github.com/BadMinus/devise.git' + +#Mongo +gem 'mongo_mapper', :git => 'http://github.com/BadMinus/mongomapper.git' +gem 'jnunemaker-validatable', :git => 'http://github.com/BadMinus/validatable.git' gem 'mongo_ext' gem 'bson_ext' -gem "haml" -gem 'roxml', :git => "git://github.com/Empact/roxml.git" +#Views +gem 'haml' +gem 'will_paginate', '3.0.pre' -gem 'gpgme' +gem 'roxml', :git => 'git://github.com/Empact/roxml.git' + +#Standards gem 'pubsubhubbub' -#mai crazy async stuff -#gem 'em-synchrony', :git => 'git://github.com/igrigorik/em-synchrony.git', :require => 'em-synchrony/em-http' + gem 'em-http-request',:git => 'git://github.com/igrigorik/em-http-request.git', :require => 'em-http' -#gem 'rack-fiber_pool', :require => 'rack/fiber_pool' -gem 'addressable', :require => "addressable/uri" +gem 'addressable', :require => 'addressable/uri' gem 'em-websocket' -gem 'thin' -gem 'will_paginate', '3.0.pre' +#File uploading +gem 'carrierwave', :git => 'git://github.com/rsofaer/carrierwave.git' , :branch => 'master' #Untested mongomapper branch +gem 'image_science' group :test do gem 'rspec', '>= 2.0.0.beta.17' gem 'rspec-rails', '2.0.0.beta.17' - gem "mocha" + gem 'mocha' gem 'webrat' gem 'redgreen' gem 'autotest' @@ -36,10 +45,10 @@ group :test do end group :development do - gem "nifty-generators" - gem "ruby-debug" + gem 'nifty-generators' + gem 'ruby-debug' end group :deployment do - gem 'sprinkle', :git => "git://github.com/rsofaer/sprinkle.git" + gem 'sprinkle', :git => 'git://github.com/rsofaer/sprinkle.git' end diff --git a/app/controllers/photos_controller.rb b/app/controllers/photos_controller.rb new file mode 100644 index 0000000000000000000000000000000000000000..6239603ec718d93390868096d9c38ca17ad2b62f --- /dev/null +++ b/app/controllers/photos_controller.rb @@ -0,0 +1,36 @@ +class PhotosController < ApplicationController + #before_filter :authenticate_user! + + def index + @photos = Photo.paginate :page => params[:page], :order => 'created_at DESC' + + end + + def create + @photo = Photo.new(params[:photo]) + @photo.person = current_user + + if @photo.save + flash[:notice] = "Successfully uploaded photo." + redirect_to photos_url + else + render :action => 'new' + end + end + + def new + @photo = Photo.new + end + + def destroy + @photo = Photo.where(:id => params[:id]).first + @photo.destroy + flash[:notice] = "Successfully deleted photo." + redirect_to root_url + end + + def show + @photo = Photo.where(:id => params[:id]).first + + end +end diff --git a/app/models/photo.rb b/app/models/photo.rb new file mode 100644 index 0000000000000000000000000000000000000000..3e8407a811f587272d9f16a0098ffe3dec18054c --- /dev/null +++ b/app/models/photo.rb @@ -0,0 +1,6 @@ +class Photo + require 'carrierwave/orm/mongomapper' + include MongoMapper::Document + + mount_uploader :image, ImageUploader +end diff --git a/app/uploaders/image_uploader.rb b/app/uploaders/image_uploader.rb new file mode 100644 index 0000000000000000000000000000000000000000..05ba9614ae0cc024584e83a353556e6954675050 --- /dev/null +++ b/app/uploaders/image_uploader.rb @@ -0,0 +1,17 @@ +class ImageUploader < CarrierWave::Uploader::Base + include CarrierWave::ImageScience + + storage :grid_fs + + def store_dir + "files/#{model.id}" + end + + def extension_white_list + %w(jpg jpeg gif png) + end + + version :small_thumb do + process :resize_to_fill => [100,100] + end +end diff --git a/config/initializers/carrierwave.rb b/config/initializers/carrierwave.rb new file mode 100644 index 0000000000000000000000000000000000000000..6c68ccdadd519e92e55e29a786dd511dd62d9546 --- /dev/null +++ b/config/initializers/carrierwave.rb @@ -0,0 +1,6 @@ +CarrierWave.configure do |config| + config.grid_fs_database = "#diaspora-#{Rails.env}" + config.grid_fs_host = 'localhost' + config.grid_fs_access_url = "/GridFS" + config.storage = :grid_fs +end diff --git a/config/routes.rb b/config/routes.rb index e1ca70581bcc03dc9b1d148480e59b93bc2ade5a..b49c9afaeecd5cbe860098a01d85c0240f45dcce 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -5,6 +5,7 @@ Diaspora::Application.routes.draw do |map| resources :status_messages resources :comments resources :requests + resources :photos match 'warzombie', :to => "dashboards#warzombie" match 'zombiefriends', :to => "dashboards#zombiefriends" diff --git a/spec/fixtures/bp.jpeg b/spec/fixtures/bp.jpeg new file mode 100644 index 0000000000000000000000000000000000000000..33f75aa044a365d52811406f0a43d8d5068cec30 Binary files /dev/null and b/spec/fixtures/bp.jpeg differ diff --git a/spec/models/photo_spec.rb b/spec/models/photo_spec.rb new file mode 100644 index 0000000000000000000000000000000000000000..48ad321c3c4fa3596b162f913dfd0f06cd883e9e --- /dev/null +++ b/spec/models/photo_spec.rb @@ -0,0 +1,13 @@ +require File.dirname(__FILE__) + '/../spec_helper' + +describe Photo do + it 'should upload a photo to GridFS' do + + photo = Photo.new + file = File.open('/spec/fixtures/bp.jpeg') + photo.image = file + photo.save.should == true + + end + +end