Permalink
Browse files

dragonfly added

  • Loading branch information...
1 parent 127ed17 commit 3b003af18308535f63be9998fe39f92534698919 @zlorfi committed Mar 16, 2013
View
@@ -3,3 +3,4 @@
body
meta
.DS_Store
+upload/*
View
@@ -5,7 +5,9 @@ gem 'compass'
gem 'zurb-foundation'
gem 'puma'
gem 'haml'
-gem 'rack-cache'
+gem 'rack-cache', :require => 'rack/cache'
+gem 'dragonfly'
+gem 'mongoid'
group :development do
gem 'shotgun'
View
@@ -1,16 +1,35 @@
GEM
remote: http://rubygems.org/
specs:
+ activemodel (3.2.12)
+ activesupport (= 3.2.12)
+ builder (~> 3.0.0)
+ activesupport (3.2.12)
+ i18n (~> 0.6)
+ multi_json (~> 1.0)
+ builder (3.0.4)
chunky_png (1.2.7)
coderay (1.0.9)
compass (0.12.2)
chunky_png (~> 1.2)
fssm (>= 0.2.7)
sass (~> 3.1)
+ dragonfly (0.9.14)
+ multi_json (~> 1.0)
+ rack
fssm (0.2.10)
haml (4.0.0)
tilt
+ i18n (0.6.4)
method_source (0.8.1)
+ mongoid (3.0.18)
+ activemodel (~> 3.1)
+ moped (~> 1.2)
+ origin (~> 1.0)
+ tzinfo (~> 0.3.22)
+ moped (1.3.2)
+ multi_json (1.6.1)
+ origin (1.0.11)
pry (0.9.12)
coderay (~> 1.0.5)
method_source (~> 0.8)
@@ -31,6 +50,7 @@ GEM
tilt (~> 1.3, >= 1.3.4)
slop (3.4.4)
tilt (1.3.5)
+ tzinfo (0.3.36)
zurb-foundation (4.0.7)
sass (>= 3.2.0)
@@ -39,7 +59,9 @@ PLATFORMS
DEPENDENCIES
compass
+ dragonfly
haml
+ mongoid
pry
puma
rack-cache
View
@@ -0,0 +1,3 @@
+# Sinatra Gallery App
+
+- with Zurb
View
@@ -4,6 +4,8 @@
require 'compass'
require "zurb-foundation"
require 'haml'
+require 'dragonfly'
+require 'mongoid'
#configure { set :server, :puma }
@@ -12,6 +14,17 @@ class App < Sinatra::Base
enable :logging
end
+ app = Dragonfly[:images].configure_with(:imagemagick)
+
+ app.datastore = Dragonfly::DataStorage::FileDataStore.new
+ app.define_macro_on_include(Mongoid::Document, :image_accessor)
+
+ app.datastore.configure do |d|
+ d.root_path = File.join('upload')
+ end
+
+ Mongoid.load!('config/mongoid.yml', ENV['RACK_ENV'] )
+
configure do
Compass.configuration do |config|
config.project_path = File.dirname __FILE__
@@ -24,6 +37,27 @@ class App < Sinatra::Base
set :scss, Compass.sass_engine_options
set :server, :puma
+ enable :sessions
+ end
+
+ helpers do
+ def flash(message = '')
+ session[:flash] = message
+ end
+ end
+
+ before do
+ @flash = session.delete(:flash)
+ end
+
+ class Picture
+ include Mongoid::Document
+
+ field :image_uid
+ field :image_name
+ field :base_path
+
+ image_accessor :image
end
get "/stylesheets/*.css" do |path|
@@ -35,4 +69,24 @@ class App < Sinatra::Base
haml :index
end
+ get "/upload" do
+ haml :upload
+ end
+
+ post "/upload" do
+ if params[:file]
+ filename = params[:file][:filename]
+ file = params[:file][:tempfile]
+
+ image_uid = app.store(file)
+ picture = Picture.create(image_uid: image_uid, image_name: filename)
+
+ flash "Upload successful of #{filename}"
+ else
+ flash 'You have to choose a file'
+ end
+
+ redirect '/upload'
+ end
+
end
View
@@ -3,12 +3,12 @@ require 'sinatra'
require 'rack/cache'
require "./app"
-use Rack::Cache,
- :metastore => 'file:./tmp/meta',
- :entitystore => 'file:./tmp/body',
- #:metastore => 'memcached://localhost:11211/meta',
- #:entitystore => 'memcached://localhost:11211/body',
- :verbose => true
+#use Rack::Cache,
+# :metastore => 'file:./tmp/meta',
+# :entitystore => 'file:./tmp/body',
+# #:metastore => 'memcached://localhost:11211/meta',
+# #:entitystore => 'memcached://localhost:11211/body',
+# :verbose => true
#run Sinatra::Application
run App
View
@@ -0,0 +1,6 @@
+development:
+ sessions:
+ default:
+ database: sinatra_gallery
+ hosts:
+ - localhost:27017
Oops, something went wrong.

0 comments on commit 3b003af

Please sign in to comment.