dust-generators 0.2.3 → 0.2.4

Sign up to get free protection for your applications and to get access to all the features.
Files changed (47) hide show
  1. data/lib/dust/version.rb +1 -1
  2. data/lib/generators/dust/albums/albums_generator.rb +129 -34
  3. data/lib/generators/dust/albums/templates/app/controllers/albums_controller.rb +24 -18
  4. data/lib/generators/dust/albums/templates/app/controllers/photos_controller.rb +37 -40
  5. data/lib/generators/dust/albums/templates/app/controllers/view_albums_controller.rb +6 -7
  6. data/lib/generators/dust/albums/templates/app/helpers/albums_helper.rb +1 -1
  7. data/lib/generators/dust/albums/templates/app/helpers/photos_helper.rb +1 -1
  8. data/lib/generators/dust/albums/templates/app/helpers/view_albums_helper.rb +1 -1
  9. data/lib/generators/dust/albums/templates/app/models/album.rb +8 -4
  10. data/lib/generators/dust/albums/templates/app/models/photo.rb +11 -4
  11. data/lib/generators/dust/albums/templates/app/views/albums/_form.html.erb +48 -18
  12. data/lib/generators/dust/albums/templates/app/views/albums/_search.html.erb +4 -4
  13. data/lib/generators/dust/albums/templates/app/views/albums/_upload_script.html.erb +11 -11
  14. data/lib/generators/dust/albums/templates/app/views/albums/edit.html.erb +3 -3
  15. data/lib/generators/dust/albums/templates/app/views/albums/index.html.erb +23 -23
  16. data/lib/generators/dust/albums/templates/app/views/albums/manage.html.erb +65 -0
  17. data/lib/generators/dust/albums/templates/app/views/albums/new.html.erb +3 -3
  18. data/lib/generators/dust/albums/templates/app/views/albums/show.html.erb +33 -21
  19. data/lib/generators/dust/albums/templates/app/views/albums/show.js.erb +1 -0
  20. data/lib/generators/dust/albums/templates/app/views/photos/_form.html.erb +20 -19
  21. data/lib/generators/dust/albums/templates/app/views/photos/_photo.html.erb +25 -23
  22. data/lib/generators/dust/albums/templates/app/views/photos/_search.html.erb +6 -0
  23. data/lib/generators/dust/albums/templates/app/views/photos/array.js.erb +3 -0
  24. data/lib/generators/dust/albums/templates/app/views/photos/edit.html.erb +6 -6
  25. data/lib/generators/dust/albums/templates/app/views/photos/index.html.erb +28 -23
  26. data/lib/generators/dust/albums/templates/app/views/photos/new.html.erb +4 -4
  27. data/lib/generators/dust/albums/templates/app/views/photos/show.html.erb +9 -9
  28. data/lib/generators/dust/albums/templates/app/views/photos/show.js.erb +2 -2
  29. data/lib/generators/dust/albums/templates/app/views/view_albums/index.html.erb +25 -14
  30. data/lib/generators/dust/albums/templates/app/views/view_albums/show.html.erb +23 -12
  31. data/lib/generators/dust/albums/templates/images/save_position.png +0 -0
  32. data/lib/generators/dust/albums/templates/javascripts/dragsort.js +288 -0
  33. data/lib/generators/dust/albums/templates/javascripts/dust_album.js +28 -0
  34. data/lib/generators/dust/albums/templates/{uploadify → javascripts/uploadify}/jquery.uploadify.v2.1.0.js +0 -0
  35. data/lib/generators/dust/albums/templates/{uploadify → javascripts/uploadify}/swfobject.js +0 -0
  36. data/lib/generators/dust/albums/templates/{uploadify → javascripts/uploadify}/uploadify.swf +0 -0
  37. data/lib/generators/dust/albums/templates/migration/albums_migration.rb +39 -0
  38. data/lib/generators/dust/albums/templates/stylesheets/dust_album.css +16 -0
  39. data/lib/generators/dust/albums/templates/stylesheets/dust_album_app.css +15 -0
  40. data/lib/generators/dust/albums/templates/{uploadify.css → stylesheets/uploadify.css} +1 -1
  41. data/rails_generators/dust_albums/templates/app/controllers/view_albums_controller.rb +1 -1
  42. data/rails_generators/dust_albums/templates/app/views/albums/show.html.erb +1 -1
  43. metadata +17 -12
  44. data/lib/generators/dust/albums/templates/albums_migration.rb +0 -18
  45. data/lib/generators/dust/albums/templates/dust_album.css +0 -11
  46. data/lib/generators/dust/albums/templates/jquery-1.4.2.js +0 -6240
  47. data/lib/generators/dust/albums/templates/photos_migration.rb +0 -20
data/lib/dust/version.rb CHANGED
@@ -2,7 +2,7 @@ class Dust
2
2
  module Version
3
3
  MAJOR = 0
4
4
  MINOR = 2
5
- PATCH = 3
5
+ PATCH = 4
6
6
 
7
7
  STRING = [MAJOR, MINOR, PATCH].compact.join('.')
8
8
  end
@@ -1,58 +1,153 @@
1
- require 'rails/generators/active_record'
1
+ require 'generators/dust'
2
+ require 'rails/generators/migration'
3
+ require 'rails/generators/generated_attribute'
2
4
 
3
5
  module Dust
4
6
  module Generators
5
- class AlbumsGenerator < ActiveRecord::Generators::Base
7
+ class AlbumsGenerator < Base
8
+ include Rails::Generators::Migration
6
9
  desc "Create all migrations and copy all files for Dust Albums."
7
-
8
- def self.source_root
10
+
11
+ argument :parent_model_name, :type => :string, :required => true, :banner => 'ParentModelName'
12
+ argument :child_model_name, :type => :string, :required => true, :banner => 'ChildModelName'
13
+
14
+ def source_root
9
15
  @source_root ||= File.expand_path('../templates', __FILE__)
10
16
  end
11
17
 
12
18
  def create_migration
13
- route("resources :albums")
14
- route("resources :photos")
15
- migration_template "albums_migration.rb", "db/migrate/create_albums.rb"
16
- migration_template "photos_migration.rb", "db/migrate/create_photos.rb"
19
+ migration_template "migration/albums_migration.rb", "db/migrate/create_#{parent_plural_name}.rb"
17
20
  end
21
+
22
+ def routes
23
+ route("match \"all/#{parent_plural_name}\" => \"view_#{parent_plural_name}#index\", :as => :view_#{parent_plural_name}")
24
+ route("match \"#{child_plural_name}-for/:filename\" => \"view_#{parent_plural_name}#show\", :as => :view_#{parent_singular_name}")
25
+ route("match \"manage-#{child_plural_name}/:id\" => \"#{parent_plural_name}#manage\", :as => :manage_#{child_plural_name}")
26
+ route("match \"#{child_plural_name}/array\" => \"#{child_plural_name}#array\", :as => :#{child_plural_name}_sort")
27
+ route("match \"destroy-#{child_plural_name}\" => \"#{child_plural_name}#destroy\", :as => :#{child_plural_name}_bulk_delete")
28
+
29
+ route("resources :#{parent_plural_name}")
30
+ route("resources :#{child_plural_name}")
31
+ end
18
32
 
19
- def generate_static_files
20
- copy_file "app/controllers/albums_controller.rb", "app/controllers/albums_controller.rb"
21
- copy_file "app/controllers/photos_controller.rb", "app/controllers/photos_controller.rb"
22
- copy_file "app/controllers/view_albums_controller.rb", "app/controllers/view_albums_controller.rb"
33
+ def app
34
+ template "app/controllers/albums_controller.rb", "app/controllers/#{parent_plural_name}_controller.rb"
35
+ template "app/controllers/photos_controller.rb", "app/controllers/#{child_plural_name}_controller.rb"
36
+ template "app/controllers/view_albums_controller.rb", "app/controllers/view_#{parent_plural_name}_controller.rb"
23
37
 
24
- copy_file "app/helpers/albums_helper.rb", "app/helpers/albums_helper.rb"
25
- copy_file "app/helpers/photos_helper.rb", "app/helpers/photos_helper.rb"
26
- copy_file "app/helpers/view_albums_helper.rb", "app/helpers/view_albums_helper.rb"
38
+ template "app/helpers/albums_helper.rb", "app/helpers/#{parent_plural_name}_helper.rb"
39
+ template "app/helpers/photos_helper.rb", "app/helpers/#{child_plural_name}_helper.rb"
40
+ template "app/helpers/view_albums_helper.rb", "app/helpers/view_#{parent_plural_name}_helper.rb"
27
41
 
28
- copy_file "app/models/album.rb", "app/models/album.rb"
29
- copy_file "app/models/photo.rb", "app/models/photo.rb"
42
+ template "app/models/album.rb", "app/models/#{parent_singular_name}.rb"
43
+ template "app/models/photo.rb", "app/models/#{child_singular_name}.rb"
30
44
 
31
- directory "app/views/albums", "app/views/albums"
32
- directory "app/views/photos", "app/views/photos"
33
- directory "app/views/view_albums", "app/views/view_albums"
34
-
35
- copy_file "dust_album.css", "public/stylesheets/dust_album.css"
36
- copy_file "uploadify.css", "public/stylesheets/uploadify.css"
45
+ template "app/views/albums/_form.html.erb", "app/views/#{parent_plural_name}/_form.html.erb"
46
+ template "app/views/albums/_search.html.erb", "app/views/#{parent_plural_name}/_search.html.erb"
47
+ template "app/views/albums/_upload_script.html.erb", "app/views/#{parent_plural_name}/_upload_script.html.erb"
48
+ template "app/views/albums/edit.html.erb", "app/views/#{parent_plural_name}/edit.html.erb"
49
+ template "app/views/albums/index.html.erb", "app/views/#{parent_plural_name}/index.html.erb"
50
+ template "app/views/albums/manage.html.erb", "app/views/#{parent_plural_name}/manage.html.erb"
51
+ template "app/views/albums/new.html.erb", "app/views/#{parent_plural_name}/new.html.erb"
52
+ template "app/views/albums/show.html.erb", "app/views/#{parent_plural_name}/show.html.erb"
53
+ template "app/views/albums/show.js.erb", "app/views/#{parent_plural_name}/show.js.erb"
37
54
 
38
- copy_file "initializers/flash_session_cookie_middleware.rb", "config/initializers/flash_session_cookie_middleware.rb"
39
- copy_file "initializers/session_store_middleware.rb", "config/initializers/session_store_middleware.rb"
55
+ template "app/views/photos/_form.html.erb", "app/views/#{child_plural_name}/_form.html.erb"
56
+ template "app/views/photos/_search.html.erb", "app/views/#{child_plural_name}/_search.html.erb"
57
+ template "app/views/photos/_photo.html.erb", "app/views/#{child_plural_name}/_#{child_singular_name}.html.erb"
58
+ template "app/views/photos/array.js.erb", "app/views/#{child_plural_name}/array.js.erb"
59
+ template "app/views/photos/edit.html.erb", "app/views/#{child_plural_name}/edit.html.erb"
60
+ template "app/views/photos/index.html.erb", "app/views/#{child_plural_name}/index.html.erb"
61
+ template "app/views/photos/new.html.erb", "app/views/#{child_plural_name}/new.html.erb"
62
+ template "app/views/photos/show.html.erb", "app/views/#{child_plural_name}/show.html.erb"
63
+ template "app/views/photos/show.js.erb", "app/views/#{child_plural_name}/show.js.erb"
40
64
 
41
- copy_file "jquery-1.4.2.js", "public/javascripts/jquery-1.4.2.js"
42
-
43
- copy_file "images/cancel.png", "public/images/cancel.png"
44
- copy_file "images/browse.png", "public/images/browse.png"
45
- copy_file "images/upload.png", "public/images/upload.png"
65
+ template "app/views/view_albums/index.html.erb", "app/views/view_#{parent_plural_name}/index.html.erb"
66
+ template "app/views/view_albums/show.html.erb", "app/views/view_#{parent_plural_name}/show.html.erb"
67
+ end
68
+
69
+ def css
70
+ template "stylesheets/dust_album.css", "public/stylesheets/dust_#{parent_singular_name}.css"
71
+ template "stylesheets/uploadify.css", "public/stylesheets/#{parent_singular_name}_uploadify.css"
72
+ template "stylesheets/dust_album_app.css", "public/stylesheets/dust_#{parent_singular_name}_app.css"
73
+ end
46
74
 
47
- copy_file "dust_album.css", "public/stylesheets/dust_album.css"
48
- copy_file "uploadify.css", "public/stylesheets/uploadify.css"
75
+ def javascript
76
+ template "javascripts/dragsort.js", "public/javascripts/dragsort.js"
77
+ template "javascripts/dust_album.js", "public/javascripts/dust_#{parent_singular_name}.js"
49
78
 
50
- directory "uploadify", "public/javascripts/uploadify"
51
- end
79
+ src_dir = File.join(source_root, 'javascripts', 'uploadify')
80
+ dst_dir = File.join(RAILS_ROOT, 'public', 'javascripts')
52
81
 
82
+ FileUtils.cp_r src_dir, dst_dir, :verbose => true
83
+ end
84
+
85
+ def images
86
+ template "images/cancel.png", "public/images/cancel.png"
87
+ template "images/browse.png", "public/images/browse.png"
88
+ template "images/upload.png", "public/images/upload.png"
89
+ template "images/save_position.png", "public/images/save_position.png"
90
+ end
91
+
92
+ def initializers
93
+ template "initializers/flash_session_cookie_middleware.rb", "config/initializers/flash_session_cookie_middleware.rb"
94
+ template "initializers/session_store_middleware.rb", "config/initializers/session_store_middleware.rb"
95
+ end
96
+
53
97
  def rake_migrations
54
98
  rake("db:migrate")
55
99
  end
100
+
101
+ #NAMING METHODS
102
+ def parent
103
+ parent_model_name.downcase.singularize
104
+ end
105
+
106
+ def child
107
+ child_model_name.downcase.singularize
108
+ end
109
+
110
+ def parent_singular_name
111
+ parent.underscore
112
+ end
113
+
114
+ def child_singular_name
115
+ child.underscore
116
+ end
117
+
118
+ def parent_plural_name
119
+ parent.underscore.pluralize
120
+ end
121
+
122
+ def child_plural_name
123
+ child.underscore.pluralize
124
+ end
125
+
126
+ def parent_class_name
127
+ parent.camelize
128
+ end
129
+
130
+ def child_class_name
131
+ child.camelize
132
+ end
133
+
134
+ def parent_plural_class_name
135
+ parent_plural_name.camelize
136
+ end
137
+
138
+ def child_plural_class_name
139
+ child_plural_name.camelize
140
+ end
141
+
142
+ # FIXME: Should be proxied to ActiveRecord::Generators::Base
143
+ # Implement the required interface for Rails::Generators::Migration.
144
+ def self.next_migration_number(dirname) #:nodoc:
145
+ if ActiveRecord::Base.timestamped_migrations
146
+ Time.now.utc.strftime("%Y%m%d%H%M%S")
147
+ else
148
+ "%.3d" % (current_migration_number(dirname) + 1)
149
+ end
150
+ end
56
151
  end
57
152
  end
58
153
  end
@@ -1,50 +1,56 @@
1
- class AlbumsController < ApplicationController
1
+ class <%=parent_plural_class_name%>Controller < ApplicationController
2
2
 
3
3
  filter_resource_access
4
4
 
5
5
  layout 'cms'
6
6
 
7
7
  def index
8
- @albums = Album.page(params[:search], params[:page])
8
+ @<%=parent_plural_name%> = <%=parent_class_name%>.page(params[:search], params[:page])
9
9
  end
10
10
 
11
11
  def show
12
- @album = Album.find(params[:id], :include => :photos)
13
- @new_photo = Photo.new(:album_id => @album.id)
12
+ @<%=parent_singular_name%> = <%=parent_class_name%>.find(params[:id], :include => :<%=child_plural_name%>)
13
+ @new_<%=child_singular_name%> = <%=child_class_name%>.new(:<%=parent_singular_name%>_id => @<%=parent_singular_name%>.id)
14
14
  end
15
15
 
16
16
  def new
17
- @album = Album.new
17
+ @<%=parent_singular_name%> = <%=parent_class_name%>.new
18
18
  end
19
19
 
20
20
  def create
21
- @album = Album.new(params[:album])
22
- if @album.save
23
- flash[:notice] = "Successfully created album."
24
- redirect_to @album
21
+ @<%=parent_singular_name%> = <%=parent_class_name%>.new(params[:<%=parent_singular_name%>])
22
+ if @<%=parent_singular_name%>.save
23
+ flash[:notice] = "Successfully created <%=parent_singular_name%>."
24
+ redirect_to @<%=parent_singular_name%>
25
25
  else
26
26
  render :action => 'new'
27
27
  end
28
28
  end
29
29
 
30
30
  def edit
31
- @album = Album.find(params[:id])
31
+ @<%=parent_singular_name%> = <%=parent_class_name%>.find(params[:id])
32
32
  end
33
33
 
34
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
35
+ @<%=parent_singular_name%> = <%=parent_class_name%>.find(params[:id])
36
+ if @<%=parent_singular_name%>.update_attributes(params[:<%=parent_singular_name%>])
37
+ flash[:notice] = "Successfully updated <%=parent_singular_name%>."
38
+ redirect_to view_<%=parent_singular_name%>_path(@<%=parent_singular_name%>.filename)
39
39
  else
40
40
  render :action => 'edit'
41
41
  end
42
42
  end
43
43
 
44
44
  def destroy
45
- @album = Album.find(params[:id])
46
- @album.destroy
47
- flash[:notice] = "Successfully destroyed album."
48
- redirect_to albums_url
45
+ @<%=parent_singular_name%> = <%=parent_class_name%>.find(params[:id])
46
+ @<%=parent_singular_name%>.destroy
47
+ flash[:notice] = "Successfully destroyed <%=parent_singular_name%>."
48
+ redirect_to <%=parent_plural_name%>_url
49
49
  end
50
+
51
+ def manage
52
+ @<%=parent_singular_name%> = <%=parent_class_name%>.find(params[:id], :include => :<%=child_plural_name%>)
53
+ @<%=child_plural_name%> = @<%=parent_singular_name%>.<%=child_plural_name%>
54
+ render :layout => false
55
+ end
50
56
  end
@@ -1,4 +1,4 @@
1
- class PhotosController < ApplicationController
1
+ class <%=child_plural_class_name%>Controller < ApplicationController
2
2
 
3
3
  filter_access_to :index, :new, :create, :destroy
4
4
  filter_access_to :edit, :update, :attribute_check => true
@@ -6,27 +6,28 @@ class PhotosController < ApplicationController
6
6
  layout 'cms'
7
7
 
8
8
  def index
9
- @photos = Photo.page(params[:search], params[:page])
10
- @photo_albums = @photos.group_by { |photo| photo.album.title }
9
+ @<%=child_plural_name%> = <%=child_class_name%>.page(params[:search], params[:page])
10
+ @<%=child_singular_name%>_<%=parent_plural_name%> = @<%=child_plural_name%>.group_by { |<%=child_singular_name%>| <%=child_singular_name%>.<%=parent_singular_name%>.title }
11
11
  end
12
12
 
13
13
  def show
14
- @photo = Photo.find(params[:id], :include => :album)
15
- @total_uploads = Photo.find(:all, :conditions => { :album_id => @photo.album.id})
14
+ @<%=child_singular_name%> = <%=child_class_name%>.find(params[:id], :include => :<%=parent_singular_name%>)
15
+ @total_uploads = <%=child_class_name%>.find(:all, :conditions => { :<%=parent_singular_name%>_id => @<%=child_singular_name%>.<%=parent_singular_name%>.id})
16
+ @<%=parent_singular_name%> = @<%=child_singular_name%>.<%=parent_singular_name%>
16
17
  end
17
18
 
18
19
  def new
19
- @photo = Photo.new
20
+ @<%=child_singular_name%> = <%=child_class_name%>.new
20
21
  end
21
22
 
22
23
  def create
23
24
  newparams = coerce(params)
24
- @photo = Photo.new(newparams[:photo])
25
- if @photo.save
26
- flash[:notice] = "Successfully created photo."
25
+ @<%=child_singular_name%> = <%=child_class_name%>.new(newparams[:<%=child_singular_name%>])
26
+ if @<%=child_singular_name%>.save
27
+ flash[:notice] = "Successfully created <%=child_singular_name%>."
27
28
  respond_to do |format|
28
- format.html { redirect_to @photo.album }
29
- format.json { render :json => { :result => 'success', :photo => photo_url(@photo) } }
29
+ format.html { redirect_to @<%=child_singular_name%>.<%=parent_singular_name%> }
30
+ format.json { render :json => { :result => 'success', :<%=child_singular_name%> => <%=child_singular_name%>_url(@<%=child_singular_name%>) } }
30
31
  end
31
32
  else
32
33
  render :action => 'new'
@@ -34,55 +35,51 @@ class PhotosController < ApplicationController
34
35
  end
35
36
 
36
37
  def edit
37
- if params[:edit] == 'photo'
38
+ if params[:edit] == '<%=child_singular_name%>'
38
39
  render :layout => false
39
- @photo = Photo.find(params[:id])
40
+ @<%=child_singular_name%> = <%=child_class_name%>.find(params[:id])
40
41
  else
41
- @photo = Photo.find(params[:id])
42
+ @<%=child_singular_name%> = <%=child_class_name%>.find(params[:id])
42
43
  end
43
44
  end
44
45
 
45
46
  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
47
+ @<%=child_singular_name%> = <%=child_class_name%>.find(params[:id])
48
+ if @<%=child_singular_name%>.update_attributes(params[:<%=child_singular_name%>])
49
+ flash[:notice] = "Successfully updated <%=child_singular_name%>."
50
+ redirect_to <%=parent_singular_name%>_url(@<%=child_singular_name%>.<%=parent_singular_name%>)
53
51
  else
54
52
  render :action => 'edit'
55
53
  end
56
54
  end
57
55
 
58
- def destroy
56
+ def destroy
59
57
  if request.post?
60
- if params[:photo_ids]
61
- params[:photo_ids].each do |photo|
62
- @photo = Photo.find photo
63
- @photo.destroy
58
+ if params[:<%=child_singular_name%>_ids]
59
+ params[:<%=child_singular_name%>_ids].each do |<%=child_singular_name%>|
60
+ @<%=child_singular_name%> = <%=child_class_name%>.find <%=child_singular_name%>
61
+ @<%=child_singular_name%>.destroy
64
62
  end
65
- flash[:notice] = "Photos Successfully deleted!"
63
+ flash[:notice] = "<%=child_plural_class_name%> Successfully deleted!"
66
64
  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
65
+ redirect_to(<%=parent_singular_name%>_path(@<%=child_singular_name%>.<%=parent_singular_name%>))
74
66
  end
75
67
  end
76
68
 
69
+ def array
70
+ menu_sort(params[:ul])
71
+ flash[:notice] = "Successfully Sorted <%=child_plural_class_name%>."
72
+ end
73
+
77
74
  private
78
75
  def coerce(params)
79
- if params[:photo].nil?
76
+ if params[:<%=child_singular_name%>].nil?
80
77
  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
78
+ h[:<%=child_singular_name%>] = Hash.new
79
+ h[:<%=child_singular_name%>][:<%=parent_singular_name%>_id] = params[:<%=parent_singular_name%>_id]
80
+ h[:<%=child_singular_name%>][:title] = params[:title]
81
+ h[:<%=child_singular_name%>][:file] = params[:Filedata]
82
+ h[:<%=child_singular_name%>][:file].content_type = MIME::Types.type_for(h[:<%=child_singular_name%>][:file].original_filename).to_s
86
83
  h
87
84
  else
88
85
  params
@@ -1,17 +1,16 @@
1
- class ViewAlbumsController < ApplicationController
2
- unloadable
1
+ class View<%=parent_plural_class_name%>Controller < ApplicationController
3
2
 
4
3
  def index
5
- @albums = Album.page(params[:search], params[:page])
4
+ @<%=parent_plural_name%> = <%=parent_class_name%>.view(params[:page])
6
5
  end
7
6
 
8
7
  def show
9
- if Album.find_by_filename(params[:filename]) == nil
10
- @album = Album.find(:first)
8
+ if <%=parent_class_name%>.find_by_filename(params[:filename]) == nil
9
+ @<%=parent_singular_name%> = <%=parent_class_name%>.find(:first)
11
10
  render :file => "#{RAILS_ROOT}/public/404.html", :layout => false, :status => 404
12
11
  else
13
- @album = Album.find_by_filename(params[:filename])
14
- @photos = @album.photos.page(params[:search], params[:page])
12
+ @<%=parent_singular_name%> = <%=parent_class_name%>.find_by_filename(params[:filename])
13
+ @<%=child_plural_name%> = @<%=parent_singular_name%>.<%=child_plural_name%>.<%=parent_singular_name%>_page(params[:page])
15
14
  end
16
15
  end
17
16
 
@@ -1,2 +1,2 @@
1
- module AlbumsHelper
1
+ module <%=parent_plural_class_name%>Helper
2
2
  end
@@ -1,2 +1,2 @@
1
- module PhotosHelper
1
+ module <%=child_plural_class_name%>Helper
2
2
  end
@@ -1,2 +1,2 @@
1
- module ViewAlbumsHelper
1
+ module View<%=parent_plural_class_name%>Helper
2
2
  end
@@ -1,6 +1,6 @@
1
- class Album < ActiveRecord::Base
1
+ class <%=parent_class_name%> < ActiveRecord::Base
2
2
 
3
- has_many :photos, :dependent => :destroy
3
+ has_many :<%=child_plural_name%>, :dependent => :destroy
4
4
 
5
5
  validates_presence_of :title
6
6
  validates_presence_of :filename
@@ -10,6 +10,10 @@ class Album < ActiveRecord::Base
10
10
  with_permissions_to(:manage).search(search).order("title").paginate(:per_page => 10, :page => page)
11
11
  end
12
12
 
13
+ def self.view(page)
14
+ order("position").paginate(:per_page => 10, :page => page)
15
+ end
16
+
13
17
  def self.search(search)
14
18
  if search
15
19
  where("title LIKE ?", "%#{search}%")
@@ -30,7 +34,7 @@ class Album < ActiveRecord::Base
30
34
  else
31
35
  @menu_item.update_attributes(
32
36
  :title => self.title,
33
- :url => "/photos-for/#{self.filename}",
37
+ :url => "/<%=child_plural_name%>-for/#{self.filename}",
34
38
  :active => self.active
35
39
  )
36
40
  end
@@ -39,7 +43,7 @@ class Album < ActiveRecord::Base
39
43
  def create_menu_item
40
44
  @menu_item = self.build_menu_item(
41
45
  :title => self.title,
42
- :url => "/photos-for/#{self.filename}",
46
+ :url => "/<%=child_plural_name%>-for/#{self.filename}",
43
47
  :active => self.active
44
48
  )
45
49
  @menu_item.save