Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/cloudinary'
Browse files Browse the repository at this point in the history
Conflicts:
	server/model.rb
  • Loading branch information
jfontan committed May 20, 2013
2 parents d21f21a + bff96fe commit 498d022
Show file tree
Hide file tree
Showing 5 changed files with 24 additions and 3 deletions.
1 change: 1 addition & 0 deletions Gemfile
Expand Up @@ -4,4 +4,5 @@ gem 'sinatra'
gem 'mongo'
gem 'bson_ext'
gem 'json'
gem 'cloudinary'

8 changes: 8 additions & 0 deletions Gemfile.lock
@@ -1,14 +1,21 @@
GEM
remote: http://rubygems.org/
specs:
aws_cf_signer (0.1.1)
bson (1.4.0)
bson_ext (1.4.0)
cloudinary (1.0.37)
aws_cf_signer
rest-client
json (1.6.1)
mime-types (1.19)
mongo (1.4.0)
bson (= 1.4.0)
rack (1.3.5)
rack-protection (1.1.4)
rack
rest-client (1.6.7)
mime-types (>= 1.16)
sinatra (1.3.1)
rack (~> 1.3, >= 1.3.4)
rack-protection (~> 1.1, >= 1.1.2)
Expand All @@ -20,6 +27,7 @@ PLATFORMS

DEPENDENCIES
bson_ext
cloudinary
json
mongo
sinatra
2 changes: 1 addition & 1 deletion server/assets/gallery.html
Expand Up @@ -91,7 +91,7 @@ <h1><a href="http://glsl.heroku.com/">GLSL Sandbox</a></h1>
<div id="gallery">

<% effects.each do |effect| %>
<a href='/e#<%= effect['_id'] %>.<%= effect['versions'].length-1 %>'><img src='<%= effect['image'] %>'></a>
<a href='/e#<%= effect['_id'] %>.<%= effect['versions'].length-1 %>'><img src='<%= image(effect) %>'></a>
<% end %>

</div>
Expand Down
4 changes: 4 additions & 0 deletions server/main.rb
Expand Up @@ -4,6 +4,7 @@
require 'mongo'
require 'json'
require 'erb'
require 'cloudinary'

$: << './server'

Expand All @@ -15,6 +16,9 @@
set :public_folder, 'server/assets'

GALLERY=ERB.new(File.read('server/assets/gallery.html'))
IMAGE_PREFIX=ENV['IMAGE_PREFIX']||''
uri=URI.parse(ENV['CLOUDINARY_URL'])
CLOUDINARY_PROJECT=uri.host

$glsl=GlslDatabase.new

Expand Down
12 changes: 10 additions & 2 deletions server/model.rb
Expand Up @@ -32,6 +32,11 @@ def next_page
@extra[:page]+1
end
end

def image(effect)
"http://res.cloudinary.com/#{CLOUDINARY_PROJECT}/image/upload/"<<
"#{IMAGE_PREFIX}#{effect['_id']}.png"
end
end

class GlslDatabase
Expand Down Expand Up @@ -62,13 +67,16 @@ def save_version(code_id, code)
:query => { :_id => code_id },
:update => {
'$set' => {
:modified_at => time,
:image => code_data['image'].tr(%q{"'><}, '')
:modified_at => time
},
'$push' => { :versions => data }
}
})

Cloudinary::Uploader.upload(
code_data['image'],
:public_id => IMAGE_PREFIX+code_id.to_s)

code=$glsl.get_code(code_id)

version=code['versions'].length-1
Expand Down

0 comments on commit 498d022

Please sign in to comment.