dust_albums 0.0.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (53) hide show
  1. data/Gemfile +13 -0
  2. data/Gemfile.lock +36 -0
  3. data/LICENSE.txt +20 -0
  4. data/README.rdoc +19 -0
  5. data/Rakefile +59 -0
  6. data/app/controllers/albums_controller.rb +50 -0
  7. data/app/controllers/photos_controller.rb +92 -0
  8. data/app/controllers/view_albums_controller.rb +18 -0
  9. data/app/helpers/albums_helper.rb +2 -0
  10. data/app/helpers/photos_helper.rb +2 -0
  11. data/app/helpers/view_albums_helper.rb +2 -0
  12. data/app/models/album.rb +48 -0
  13. data/app/models/photo.rb +18 -0
  14. data/app/views/albums/_form.html.erb +22 -0
  15. data/app/views/albums/_search.html.erb +6 -0
  16. data/app/views/albums/_upload_script.html.erb +39 -0
  17. data/app/views/albums/edit.html.erb +5 -0
  18. data/app/views/albums/index.html.erb +61 -0
  19. data/app/views/albums/new.html.erb +6 -0
  20. data/app/views/albums/show.html.erb +44 -0
  21. data/app/views/albums/show.js.erb +0 -0
  22. data/app/views/photos/_form.html.erb +22 -0
  23. data/app/views/photos/_photo.html.erb +23 -0
  24. data/app/views/photos/edit.html.erb +28 -0
  25. data/app/views/photos/index.html.erb +80 -0
  26. data/app/views/photos/new.html.erb +7 -0
  27. data/app/views/photos/show.html.erb +26 -0
  28. data/app/views/photos/show.js.erb +9 -0
  29. data/app/views/view_albums/index.html.erb +20 -0
  30. data/app/views/view_albums/show.html.erb +20 -0
  31. data/config/routes.rb +10 -0
  32. data/lib/dust_albums.rb +5 -0
  33. data/lib/dust_albums/engine.rb +13 -0
  34. data/lib/dust_albums/middleware.rb +19 -0
  35. data/lib/dust_albums/version.rb +11 -0
  36. data/lib/generators/dust_album/USAGE +8 -0
  37. data/lib/generators/dust_album/dust_album_generator.rb +39 -0
  38. data/lib/generators/dust_album/templates/albums_migration.rb +18 -0
  39. data/lib/generators/dust_album/templates/dust_album.css +11 -0
  40. data/lib/generators/dust_album/templates/images/browse.png +0 -0
  41. data/lib/generators/dust_album/templates/images/cancel.png +0 -0
  42. data/lib/generators/dust_album/templates/images/upload.png +0 -0
  43. data/lib/generators/dust_album/templates/initializers/flash_session_cookie_middleware.rb +19 -0
  44. data/lib/generators/dust_album/templates/initializers/session_store_middleware.rb +5 -0
  45. data/lib/generators/dust_album/templates/jquery-1.4.2.js +6240 -0
  46. data/lib/generators/dust_album/templates/photos_migration.rb +20 -0
  47. data/lib/generators/dust_album/templates/uploadify.css +84 -0
  48. data/lib/generators/dust_album/templates/uploadify/jquery.uploadify.v2.1.0.js +258 -0
  49. data/lib/generators/dust_album/templates/uploadify/swfobject.js +4 -0
  50. data/lib/generators/dust_album/templates/uploadify/uploadify.swf +0 -0
  51. data/test/helper.rb +18 -0
  52. data/test/test_dust_albums.rb +7 -0
  53. metadata +173 -0
data/Gemfile ADDED
@@ -0,0 +1,13 @@
1
+ source "http://rubygems.org"
2
+ # Add dependencies required to use your gem here.
3
+ # Example:
4
+ # gem "activesupport", ">= 2.3.5"
5
+ gem "paperclip"
6
+ # Add dependencies to develop your gem here.
7
+ # Include everything needed to run rake, tests, features, etc.
8
+ group :development do
9
+ #gem "shoulda", ">= 0"
10
+ gem "bundler", "~> 1.0.0"
11
+ gem "jeweler", "~> 1.5.2"
12
+ gem "rcov", ">= 0"
13
+ end
@@ -0,0 +1,36 @@
1
+ GEM
2
+ remote: http://rubygems.org/
3
+ specs:
4
+ activemodel (3.0.3)
5
+ activesupport (= 3.0.3)
6
+ builder (~> 2.1.2)
7
+ i18n (~> 0.4)
8
+ activerecord (3.0.3)
9
+ activemodel (= 3.0.3)
10
+ activesupport (= 3.0.3)
11
+ arel (~> 2.0.2)
12
+ tzinfo (~> 0.3.23)
13
+ activesupport (3.0.3)
14
+ arel (2.0.8)
15
+ builder (2.1.2)
16
+ git (1.2.5)
17
+ i18n (0.5.0)
18
+ jeweler (1.5.2)
19
+ bundler (~> 1.0.0)
20
+ git (>= 1.2.5)
21
+ rake
22
+ paperclip (2.3.8)
23
+ activerecord
24
+ activesupport
25
+ rake (0.8.7)
26
+ rcov (0.9.9)
27
+ tzinfo (0.3.24)
28
+
29
+ PLATFORMS
30
+ ruby
31
+
32
+ DEPENDENCIES
33
+ bundler (~> 1.0.0)
34
+ jeweler (~> 1.5.2)
35
+ paperclip
36
+ rcov
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2011 rossnelson
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,19 @@
1
+ = dust_albums
2
+
3
+ Description goes here.
4
+
5
+ == Contributing to dust_albums
6
+
7
+ * Check out the latest master to make sure the feature hasn't been implemented or the bug hasn't been fixed yet
8
+ * Check out the issue tracker to make sure someone already hasn't requested it and/or contributed it
9
+ * Fork the project
10
+ * Start a feature/bugfix branch
11
+ * Commit and push until you are happy with your contribution
12
+ * Make sure to add tests for it. This is important so I don't break it in a future version unintentionally.
13
+ * Please try not to mess with the Rakefile, version, or history. If you want to have your own version, or is otherwise necessary, that is fine, but please isolate to its own commit so I can cherry-pick around it.
14
+
15
+ == Copyright
16
+
17
+ Copyright (c) 2011 rossnelson. See LICENSE.txt for
18
+ further details.
19
+
@@ -0,0 +1,59 @@
1
+ require 'rubygems'
2
+ require 'bundler'
3
+ require File.join(File.dirname(__FILE__), 'lib', 'dust_albums', 'version')
4
+
5
+ begin
6
+ Bundler.setup(:default, :development)
7
+ rescue Bundler::BundlerError => e
8
+ $stderr.puts e.message
9
+ $stderr.puts "Run `bundle install` to install missing gems"
10
+ exit e.status_code
11
+ end
12
+
13
+ require 'rake'
14
+ require 'jeweler'
15
+
16
+ Jeweler::Tasks.new do |gem|
17
+ # gem is a Gem::Specification... see http://docs.rubygems.org/read/chapter/20 for more options
18
+ gem.name = "dust_albums"
19
+ gem.version = DustAlbums::Version.dup
20
+ gem.homepage = "http://github.com/hificreative/dust_albums_2"
21
+ gem.license = "MIT"
22
+ gem.summary = %Q{Albums and photos for Dus CMS}
23
+ gem.description = %Q{Albums and photos for Dus CMS using paperclip and Uploadify}
24
+ gem.email = "axcess1@me.com"
25
+ gem.authors = ["rossnelson"]
26
+ gem.files = FileList["[A-Z]*", "{app,config,lib}/**/*"]
27
+ # Include your dependencies below. Runtime dependencies are required when using your gem,
28
+ # and development dependencies are only needed for development (ie running rake tasks, tests, etc)
29
+ # gem.add_runtime_dependency 'jabber4r', '> 0.1'
30
+ # gem.add_development_dependency 'rspec', '> 1.2.3'
31
+ # gem.add_runtime_dependency 'paperclip'
32
+ end
33
+ Jeweler::RubygemsDotOrgTasks.new
34
+
35
+ require 'rake/testtask'
36
+ Rake::TestTask.new(:test) do |test|
37
+ test.libs << 'lib' << 'test'
38
+ test.pattern = 'test/**/test_*.rb'
39
+ test.verbose = true
40
+ end
41
+
42
+ require 'rcov/rcovtask'
43
+ Rcov::RcovTask.new do |test|
44
+ test.libs << 'test'
45
+ test.pattern = 'test/**/test_*.rb'
46
+ test.verbose = true
47
+ end
48
+
49
+ task :default => :test
50
+
51
+ require 'rake/rdoctask'
52
+ Rake::RDocTask.new do |rdoc|
53
+ version = File.exist?('VERSION') ? File.read('VERSION') : ""
54
+
55
+ rdoc.rdoc_dir = 'rdoc'
56
+ rdoc.title = "dust_albums #{version}"
57
+ rdoc.rdoc_files.include('README*')
58
+ rdoc.rdoc_files.include('lib/**/*.rb')
59
+ end
@@ -0,0 +1,50 @@
1
+ class AlbumsController < ApplicationController
2
+
3
+ filter_resource_access
4
+
5
+ layout 'cms'
6
+
7
+ def index
8
+ @albums = Album.page(params[:search], params[:page])
9
+ end
10
+
11
+ def show
12
+ @album = Album.find(params[:id], :include => :photos)
13
+ @new_photo = Photo.new(:album_id => @album.id)
14
+ end
15
+
16
+ def new
17
+ @album = Album.new
18
+ end
19
+
20
+ def create
21
+ @album = Album.new(params[:album])
22
+ if @album.save
23
+ flash[:notice] = "Successfully created album."
24
+ redirect_to @album
25
+ else
26
+ render :action => 'new'
27
+ end
28
+ end
29
+
30
+ def edit
31
+ @album = Album.find(params[:id])
32
+ end
33
+
34
+ def update
35
+ @album = Album.find(params[:id])
36
+ if @album.update_attributes(params[:album])
37
+ flash[:notice] = "Successfully updated album."
38
+ redirect_to @album
39
+ else
40
+ render :action => 'edit'
41
+ end
42
+ end
43
+
44
+ def destroy
45
+ @album = Album.find(params[:id])
46
+ @album.destroy
47
+ flash[:notice] = "Successfully destroyed album."
48
+ redirect_to albums_url
49
+ end
50
+ end
@@ -0,0 +1,92 @@
1
+ class PhotosController < ApplicationController
2
+
3
+ filter_access_to :index, :new, :create, :destroy
4
+ filter_access_to :edit, :update, :attribute_check => true
5
+
6
+ layout 'cms'
7
+
8
+ def index
9
+ @photos = Photo.page(params[:search], params[:page])
10
+ @photo_albums = @photos.group_by { |photo| photo.album.title }
11
+ end
12
+
13
+ def show
14
+ @photo = Photo.find(params[:id], :include => :album)
15
+ @total_uploads = Photo.find(:all, :conditions => { :album_id => @photo.album.id})
16
+ end
17
+
18
+ def new
19
+ @photo = Photo.new
20
+ end
21
+
22
+ def create
23
+ newparams = coerce(params)
24
+ @photo = Photo.new(newparams[:photo])
25
+ if @photo.save
26
+ flash[:notice] = "Successfully created photo."
27
+ respond_to do |format|
28
+ format.html { redirect_to @photo.album }
29
+ format.json { render :json => { :result => 'success', :photo => photo_url(@photo) } }
30
+ end
31
+ else
32
+ render :action => 'new'
33
+ end
34
+ end
35
+
36
+ def edit
37
+ if params[:edit] == 'photo'
38
+ render :layout => false
39
+ @photo = Photo.find(params[:id])
40
+ else
41
+ @photo = Photo.find(params[:id])
42
+ end
43
+ end
44
+
45
+ def update
46
+ @photo = Photo.find(params[:id])
47
+ if @photo.update_attributes(params[:photo])
48
+ flash[:notice] = "Successfully updated photo."
49
+ respond_to do |format|
50
+ format.html { redirect_to album_url(@photo.album)}
51
+ format.js { render :json => { :result => 'success', :album => album_url(@photo.album) } }
52
+ end
53
+ else
54
+ render :action => 'edit'
55
+ end
56
+ end
57
+
58
+ def destroy
59
+ if request.post?
60
+ if params[:photo_ids]
61
+ params[:photo_ids].each do |photo|
62
+ @photo = Photo.find photo
63
+ @photo.destroy
64
+ end
65
+ flash[:notice] = "Photos Successfully deleted!"
66
+ end
67
+ respond_to do |format|
68
+ if Photo.all.blank?
69
+ format.html { redirect_to(albums_url) }
70
+ else
71
+ format.html { redirect_to(:back) }
72
+ end
73
+ end
74
+ end
75
+ end
76
+
77
+ private
78
+ def coerce(params)
79
+ if params[:photo].nil?
80
+ h = Hash.new
81
+ h[:photo] = Hash.new
82
+ h[:photo][:album_id] = params[:album_id]
83
+ h[:photo][:title] = params[:title]
84
+ h[:photo][:file] = params[:Filedata]
85
+ h[:photo][:file].content_type = MIME::Types.type_for(h[:photo][:file].original_filename).to_s
86
+ h
87
+ else
88
+ params
89
+ end
90
+ end
91
+
92
+ end
@@ -0,0 +1,18 @@
1
+ class ViewAlbumsController < ApplicationController
2
+ unloadable
3
+
4
+ def index
5
+ @albums = Album.page(params[:search], params[:page])
6
+ end
7
+
8
+ def show
9
+ if Album.find_by_filename(params[:filename]) == nil
10
+ @album = Album.find(:first)
11
+ render :file => "#{RAILS_ROOT}/public/404.html", :layout => false, :status => 404
12
+ else
13
+ @album = Album.find_by_filename(params[:filename])
14
+ @photos = @album.photos.page(params[:search], params[:page])
15
+ end
16
+ end
17
+
18
+ end
@@ -0,0 +1,2 @@
1
+ module AlbumsHelper
2
+ end
@@ -0,0 +1,2 @@
1
+ module PhotosHelper
2
+ end
@@ -0,0 +1,2 @@
1
+ module ViewAlbumsHelper
2
+ end
@@ -0,0 +1,48 @@
1
+ class Album < ActiveRecord::Base
2
+
3
+ has_many :photos, :dependent => :destroy
4
+
5
+ validates_presence_of :title
6
+ validates_presence_of :filename
7
+ validates_uniqueness_of :filename
8
+
9
+ def self.page(search, page)
10
+ with_permissions_to(:manage).search(search).order("title").paginate(:per_page => 10, :page => page)
11
+ end
12
+
13
+ def self.search(search)
14
+ if search
15
+ where("title LIKE ?", "%#{search}%")
16
+ else
17
+ scoped
18
+ end
19
+ end
20
+
21
+ has_one :menu_item, :as => :linkable, :dependent => :destroy
22
+
23
+ after_create :create_menu_item
24
+ after_update :update_menu_item
25
+
26
+ def update_menu_item
27
+ @menu_item = self.menu_item
28
+ if @menu_item == nil
29
+ self.create_menu_item
30
+ else
31
+ @menu_item.update_attributes(
32
+ :title => self.title,
33
+ :url => "/photos-for/#{self.filename}",
34
+ :active => self.active
35
+ )
36
+ end
37
+ end
38
+
39
+ def create_menu_item
40
+ @menu_item = self.build_menu_item(
41
+ :title => self.title,
42
+ :url => "/photos-for/#{self.filename}",
43
+ :active => self.active
44
+ )
45
+ @menu_item.save
46
+ end
47
+
48
+ end
@@ -0,0 +1,18 @@
1
+ class Photo < ActiveRecord::Base
2
+ belongs_to :album
3
+ has_attached_file :file, :styles => { :medium => "300x300>", :thumb => "100x100>" }
4
+ validates_presence_of :album
5
+
6
+ def self.page(search, page)
7
+ with_permissions_to(:manage).search(search).order("title").paginate(:per_page => 20, :page => page)
8
+ end
9
+
10
+ def self.search(search)
11
+ if search
12
+ where("title LIKE ?", "%#{search}%")
13
+ else
14
+ scoped
15
+ end
16
+ end
17
+
18
+ end
@@ -0,0 +1,22 @@
1
+ <%= stylesheet( 'dust_album','uploadify') %>
2
+
3
+ <% form_for @album, :validations => true do |f| %>
4
+ <%= f.error_messages %>
5
+ <p>
6
+ <%= f.label :title %><br />
7
+ <%= f.text_field :title, :class => 'field' %>
8
+ </p>
9
+ <p>
10
+ <%= f.label :filename %><br />
11
+ <%= f.text_field :filename, :class => 'field' %>
12
+ </p>
13
+ <p>
14
+ <%= f.label :desc %><br />
15
+ <%= f.text_area :desc, :class => 'field' %>
16
+ </p>
17
+ <p>
18
+ <%= f.label :active %>
19
+ <%= f.check_box :active %>
20
+ </p>
21
+ <p><%= f.submit %></p>
22
+ <% end %>
@@ -0,0 +1,6 @@
1
+ <div id="searchbox">
2
+ <%= form_tag albums_path, :method => 'get' do %>
3
+ <%= text_field_tag :search, params[:search], :class => "input-text", :placeholder => 'Search Albums' %>
4
+ <%= image_submit_tag "admin/blank.png", :class => "image-submit"%>
5
+ <% end %>
6
+ </div>
@@ -0,0 +1,39 @@
1
+
2
+ <%= javascript_include_tag "uploadify/swfobject", "uploadify/jquery.uploadify.v2.1.0" %>
3
+ <%- session_key = Rails.application.config.session_options[:key] -%>
4
+ <script type="text/javascript" charset="utf-8">
5
+
6
+ $(document).ready(function() {
7
+ $('#photo_file').click(function(event) {
8
+ event.preventDefault();
9
+ });
10
+
11
+ $('#photo_file').uploadify({
12
+ 'uploader' : '/javascripts/uploadify/uploadify.swf',
13
+ 'script' : '/photos',
14
+ 'multi' : true,
15
+ 'auto' : false,
16
+ 'buttonText' : 'Find',
17
+ 'buttonImg' : '/images/browse.png',
18
+ 'cancelImg' : '/images/cancel.png',
19
+ 'wmode' : 'transparent',
20
+ height : 26, // The height of the flash button
21
+ width : 101, // The width of the flash button
22
+ onComplete : function(event, queueID, fileObj, response, data) { var dat = eval('(' +
23
+ response + ')');$.getScript(dat.photo);},
24
+ scriptData: {
25
+ '_http_accept': 'application/javascript',
26
+ 'format' : 'json',
27
+ '_method': 'post',
28
+ '<%= session_key %>' : encodeURIComponent('<%= u cookies[session_key] %>'),
29
+ 'authenticity_token': encodeURIComponent('<%= u form_authenticity_token %>'),
30
+ 'album_id' : '<%= @album.id %>'
31
+ }
32
+ });
33
+
34
+ $('#photo_submit').click(function(event){
35
+ event.preventDefault();
36
+ $('#photo_file').uploadifyUpload();
37
+ });
38
+ });
39
+ </script>