Skip to content

Commit

Permalink
Use cloudinary to save and show images
Browse files Browse the repository at this point in the history
  • Loading branch information
jfontan committed Sep 23, 2012
1 parent 456dba5 commit bff96fe
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 3 deletions.
2 changes: 1 addition & 1 deletion server/assets/gallery.html
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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']
: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 bff96fe

Please sign in to comment.