dust-generators 0.1.3 → 0.1.4

Sign up to get free protection for your applications and to get access to all the features.
Files changed (106) hide show
  1. data/Gemfile +0 -1
  2. data/Gemfile.lock +0 -18
  3. data/Rakefile +1 -1
  4. data/lib/dust/version.rb +1 -1
  5. data/rails_generators/dust_albums/USAGE +8 -0
  6. data/rails_generators/dust_albums/dust_albums_generator.rb +127 -0
  7. data/rails_generators/dust_albums/templates/README +11 -0
  8. data/rails_generators/dust_albums/templates/app/controllers/albums_controller.rb +56 -0
  9. data/rails_generators/dust_albums/templates/app/controllers/photos_controller.rb +89 -0
  10. data/rails_generators/dust_albums/templates/app/controllers/view_albums_controller.rb +17 -0
  11. data/rails_generators/dust_albums/templates/app/helpers/albums_helper.rb +2 -0
  12. data/rails_generators/dust_albums/templates/app/helpers/photos_helper.rb +2 -0
  13. data/rails_generators/dust_albums/templates/app/helpers/view_albums_helper.rb +2 -0
  14. data/rails_generators/dust_albums/templates/app/models/album.rb +42 -0
  15. data/rails_generators/dust_albums/templates/app/models/photo.rb +18 -0
  16. data/rails_generators/dust_albums/templates/app/views/albums/_form.html.erb +52 -0
  17. data/rails_generators/dust_albums/templates/app/views/albums/_search.html.erb +6 -0
  18. data/rails_generators/dust_albums/templates/app/views/albums/_upload_script.html.erb +37 -0
  19. data/rails_generators/dust_albums/templates/app/views/albums/edit.html.erb +5 -0
  20. data/rails_generators/dust_albums/templates/app/views/albums/index.html.erb +61 -0
  21. data/rails_generators/dust_albums/templates/app/views/albums/manage.html.erb +65 -0
  22. data/rails_generators/dust_albums/templates/app/views/albums/new.html.erb +6 -0
  23. data/rails_generators/dust_albums/templates/app/views/albums/show.html.erb +51 -0
  24. data/rails_generators/dust_albums/templates/app/views/albums/show.js.erb +1 -0
  25. data/rails_generators/dust_albums/templates/app/views/photos/_form.html.erb +23 -0
  26. data/rails_generators/dust_albums/templates/app/views/photos/_photo.html.erb +25 -0
  27. data/rails_generators/dust_albums/templates/app/views/photos/_search.html.erb +6 -0
  28. data/rails_generators/dust_albums/templates/app/views/photos/array.js.erb +3 -0
  29. data/rails_generators/dust_albums/templates/app/views/photos/edit.html.erb +28 -0
  30. data/rails_generators/dust_albums/templates/app/views/photos/index.html.erb +85 -0
  31. data/rails_generators/dust_albums/templates/app/views/photos/new.html.erb +7 -0
  32. data/rails_generators/dust_albums/templates/app/views/photos/show.html.erb +26 -0
  33. data/rails_generators/dust_albums/templates/app/views/photos/show.js.erb +9 -0
  34. data/rails_generators/dust_albums/templates/app/views/view_albums/index.html.erb +27 -0
  35. data/rails_generators/dust_albums/templates/app/views/view_albums/show.html.erb +31 -0
  36. data/rails_generators/dust_albums/templates/images/browse.png +0 -0
  37. data/rails_generators/dust_albums/templates/images/cancel.png +0 -0
  38. data/rails_generators/dust_albums/templates/images/save_position.png +0 -0
  39. data/rails_generators/dust_albums/templates/images/upload.png +0 -0
  40. data/rails_generators/dust_albums/templates/initializers/flash_session_cookie_middleware.rb +17 -0
  41. data/rails_generators/dust_albums/templates/initializers/session_store_middleware.rb +1 -0
  42. data/rails_generators/dust_albums/templates/javascript/dragsort.js +288 -0
  43. data/rails_generators/dust_albums/templates/javascript/dust_album.js +19 -0
  44. data/rails_generators/dust_albums/templates/javascript/uploadify/jquery.uploadify.v2.1.0.js +258 -0
  45. data/rails_generators/dust_albums/templates/javascript/uploadify/swfobject.js +4 -0
  46. data/rails_generators/dust_albums/templates/javascript/uploadify/uploadify.swf +0 -0
  47. data/rails_generators/dust_albums/templates/migration/albums_migration.rb +38 -0
  48. data/rails_generators/dust_albums/templates/stylesheets/dust_album.css +16 -0
  49. data/rails_generators/dust_albums/templates/stylesheets/dust_album_app.css +15 -0
  50. data/rails_generators/dust_albums/templates/stylesheets/uploadify.css +84 -0
  51. data/rails_generators/dust_config/USAGE +23 -0
  52. data/rails_generators/dust_config/dust_config_generator.rb +32 -0
  53. data/rails_generators/dust_config/templates/config.yml +8 -0
  54. data/rails_generators/dust_config/templates/load_config.rb +2 -0
  55. data/rails_generators/dust_scaffold/USAGE +51 -0
  56. data/rails_generators/dust_scaffold/dust_scaffold_generator.rb +232 -0
  57. data/rails_generators/dust_scaffold/templates/actions/create.rb +9 -0
  58. data/rails_generators/dust_scaffold/templates/actions/destroy.rb +6 -0
  59. data/rails_generators/dust_scaffold/templates/actions/edit.rb +3 -0
  60. data/rails_generators/dust_scaffold/templates/actions/index.rb +3 -0
  61. data/rails_generators/dust_scaffold/templates/actions/new.rb +3 -0
  62. data/rails_generators/dust_scaffold/templates/actions/show.rb +3 -0
  63. data/rails_generators/dust_scaffold/templates/actions/update.rb +9 -0
  64. data/rails_generators/dust_scaffold/templates/controller.rb +3 -0
  65. data/rails_generators/dust_scaffold/templates/fixtures.yml +9 -0
  66. data/rails_generators/dust_scaffold/templates/helper.rb +2 -0
  67. data/rails_generators/dust_scaffold/templates/migration.rb +16 -0
  68. data/rails_generators/dust_scaffold/templates/model.rb +3 -0
  69. data/rails_generators/dust_scaffold/templates/tests/rspec/actions/create.rb +11 -0
  70. data/rails_generators/dust_scaffold/templates/tests/rspec/actions/destroy.rb +6 -0
  71. data/rails_generators/dust_scaffold/templates/tests/rspec/actions/edit.rb +4 -0
  72. data/rails_generators/dust_scaffold/templates/tests/rspec/actions/index.rb +4 -0
  73. data/rails_generators/dust_scaffold/templates/tests/rspec/actions/new.rb +4 -0
  74. data/rails_generators/dust_scaffold/templates/tests/rspec/actions/show.rb +4 -0
  75. data/rails_generators/dust_scaffold/templates/tests/rspec/actions/update.rb +11 -0
  76. data/rails_generators/dust_scaffold/templates/tests/rspec/controller.rb +8 -0
  77. data/rails_generators/dust_scaffold/templates/tests/rspec/model.rb +7 -0
  78. data/rails_generators/dust_scaffold/templates/tests/shoulda/actions/create.rb +13 -0
  79. data/rails_generators/dust_scaffold/templates/tests/shoulda/actions/destroy.rb +8 -0
  80. data/rails_generators/dust_scaffold/templates/tests/shoulda/actions/edit.rb +6 -0
  81. data/rails_generators/dust_scaffold/templates/tests/shoulda/actions/index.rb +6 -0
  82. data/rails_generators/dust_scaffold/templates/tests/shoulda/actions/new.rb +6 -0
  83. data/rails_generators/dust_scaffold/templates/tests/shoulda/actions/show.rb +6 -0
  84. data/rails_generators/dust_scaffold/templates/tests/shoulda/actions/update.rb +13 -0
  85. data/rails_generators/dust_scaffold/templates/tests/shoulda/controller.rb +5 -0
  86. data/rails_generators/dust_scaffold/templates/tests/shoulda/model.rb +7 -0
  87. data/rails_generators/dust_scaffold/templates/tests/testunit/actions/create.rb +11 -0
  88. data/rails_generators/dust_scaffold/templates/tests/testunit/actions/destroy.rb +6 -0
  89. data/rails_generators/dust_scaffold/templates/tests/testunit/actions/edit.rb +4 -0
  90. data/rails_generators/dust_scaffold/templates/tests/testunit/actions/index.rb +4 -0
  91. data/rails_generators/dust_scaffold/templates/tests/testunit/actions/new.rb +4 -0
  92. data/rails_generators/dust_scaffold/templates/tests/testunit/actions/show.rb +4 -0
  93. data/rails_generators/dust_scaffold/templates/tests/testunit/actions/update.rb +11 -0
  94. data/rails_generators/dust_scaffold/templates/tests/testunit/controller.rb +5 -0
  95. data/rails_generators/dust_scaffold/templates/tests/testunit/model.rb +7 -0
  96. data/rails_generators/dust_scaffold/templates/views/erb/_form.html.erb +10 -0
  97. data/rails_generators/dust_scaffold/templates/views/erb/edit.html.erb +14 -0
  98. data/rails_generators/dust_scaffold/templates/views/erb/index.html.erb +29 -0
  99. data/rails_generators/dust_scaffold/templates/views/erb/new.html.erb +7 -0
  100. data/rails_generators/dust_scaffold/templates/views/erb/show.html.erb +20 -0
  101. data/rails_generators/dust_scaffold/templates/views/haml/_form.html.haml +10 -0
  102. data/rails_generators/dust_scaffold/templates/views/haml/edit.html.haml +14 -0
  103. data/rails_generators/dust_scaffold/templates/views/haml/index.html.haml +25 -0
  104. data/rails_generators/dust_scaffold/templates/views/haml/new.html.haml +7 -0
  105. data/rails_generators/dust_scaffold/templates/views/haml/show.html.haml +20 -0
  106. metadata +127 -33
data/Gemfile CHANGED
@@ -2,7 +2,6 @@ source "http://rubygems.org"
2
2
  # Add dependencies required to use your gem here.
3
3
  # Example:
4
4
  # gem "activesupport", ">= 2.3.5"
5
- gem 'paperclip'
6
5
  # Add dependencies to develop your gem here.
7
6
  # Include everything needed to run rake, tests, features, etc.
8
7
  group :development do
data/Gemfile.lock CHANGED
@@ -1,31 +1,14 @@
1
1
  GEM
2
2
  remote: http://rubygems.org/
3
3
  specs:
4
- activemodel (3.0.4)
5
- activesupport (= 3.0.4)
6
- builder (~> 2.1.2)
7
- i18n (~> 0.4)
8
- activerecord (3.0.4)
9
- activemodel (= 3.0.4)
10
- activesupport (= 3.0.4)
11
- arel (~> 2.0.2)
12
- tzinfo (~> 0.3.23)
13
- activesupport (3.0.4)
14
- arel (2.0.8)
15
- builder (2.1.2)
16
4
  git (1.2.5)
17
- i18n (0.5.0)
18
5
  jeweler (1.5.2)
19
6
  bundler (~> 1.0.0)
20
7
  git (>= 1.2.5)
21
8
  rake
22
- paperclip (2.3.8)
23
- activerecord
24
- activesupport
25
9
  rake (0.8.7)
26
10
  rcov (0.9.9)
27
11
  shoulda (2.11.3)
28
- tzinfo (0.3.24)
29
12
 
30
13
  PLATFORMS
31
14
  ruby
@@ -33,6 +16,5 @@ PLATFORMS
33
16
  DEPENDENCIES
34
17
  bundler (~> 1.0.0)
35
18
  jeweler (~> 1.5.2)
36
- paperclip
37
19
  rcov
38
20
  shoulda
data/Rakefile CHANGED
@@ -22,7 +22,7 @@ Jeweler::Tasks.new do |gem|
22
22
  gem.description = %Q{Generators such as Uploadify Albums and Photos, and Location or facilities}
23
23
  gem.email = "axcess1@me.com"
24
24
  gem.authors = ["rossnelson"]
25
- gem.files = FileList["[A-Z]*", "{lib}/**/*"]
25
+ gem.files = FileList["{lib,test,rails_generators}/**/*", "[A-Z]*"]
26
26
  end
27
27
 
28
28
  Jeweler::RubygemsDotOrgTasks.new
data/lib/dust/version.rb CHANGED
@@ -2,7 +2,7 @@ class Dust
2
2
  module Version
3
3
  MAJOR = 0
4
4
  MINOR = 1
5
- PATCH = 3
5
+ PATCH = 4
6
6
 
7
7
  STRING = [MAJOR, MINOR, PATCH].compact.join('.')
8
8
  end
@@ -0,0 +1,8 @@
1
+ Description:
2
+ Explain the generator
3
+
4
+ Example:
5
+ rails generate install Thing
6
+
7
+ This will create:
8
+ what/will/it/create
@@ -0,0 +1,127 @@
1
+ class DustAlbumsGenerator < Rails::Generator::Base
2
+
3
+ def manifest
4
+ record do |m|
5
+ app(m)
6
+ migrations(m)
7
+ css(m)
8
+ javascript(m)
9
+ images(m)
10
+ initializers(m)
11
+ routes(m)
12
+
13
+ m.readme 'README'
14
+ end
15
+ end
16
+
17
+ def app(m)
18
+ m.template "app/controllers/albums_controller.rb", "app/controllers/albums_controller.rb"
19
+ m.template "app/controllers/photos_controller.rb", "app/controllers/photos_controller.rb"
20
+ m.template "app/controllers/view_albums_controller.rb", "app/controllers/view_albums_controller.rb"
21
+
22
+ m.template "app/helpers/albums_helper.rb", "app/helpers/albums_helper.rb"
23
+ m.template "app/helpers/photos_helper.rb", "app/helpers/photos_helper.rb"
24
+ m.template "app/helpers/view_albums_helper.rb", "app/helpers/view_albums_helper.rb"
25
+
26
+ m.template "app/models/album.rb", "app/models/album.rb"
27
+ m.template "app/models/photo.rb", "app/models/photo.rb"
28
+
29
+ photos_dir = File.join(@source_root, 'app', 'views', 'photos')
30
+ albums_dir = File.join(@source_root, 'app', 'views', 'albums')
31
+ view_albums_dir = File.join(@source_root, 'app', 'views', 'view_albums')
32
+ dst_dir = File.join(RAILS_ROOT, 'app', 'views')
33
+
34
+ FileUtils.cp_r photos_dir, dst_dir, :verbose => true
35
+ FileUtils.cp_r albums_dir, dst_dir, :verbose => true
36
+ FileUtils.cp_r view_albums_dir, dst_dir, :verbose => true
37
+ end
38
+
39
+ def migrations(m)
40
+ m.migration_template "migration/albums_migration.rb", "db/migrate", :migration_file_name => "create_albums"
41
+ end
42
+
43
+ def css(m)
44
+ m.template "stylesheets/dust_album.css", "public/stylesheets/dust_album.css"
45
+ m.template "stylesheets/uploadify.css", "public/stylesheets/uploadify.css"
46
+ m.template "stylesheets/dust_album_app.css", "public/stylesheets/dust_album_app.css"
47
+ end
48
+
49
+ def javascript(m)
50
+ m.template "javascript/dragsort.js", "public/javascripts/dragsort.js"
51
+ m.template "javascript/dust_album.js", "public/javascripts/dust_album.js"
52
+
53
+ src_dir = File.join(@source_root, 'javascript', 'uploadify')
54
+ dst_dir = File.join(RAILS_ROOT, 'public', 'javascripts')
55
+
56
+ FileUtils.cp_r src_dir, dst_dir, :verbose => true
57
+ end
58
+
59
+ def images(m)
60
+ m.template "images/cancel.png", "public/images/cancel.png"
61
+ m.template "images/browse.png", "public/images/browse.png"
62
+ m.template "images/upload.png", "public/images/upload.png"
63
+ end
64
+
65
+ def initializers(m)
66
+ m.template "initializers/flash_session_cookie_middleware.rb", "config/initializers/flash_session_cookie_middleware.rb"
67
+ m.template "initializers/session_store_middleware.rb", "config/initializers/session_store_middleware.rb"
68
+ end
69
+
70
+ def routes(m)
71
+ m.route_resources 'photos'
72
+ m.route_resources 'albums'
73
+
74
+ m.route :name => 'view_albums',
75
+ :url => 'all/albums',
76
+ :controller => 'view_albums',
77
+ :action => 'index'
78
+ m.route :name => 'view_album',
79
+ :url => 'photos-for/:filename',
80
+ :controller => 'view_albums',
81
+ :action => 'show'
82
+ m.route :name => 'manage_photos',
83
+ :url => 'manage-photos/:id',
84
+ :controller => 'albums',
85
+ :action => 'manage'
86
+ end
87
+
88
+ end
89
+
90
+ module Rails
91
+ module Generator
92
+ module Commands
93
+
94
+ class Base
95
+ def route_code(route_options)
96
+ "map.#{route_options[:name]} '#{route_options[:url]}', :controller => '#{route_options[:controller]}', :action => '#{route_options[:action]}'"
97
+ end
98
+ end
99
+
100
+ # Here's a readable version of the long string used above in route_code;
101
+ # but it should be kept on one line to avoid inserting extra whitespace
102
+ # into routes.rb when the generator is run:
103
+ # "map.#{route_options[:name]} '#{route_options[:name]}',
104
+ # :controller => '#{route_options[:controller]}',
105
+ # :action => '#{route_options[:action]}'"
106
+
107
+ class Create
108
+ def route(route_options)
109
+ sentinel = 'ActionController::Routing::Routes.draw do |map|'
110
+ logger.route route_code(route_options)
111
+ gsub_file 'config/routes.rb', /(#{Regexp.escape(sentinel)})/mi do |m|
112
+ "#{m}\n #{route_code(route_options)}\n"
113
+ end
114
+ end
115
+ end
116
+
117
+ class Destroy
118
+ def route(route_options)
119
+ logger.remove_route route_code(route_options)
120
+ to_remove = "\n #{route_code(route_options)}"
121
+ gsub_file 'config/routes.rb', /(#{to_remove})/mi, ''
122
+ end
123
+ end
124
+
125
+ end
126
+ end
127
+ end
@@ -0,0 +1,11 @@
1
+ ######################################################################################################
2
+ #
3
+ # Unfortunately the generated routes
4
+ #
5
+ # {photos, albums, and three named routes ('manage-photos/:id', 'photos-for/:filename', 'all/albums')}
6
+ #
7
+ # need to be placed before the existing named routes
8
+ #
9
+ # NOW run rake db:migrate
10
+ #
11
+ ######################################################################################################
@@ -0,0 +1,56 @@
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 view_album_path(@album.filename)
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
+
51
+ def manage
52
+ @album = Album.find(params[:id], :include => :photos)
53
+ @photos = @album.photos
54
+ render :layout => false
55
+ end
56
+ end
@@ -0,0 +1,89 @@
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
+ @album = @photo.album
17
+ end
18
+
19
+ def new
20
+ @photo = Photo.new
21
+ end
22
+
23
+ def create
24
+ newparams = coerce(params)
25
+ @photo = Photo.new(newparams[:photo])
26
+ if @photo.save
27
+ flash[:notice] = "Successfully created photo."
28
+ respond_to do |format|
29
+ format.html { redirect_to @photo.album }
30
+ format.json { render :json => { :result => 'success', :photo => photo_url(@photo) } }
31
+ end
32
+ else
33
+ render :action => 'new'
34
+ end
35
+ end
36
+
37
+ def edit
38
+ if params[:edit] == 'photo'
39
+ render :layout => false
40
+ @photo = Photo.find(params[:id])
41
+ else
42
+ @photo = Photo.find(params[:id])
43
+ end
44
+ end
45
+
46
+ def update
47
+ @photo = Photo.find(params[:id])
48
+ if @photo.update_attributes(params[:photo])
49
+ flash[:notice] = "Successfully updated photo."
50
+ redirect_to album_url(@photo.album)
51
+ else
52
+ render :action => 'edit'
53
+ end
54
+ end
55
+
56
+ def destroy
57
+ if request.post?
58
+ if params[:photo_ids]
59
+ params[:photo_ids].each do |photo|
60
+ @photo = Photo.find photo
61
+ @photo.destroy
62
+ end
63
+ flash[:notice] = "Photos Successfully deleted!"
64
+ end
65
+ redirect_to(album_path(@photo.album))
66
+ end
67
+ end
68
+
69
+ def array
70
+ menu_sort(params[:ul])
71
+ flash[:notice] = "Successfully Sorted Photos."
72
+ end
73
+
74
+ private
75
+ def coerce(params)
76
+ if params[:photo].nil?
77
+ h = Hash.new
78
+ h[:photo] = Hash.new
79
+ h[:photo][:album_id] = params[:album_id]
80
+ h[:photo][:title] = params[:title]
81
+ h[:photo][:file] = params[:Filedata]
82
+ h[:photo][:file].content_type = MIME::Types.type_for(h[:photo][:file].original_filename).to_s
83
+ h
84
+ else
85
+ params
86
+ end
87
+ end
88
+
89
+ end
@@ -0,0 +1,17 @@
1
+ class ViewAlbumsController < ApplicationController
2
+
3
+ def index
4
+ @albums = Album.page(params[:search], params[:page])
5
+ end
6
+
7
+ def show
8
+ if Album.find_by_filename(params[:filename]) == nil
9
+ @album = Album.find(:first)
10
+ render :file => "#{RAILS_ROOT}/public/404.html", :layout => false, :status => 404
11
+ else
12
+ @album = Album.find_by_filename(params[:filename])
13
+ @photos = @album.photos.album_page(params[:page])
14
+ end
15
+ end
16
+
17
+ 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,42 @@
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
+ paginate :per_page => 10, :page => page,
11
+ :order => 'title',
12
+ :conditions => ["title LIKE ?", "%#{search}%"]
13
+ end
14
+
15
+ has_one :menu_item, :as => :linkable, :dependent => :destroy
16
+
17
+ after_create :create_menu_item
18
+ after_update :update_menu_item
19
+
20
+ def update_menu_item
21
+ @menu_item = self.menu_item
22
+ if @menu_item == nil
23
+ self.create_menu_item
24
+ else
25
+ @menu_item.update_attributes(
26
+ :title => self.nav,
27
+ :url => "/photos-for/#{self.filename}",
28
+ :active => self.active
29
+ )
30
+ end
31
+ end
32
+
33
+ def create_menu_item
34
+ @menu_item = self.build_menu_item(
35
+ :title => self.nav,
36
+ :url => "/photos-for/#{self.filename}",
37
+ :active => self.active
38
+ )
39
+ @menu_item.save
40
+ end
41
+
42
+ end
@@ -0,0 +1,18 @@
1
+ class Photo < ActiveRecord::Base
2
+
3
+ acts_as_nested_set
4
+
5
+ belongs_to :album
6
+ has_attached_file :file, :styles => {:large => '800>', :medium => "300x300>", :thumb => "100x100#" }
7
+ validates_presence_of :album
8
+
9
+ def self.page(search, page)
10
+ paginate :per_page => 24, :page => page,
11
+ :order => 'title',
12
+ :conditions => ["title LIKE ?", "%#{search}%"]
13
+ end
14
+
15
+ def self.album_page(page)
16
+ roots.paginate :per_page => 24, :page => page
17
+ end
18
+ end
@@ -0,0 +1,52 @@
1
+ <%= stylesheet( 'dust_album','uploadify') %>
2
+
3
+ <% form_for @album, :validations => true do |f| %>
4
+ <%= f.error_messages %>
5
+
6
+ <div class="item">
7
+ <p>
8
+ <%= f.label :active %>
9
+ <%= f.check_box :active %>
10
+ </p>
11
+ </div>
12
+
13
+ <div class="item">
14
+ <p>
15
+ <%= f.label :nav, "Navigation Link" %><br />
16
+ <%= f.text_field :nav, :class => 'field' %>
17
+ </p>
18
+ </div>
19
+
20
+ <div class="item">
21
+ <p>
22
+ <%= f.label :title %><br />
23
+ <%= f.text_field :title, :class => 'field' %>
24
+ </p>
25
+ </div>
26
+
27
+ <div class="item">
28
+ <p>
29
+ <%= f.label :heading %><br />
30
+ <%= f.text_field :heading, :class => 'field' %>
31
+ </p>
32
+ </div>
33
+
34
+ <div class="item">
35
+ <p>
36
+ <%= f.label :filename %><br />
37
+ <%= f.text_field :filename, :class => 'field' %>
38
+ </p>
39
+ </div>
40
+
41
+ <div class="item">
42
+ <p>
43
+ <%= f.label :desc %><br />
44
+ <%= f.text_area :desc, :class => 'field' %>
45
+ </p>
46
+ </div>
47
+
48
+ <div class="item">
49
+ <p><%= f.submit %></p>
50
+ </div>
51
+
52
+ <% 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,37 @@
1
+ <%- session_key_name = ActionController::Base.session_options[:key] -%>
2
+ <%= javascript_include_tag "uploadify/swfobject", "uploadify/jquery.uploadify.v2.1.0" %>
3
+
4
+ <script type="text/javascript" charset="utf-8">
5
+ $(document).ready(function() {
6
+ $('#photo_file').click(function(event) {
7
+ event.preventDefault();
8
+ });
9
+
10
+ $('#photo_file').uploadify({
11
+ 'uploader' : '/javascripts/uploadify/uploadify.swf',
12
+ 'script' : '/photos/create',
13
+ 'multi' : true,
14
+ 'auto' : false,
15
+ 'buttonText' : 'Find',
16
+ 'buttonImg' : '/images/browse.png',
17
+ 'cancelImg' : '/images/cancel.png',
18
+ 'wmode' : 'transparent',
19
+ height : 26, // The height of the flash button
20
+ width : 101, // The width of the flash button
21
+ onComplete : function(event, queueID, fileObj, response, data) { var dat = eval('(' +
22
+ response + ')');$.getScript(dat.photo);},
23
+ 'scriptData': {
24
+ '<%= session_key_name %>' : encodeURIComponent('<%= u cookies[session_key_name] %>'),
25
+ 'authenticity_token' : encodeURIComponent('<%= u form_authenticity_token if protect_against_forgery? %>'),
26
+ 'album_id' : '<%= @album.id %>',
27
+ 'title' : 'change me!',
28
+ 'format' : 'json'
29
+ }
30
+ });
31
+
32
+ $('#photo_submit').click(function(event){
33
+ event.preventDefault();
34
+ $('#photo_file').uploadifyUpload();
35
+ });
36
+ });
37
+ </script>
@@ -0,0 +1,5 @@
1
+ <% title "Edit Album" %>
2
+
3
+ <%= stylesheet( 'dust_album','uploadify') %>
4
+
5
+ <%= render :partial => 'form' %>
@@ -0,0 +1,61 @@
1
+ <% title "Albums" %>
2
+ <% heading "Albums" %>
3
+
4
+ <%= stylesheet( 'dust_album','uploadify') %>
5
+
6
+ <div class="button_bar">
7
+ <%= render :partial => 'search' %>
8
+ <%=link_to('new allbum', new_album_path, :class => 'newfile tip', :title => "New Album")%>
9
+ </div>
10
+
11
+ <div class='photolist'>
12
+
13
+ <%= will_paginate @albums %>
14
+
15
+ <table class="photos">
16
+ <tr style='color:#222;'>
17
+ <th></th>
18
+ <th>
19
+ Album Title
20
+ </th>
21
+ <th>
22
+ Created At
23
+ </th>
24
+ <th></th>
25
+ </tr>
26
+ <% @albums.each do |album| %>
27
+ <tr class='<%= cycle('odd', 'even')%>'>
28
+
29
+ <td>
30
+ <% if album.photos.empty? %>
31
+ <%= link_to "add photos to #{album.title}", album %>
32
+ <% else %>
33
+ <% @photo = album.photos.find(:first) %>
34
+ <%= link_to image_tag(@photo.file.url(:thumb)), album %>
35
+ <% end -%>
36
+ </td>
37
+ <td>
38
+ <%= album.title%>
39
+ </td>
40
+ <td>
41
+ <%= album.created_at.to_s(:m_d_y) %>
42
+ </td>
43
+ <td>
44
+ <div style='float:right'>
45
+ <%=link_to('', edit_album_path(album), :class => 'edit')%>
46
+ <%=link_to "", album, :confirm => 'Are you sure?', :method => :delete, :class => 'destroy' %>
47
+ </div>
48
+ </td>
49
+ </tr>
50
+ <% end %>
51
+
52
+ </table>
53
+
54
+
55
+ </div>
56
+
57
+ <div class="clear"></div>
58
+
59
+ <%= will_paginate @albums %>
60
+
61
+
@@ -0,0 +1,65 @@
1
+ <%= stylesheet( 'dust_album','uploadify') %>
2
+
3
+ <script type="text/javascript" charset="utf-8">
4
+ $(document).ready(function() {
5
+ $(function () { // this line makes sure this code runs on page load
6
+ $('.checkall').click(function () {
7
+ $(this).parents('form:eq(0)').find(':checkbox').attr('checked', this.checked);
8
+ });
9
+ });
10
+ });
11
+ </script>
12
+
13
+ <div class='photolist'>
14
+ <h1><%= link_to @album.title, album_path(@album) %></h1>
15
+
16
+ <% form_tag '/photos/destroy' do %>
17
+
18
+ <table class='photos'>
19
+ <tr style='color:#222;'>
20
+ <th>
21
+
22
+ </th>
23
+ <th></th>
24
+ <th>
25
+ File Name
26
+ </th>
27
+ <th>
28
+ File Size
29
+ </th>
30
+ <th>
31
+ Created At
32
+ </th>
33
+ </tr>
34
+ <% @album.photos.each do |photo| %>
35
+ <tr class='<%= cycle('odd', 'even')%>'>
36
+ <td>
37
+ <%= check_box_tag "photo_ids[]", photo.id %>
38
+ </td>
39
+ <td>
40
+ <%= image_tag(photo.file.url(:thumb), :height => "60") %>
41
+
42
+ <div style="display:none"><div id="<%=photo.id%>"><%= image_tag(photo.file.url(:original)) %></div></div>
43
+ </td>
44
+ <td>
45
+ <%= photo.file_file_name %>
46
+ </td>
47
+ <td>
48
+ <%= number_to_human_size(photo.file_file_size) %>
49
+ </td>
50
+ <td>
51
+ <%= photo.created_at.to_s(:m_d_y) %>
52
+ </td>
53
+ </tr>
54
+ <% end %>
55
+ <tr class='odd'>
56
+ <td colspan='5'>
57
+ <input type="checkbox" class="checkall"> Check all
58
+ <%= submit_tag "Delete checked" %>
59
+ </td>
60
+ </tr>
61
+ </table>
62
+
63
+ <% end -%>
64
+
65
+ </div>