spud_photos 0.0.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (86) hide show
  1. data/MIT-LICENSE +20 -0
  2. data/README.markdown +53 -0
  3. data/Rakefile +40 -0
  4. data/app/assets/images/spud/photos/buttons/cog_16x16.png +0 -0
  5. data/app/assets/images/spud/photos/buttons/x_16x16.png +0 -0
  6. data/app/assets/images/spud/photos/photo_albums_thumb.png +0 -0
  7. data/app/assets/images/spud/photos/photo_albums_thumb@2x.png +0 -0
  8. data/app/assets/javascripts/spud/admin/photos.js +158 -0
  9. data/app/assets/stylesheets/photo_albums.css +4 -0
  10. data/app/assets/stylesheets/photo_galleries.css +4 -0
  11. data/app/assets/stylesheets/spud/admin/photo_albums.css +4 -0
  12. data/app/assets/stylesheets/spud/admin/photo_galleries.css +4 -0
  13. data/app/assets/stylesheets/spud/admin/photos.css +112 -0
  14. data/app/controllers/photo_albums_controller.rb +25 -0
  15. data/app/controllers/photo_galleries_controller.rb +11 -0
  16. data/app/controllers/spud/admin/photo_albums_controller.rb +46 -0
  17. data/app/controllers/spud/admin/photo_galleries_controller.rb +51 -0
  18. data/app/controllers/spud/admin/photos_controller.rb +89 -0
  19. data/app/helpers/photo_albums_helper.rb +2 -0
  20. data/app/helpers/photo_galleries_helper.rb +2 -0
  21. data/app/helpers/spud/admin/photo_albums_helper.rb +2 -0
  22. data/app/helpers/spud/admin/photo_galleries_helper.rb +2 -0
  23. data/app/helpers/spud/admin/photos_helper.rb +2 -0
  24. data/app/models/spud_photo.rb +23 -0
  25. data/app/models/spud_photo_album.rb +34 -0
  26. data/app/models/spud_photo_gallery.rb +29 -0
  27. data/app/views/layouts/spud/admin/spud_photos.html.erb +8 -0
  28. data/app/views/photo_albums/index.html.erb +18 -0
  29. data/app/views/photo_albums/show.html.erb +17 -0
  30. data/app/views/photo_galleries/index.html.erb +18 -0
  31. data/app/views/spud/admin/photo_albums/_album.html.erb +10 -0
  32. data/app/views/spud/admin/photo_albums/_form.html.erb +37 -0
  33. data/app/views/spud/admin/photo_albums/destroy.js.erb +1 -0
  34. data/app/views/spud/admin/photo_albums/edit.html.erb +1 -0
  35. data/app/views/spud/admin/photo_albums/index.html.erb +9 -0
  36. data/app/views/spud/admin/photo_albums/new.html.erb +1 -0
  37. data/app/views/spud/admin/photo_galleries/_form.html.erb +40 -0
  38. data/app/views/spud/admin/photo_galleries/destroy.js.erb +1 -0
  39. data/app/views/spud/admin/photo_galleries/edit.html.erb +1 -0
  40. data/app/views/spud/admin/photo_galleries/index.html.erb +17 -0
  41. data/app/views/spud/admin/photo_galleries/new.html.erb +1 -0
  42. data/app/views/spud/admin/photos/_form.html.erb +48 -0
  43. data/app/views/spud/admin/photos/_photo.html.erb +9 -0
  44. data/app/views/spud/admin/photos/destroy.js.erb +1 -0
  45. data/app/views/spud/admin/photos/edit.html.erb +1 -0
  46. data/app/views/spud/admin/photos/index.html.erb +12 -0
  47. data/app/views/spud/admin/photos/new.html.erb +1 -0
  48. data/config/routes.rb +23 -0
  49. data/db/migrate/20120228232120_create_spud_photos.rb +13 -0
  50. data/db/migrate/20120228232329_create_spud_photo_albums.rb +15 -0
  51. data/db/migrate/20120228232344_create_spud_photo_galleries.rb +15 -0
  52. data/lib/generators/spud/photos/views_generator.rb +14 -0
  53. data/lib/spud_photos.rb +6 -0
  54. data/lib/spud_photos/configuration.rb +18 -0
  55. data/lib/spud_photos/engine.rb +37 -0
  56. data/lib/spud_photos/version.rb +5 -0
  57. data/lib/tasks/spud_photos_tasks.rake +4 -0
  58. data/test/dummy/README.rdoc +261 -0
  59. data/test/dummy/Rakefile +7 -0
  60. data/test/dummy/app/assets/javascripts/application.js +15 -0
  61. data/test/dummy/app/assets/stylesheets/application.css +13 -0
  62. data/test/dummy/app/controllers/application_controller.rb +3 -0
  63. data/test/dummy/app/helpers/application_helper.rb +2 -0
  64. data/test/dummy/app/views/layouts/application.html.erb +14 -0
  65. data/test/dummy/config.ru +4 -0
  66. data/test/dummy/config/application.rb +56 -0
  67. data/test/dummy/config/boot.rb +10 -0
  68. data/test/dummy/config/database.yml +15 -0
  69. data/test/dummy/config/environment.rb +5 -0
  70. data/test/dummy/config/environments/development.rb +37 -0
  71. data/test/dummy/config/environments/production.rb +67 -0
  72. data/test/dummy/config/environments/test.rb +37 -0
  73. data/test/dummy/config/initializers/backtrace_silencers.rb +7 -0
  74. data/test/dummy/config/initializers/inflections.rb +15 -0
  75. data/test/dummy/config/initializers/mime_types.rb +5 -0
  76. data/test/dummy/config/initializers/secret_token.rb +7 -0
  77. data/test/dummy/config/initializers/session_store.rb +8 -0
  78. data/test/dummy/config/initializers/wrap_parameters.rb +14 -0
  79. data/test/dummy/config/locales/en.yml +5 -0
  80. data/test/dummy/config/routes.rb +4 -0
  81. data/test/dummy/public/404.html +26 -0
  82. data/test/dummy/public/422.html +26 -0
  83. data/test/dummy/public/500.html +25 -0
  84. data/test/dummy/public/favicon.ico +0 -0
  85. data/test/dummy/script/rails +6 -0
  86. metadata +213 -0
@@ -0,0 +1,11 @@
1
+ class PhotoGalleriesController < ApplicationController
2
+
3
+ respond_to :html, :json, :xml
4
+ layout Spud::Photos.base_layout
5
+
6
+ def index
7
+ @photo_galleries = SpudPhotoGallery.order('created_at desc')
8
+ respond_with @photo_galleries
9
+ end
10
+
11
+ end
@@ -0,0 +1,46 @@
1
+ class Spud::Admin::PhotoAlbumsController < Spud::Admin::ApplicationController
2
+
3
+ before_filter :get_album, :only => [:show, :edit, :update, :destroy]
4
+ respond_to :html, :json, :xml
5
+ layout 'spud/admin/spud_photos'
6
+
7
+ def index
8
+ @photo_albums = SpudPhotoAlbum.all
9
+ respond_with @photo_albums
10
+ end
11
+
12
+ def show
13
+ respond_with @photo_album
14
+ end
15
+
16
+ def new
17
+ @photo_album = SpudPhotoAlbum.new
18
+ respond_with @photo_album
19
+ end
20
+
21
+ def create
22
+ @photo_album = SpudPhotoAlbum.new(params[:spud_photo_album])
23
+ flash[:notice] = 'SpudPhotoAlbum created successfully' if @photo_album.save
24
+ respond_with @photo_album, :location => spud_admin_photo_albums_path
25
+ end
26
+
27
+ def edit
28
+ respond_with @photo_album
29
+ end
30
+
31
+ def update
32
+ @photo_album.update_attributes(params[:spud_photo_album])
33
+ flash[:notice] = 'SpudPhotoAlbum updated successfully' if @photo_album.save
34
+ respond_with @photo_album, :location => spud_admin_photo_albums_path
35
+ end
36
+
37
+ def destroy
38
+ flash[:notice] = 'SpudPhotoAlbum deleted successfully' if @photo_album.destroy
39
+ respond_with @photo_album, :location => spud_admin_photo_albums_path
40
+ end
41
+
42
+ def get_album
43
+ @photo_album = SpudPhotoAlbum.find(params[:id])
44
+ end
45
+
46
+ end
@@ -0,0 +1,51 @@
1
+ class Spud::Admin::PhotoGalleriesController < Spud::Admin::ApplicationController
2
+
3
+ before_filter :get_gallery, :only => [:show, :edit, :update, :destroy]
4
+ before_filter :get_albums, :only => [:new, :create, :edit, :update]
5
+ respond_to :html, :json, :xml
6
+ layout 'spud/admin/spud_photos'
7
+
8
+ def index
9
+ @photo_galleries = SpudPhotoGallery.all
10
+ respond_with @photo_galleries
11
+ end
12
+
13
+ def show
14
+ respond_with @photo_gallery
15
+ end
16
+
17
+ def new
18
+ @photo_gallery = SpudPhotoGallery.new
19
+ respond_with @photo_gallery
20
+ end
21
+
22
+ def create
23
+ @photo_gallery = SpudPhotoGallery.new(params[:spud_photo_gallery])
24
+ flash[:notice] = 'SpudPhotoGallery created successfully' if @photo_gallery.save
25
+ respond_with @photo_gallery, :location => spud_admin_photo_galleries_path
26
+ end
27
+
28
+ def edit
29
+ respond_with @photo_gallery
30
+ end
31
+
32
+ def update
33
+ @photo_gallery.update_attributes(params[:spud_photo_gallery])
34
+ flash[:notice] = 'SpudPhotoGallery updated successfully' if @photo_gallery.save
35
+ respond_with @photo_gallery, :location => spud_admin_photo_galleries_path
36
+ end
37
+
38
+ def destroy
39
+ flash[:notice] = 'SpudPhotoGallery deleted successfully' if @photo_gallery.destroy
40
+ respond_with @photo_gallery, :location => spud_admin_photo_galleries_path
41
+ end
42
+
43
+ def get_gallery
44
+ @photo_gallery = SpudPhotoGallery.find(params[:id])
45
+ end
46
+
47
+ def get_albums
48
+ @photo_albums = SpudPhotoAlbum.all
49
+ end
50
+
51
+ end
@@ -0,0 +1,89 @@
1
+ class Spud::Admin::PhotosController < Spud::Admin::ApplicationController
2
+
3
+ before_filter :get_photo, :only => [:show, :edit, :update, :destroy]
4
+ respond_to :html, :json, :xml, :js
5
+ layout 'spud/admin/spud_photos'
6
+
7
+ add_breadcrumb 'Photos', :spud_admin_photos_path
8
+ belongs_to_spud_app :photos
9
+
10
+ def index
11
+ @photos = SpudPhoto.all
12
+ respond_with @photos
13
+ end
14
+
15
+ def show
16
+ respond_with @photo
17
+ end
18
+
19
+ def new
20
+ @photo = SpudPhoto.new
21
+ respond_with @photo do |format|
22
+ format.js { render 'new', :layout => false }
23
+ end
24
+ end
25
+
26
+ def create
27
+ @photo = SpudPhoto.new(params[:spud_photo])
28
+ if @photo.save
29
+ success = true
30
+ flash[:notice] = 'SpudPhoto created successfully'
31
+ end
32
+ if request.xhr?
33
+ render json_for_photo(success)
34
+ else
35
+ respond_with @photo, :location => spud_admin_photos_path
36
+ end
37
+ end
38
+
39
+ def edit
40
+ respond_with @photo do |format|
41
+ format.js { render 'edit', :layout => false }
42
+ end
43
+ end
44
+
45
+ def update
46
+ @photo.update_attributes(params[:spud_photo])
47
+ if @photo.save
48
+ success = true
49
+ flash[:notice] = 'SpudPhoto updated successfully'
50
+ end
51
+ if request.xhr?
52
+ render json_for_photo(success)
53
+ else
54
+ respond_with @photo, :location => spud_admin_photos_path
55
+ end
56
+ end
57
+
58
+ def destroy
59
+ flash[:notice] = 'SpudPhoto deleted successfully' if @photo.destroy
60
+ respond_with @photo, :location => spud_admin_photos_path
61
+ end
62
+
63
+ def mass_destroy
64
+ @photos = SpudPhoto.where(:id => params[:spud_photo_ids])
65
+ flash[:notice] = 'Photos deleted successfully' if @photos.destroy_all
66
+ respond_with @photos, :location => spud_admin_photos_path
67
+ end
68
+
69
+ private
70
+
71
+ def get_photo
72
+ @photo = SpudPhoto.find(params[:id])
73
+ end
74
+
75
+ def json_for_photo(success)
76
+ if success
77
+ return {:status => 200, :json => {
78
+ :id => @photo.id,
79
+ :html => render_to_string(:partial => 'photo', :locals => {:photo => @photo}, :layout => nil)
80
+ }}
81
+ else
82
+ return {:status => 422, :json => {
83
+ :id => 0,
84
+ :html => render_to_string(:partial => 'form', :layout => nil)
85
+ }}
86
+ end
87
+ end
88
+
89
+ end
@@ -0,0 +1,2 @@
1
+ module PhotoAlbumsHelper
2
+ end
@@ -0,0 +1,2 @@
1
+ module PhotoGalleriesHelper
2
+ end
@@ -0,0 +1,2 @@
1
+ module Spud::Admin::PhotoAlbumsHelper
2
+ end
@@ -0,0 +1,2 @@
1
+ module Spud::Admin::PhotoGalleriesHelper
2
+ end
@@ -0,0 +1,2 @@
1
+ module Spud::Admin::PhotosHelper
2
+ end
@@ -0,0 +1,23 @@
1
+ class SpudPhoto < ActiveRecord::Base
2
+ has_and_belongs_to_many :albums,
3
+ :class_name => 'SpudPhotoAlbum',
4
+ :join_table => 'spud_photo_albums_photos'
5
+
6
+ has_attached_file :photo,
7
+ :styles => lambda { |attachment| attachment.instance.dynamic_styles },
8
+ :storage => Spud::Photos.paperclip_storage,
9
+ :s3_credentials => Spud::Photos.s3_credentials,
10
+ :url => Spud::Photos.storage_url,
11
+ :path => Spud::Photos.storage_path
12
+
13
+ validates_attachment_presence :photo
14
+
15
+ def dynamic_styles
16
+ admin_styles = {
17
+ :spud_admin_small => '125x125#',
18
+ :spud_admin_medium => '300x300'
19
+ }
20
+ return admin_styles.merge(Spud::Photos.config.photo_styles)
21
+ end
22
+
23
+ end
@@ -0,0 +1,34 @@
1
+ class SpudPhotoAlbum < ActiveRecord::Base
2
+ has_and_belongs_to_many :galleries,
3
+ :class_name => 'SpudPhotoGallery',
4
+ :join_table => 'spud_photo_galleries_albums'
5
+ has_and_belongs_to_many :photos,
6
+ :class_name => 'SpudPhoto',
7
+ :join_table => 'spud_photo_albums_photos',
8
+ :order => 'created_at'
9
+ validates_presence_of :title, :url_name
10
+ validates_uniqueness_of :title, :url_name
11
+ before_validation :set_url_name
12
+
13
+
14
+ def top_photo_url(style)
15
+ unless photos.empty?
16
+ return photos.first.photo.url(style)
17
+ end
18
+ end
19
+
20
+ def photos_available
21
+ if photo_ids.any?
22
+ return SpudPhoto.where('id not in (?)', photo_ids)
23
+ else
24
+ return SpudPhoto.all
25
+ end
26
+ end
27
+
28
+ private
29
+
30
+ def set_url_name
31
+ self.url_name = self.title.parameterize
32
+ end
33
+
34
+ end
@@ -0,0 +1,29 @@
1
+ class SpudPhotoGallery < ActiveRecord::Base
2
+ has_and_belongs_to_many :albums,
3
+ :class_name => 'SpudPhotoAlbum',
4
+ :join_table => 'spud_photo_galleries_albums'
5
+ validates_presence_of :title, :url_name
6
+ validates_uniqueness_of :title, :url_name
7
+ before_validation :set_url_name
8
+
9
+ def top_photo_url(style)
10
+ unless albums.empty?
11
+ return albums.first.top_photo_url(style)
12
+ end
13
+ end
14
+
15
+ def albums_available
16
+ if album_ids.any?
17
+ return SpudPhotoAlbum.where('id not in (?)', album_ids)
18
+ else
19
+ return SpudPhotoAlbum.all
20
+ end
21
+ end
22
+
23
+ private
24
+
25
+ def set_url_name
26
+ self.url_name = self.title.parameterize
27
+ end
28
+
29
+ end
@@ -0,0 +1,8 @@
1
+ <%= content_for :head do %>
2
+ <%= javascript_include_tag "spud/admin/photos" %>
3
+ <%= stylesheet_link_tag 'spud/admin/photos' %>
4
+ <script type="text/javascript">
5
+ $(document).ready(Spud.Admin.Photos.init);
6
+ </script>
7
+ <% end %>
8
+ <%= render :template => 'layouts/spud/admin/detail' %>
@@ -0,0 +1,18 @@
1
+ <% content_for :title do %>
2
+ <%= (@photo_gallery ? @photo_gallery.title : 'Photo Albums') %> | <%= Spud::Core.site_name %>
3
+ <% end %>
4
+
5
+ <% content_for :head do %>
6
+
7
+ <% end %>
8
+
9
+ <h2><%= (@photo_gallery ? @photo_gallery.title : 'Photo Albums') %></h2>
10
+
11
+ <div id="spud_photo_albums">
12
+ <% @photo_albums.each do |album| %>
13
+ <div class="spud_photo_album_thumbnail">
14
+ <h3><%= link_to album.title, (@photo_gallery ? photo_gallery_photo_album_path(@photo_gallery.url_name, album.url_name) : photo_album_path(album.url_name) ) %></h3>
15
+ <%= image_tag album.top_photo_url(:medium), :title => album.title %>
16
+ </div>
17
+ <% end %>
18
+ </div>
@@ -0,0 +1,17 @@
1
+ <% content_for :title do %>
2
+ <%= @photo_album.title %> | <%= Spud::Core.site_name %>
3
+ <% end %>
4
+
5
+ <% content_for :head do %>
6
+
7
+ <% end %>
8
+
9
+ <h2>Photo Album: <% @photo_album.title %></h2>
10
+
11
+ <div id="spud_photo_galleries">
12
+ <% @photo_album.photos.each do |photo| %>
13
+ <div class="spud_photo_album_thumbnail">
14
+ <%= link_to image_tag(photo.photo.url(:small), :alt => photo.caption, :title => photo.title), photo.photo.url(:large) %>
15
+ </div>
16
+ <% end %>
17
+ </div>
@@ -0,0 +1,18 @@
1
+ <% content_for :title do %>
2
+ Photo Galleries | <%= Spud::Core.site_name %>
3
+ <% end %>
4
+
5
+ <% content_for :head do %>
6
+
7
+ <% end %>
8
+
9
+ <h2>Photo Galleries</h2>
10
+
11
+ <div id="spud_photo_galleries">
12
+ <% @photo_galleries.each do |gallery| %>
13
+ <div class="spud_photo_gallery_thumbnail">
14
+ <h3><%= link_to gallery.title, photo_gallery_photo_albums_path(gallery.url_name) %></h3>
15
+ <%= image_tag gallery.top_photo_url(:medium), :title => gallery.title %>
16
+ </div>
17
+ <% end %>
18
+ </div>
@@ -0,0 +1,10 @@
1
+ <div id="spud_admin_photo_album_<%= album.id %>" class="spud_admin_photo_ui_thumb" style="background-image:url('<%= album.top_photo_url(:spud_admin_small) %>')">
2
+ <h5><%= album.title %></h5>
3
+ <div style="display:none;">
4
+ <%= check_box_tag 'spud_photo_gallery[album_ids][]', album.id, (@photo_gallery && @photo_gallery.album_ids.include?(album.id)) %>
5
+ </div>
6
+ <div class="spud_admin_photo_ui_thumb_controls">
7
+ <%= link_to 'Edit', edit_spud_admin_photo_album_path(album), :class => 'spud_admin_photos_btn_edit' %>
8
+ <%= link_to 'Delete', spud_admin_photo_album_path(album), :method => :delete, :class => 'spud_admin_photos_btn_delete', :remote => true, :confirm => 'Are you sure?' %>
9
+ </div>
10
+ </div>
@@ -0,0 +1,37 @@
1
+ <%= form_for @photo_album, :url => path, :html => {:class => 'form-horizontal', :id => 'spud_admin_photo_album_form'} do |f| %>
2
+
3
+ <%= error_messages_for(f.object) %>
4
+
5
+ <fieldset>
6
+ <legend>Photo Album Info</legend>
7
+ <div class="control-group">
8
+ <%= f.label :title, :class => "control-label" %>
9
+ <div class="controls">
10
+ <%= f.text_field :title %>
11
+ </div>
12
+ </div>
13
+ </fieldset>
14
+
15
+ <fieldset class="spud_admin_photos_album_fieldset">
16
+ <%= link_to "New Photo", new_spud_admin_photo_path, :class => "spud_admin_photo_create ajax btn btn-primary", :title => "New Photo" %>
17
+ <legend>Select Photos</legend>
18
+ <div id="spud_admin_photos_selected" class="spud_admin_photos_selection_left">
19
+ <h4>Selected:</h4>
20
+ <div class="spud_admin_photo_ui_thumbs spud_admin_photo_ui_thumbs_sortable">
21
+ <%= render :partial => '/spud/admin/photos/photo', :collection => @photo_album.photos %>
22
+ </div>
23
+ </div>
24
+ <div id="spud_admin_photos_available" class="spud_admin_photos_selection_right">
25
+ <h4>Available:</h4>
26
+ <div class="spud_admin_photo_ui_thumbs spud_admin_photo_ui_thumbs_sortable">
27
+ <%= render :partial => '/spud/admin/photos/photo', :collection => @photo_album.photos_available %>
28
+ </div>
29
+ </div>
30
+ </fieldset>
31
+
32
+ <div class="form-actions" style="clear:both">
33
+ <%= f.submit "Save Photo Album", :class=>"btn btn-primary form-btn", "data-loading-text" => "Saving..." %>
34
+ or <%=link_to "cancel", request.referer, :class => "btn" %>
35
+ </div>
36
+
37
+ <% end %>
@@ -0,0 +1 @@
1
+ Spud.Admin.Photos.markPhotoAlbumAsDeleted(<%= @photo_album.id %>);
@@ -0,0 +1 @@
1
+ <%= render :partial => 'form', :locals => {:path => spud_admin_photo_album_path(@photo_album)} %>
@@ -0,0 +1,9 @@
1
+ <%= content_for :data_controls do %>
2
+ <%= link_to "New Photo Album", new_spud_admin_photo_album_path, :class => "btn btn-primary", :title => "New Photo Album" %>
3
+ <% end %>
4
+
5
+ <%= content_for :detail do %>
6
+ <div id="spud_admin_photo_galleries" class="spud_admin_photo_ui_thumbs">
7
+ <%= render :partial => 'album', :collection => @photo_albums %>
8
+ <div>
9
+ <% end %>