dust-generators 0.2.8 → 0.3.1
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/dust/version.rb +2 -2
- data/lib/generators/dust/albums/templates/app/views/albums/show.html.haml +1 -1
- data/lib/generators/dust/scaffold/scaffold_generator.rb +24 -24
- data/lib/generators/dust/scaffold/templates/actions/create.rb +1 -1
- data/lib/generators/dust/scaffold/templates/actions/destroy.rb +2 -2
- data/lib/generators/dust/scaffold/templates/actions/edit.rb +1 -1
- data/lib/generators/dust/scaffold/templates/actions/index.rb +1 -1
- data/lib/generators/dust/scaffold/templates/actions/new.rb +1 -1
- data/lib/generators/dust/scaffold/templates/actions/show.rb +1 -1
- data/lib/generators/dust/scaffold/templates/actions/update.rb +2 -2
- data/lib/generators/dust/scaffold/templates/controller.rb +3 -2
- data/lib/generators/dust/scaffold/templates/migration.rb +2 -2
- data/lib/generators/dust/scaffold/templates/model.rb +13 -11
- data/lib/generators/dust/scaffold/templates/view_controller.rb +8 -6
- data/lib/generators/dust/scaffold/templates/views/front_end/haml/index.html.haml +6 -5
- data/lib/generators/dust/scaffold/templates/views/front_end/haml/show.html.haml +11 -11
- data/lib/generators/dust/scaffold/templates/views/haml/_form.html.haml +1 -1
- data/lib/generators/dust/scaffold/templates/views/haml/_search.html.haml +1 -1
- data/lib/generators/dust/scaffold/templates/views/haml/index.html.haml +2 -2
- data/lib/generators/dust/scaffold/templates/views/haml/show.html.haml +1 -1
- metadata +49 -174
- data/rails_generators/dust_albums/USAGE +0 -6
- data/rails_generators/dust_albums/dust_albums_generator.rb +0 -196
- data/rails_generators/dust_albums/templates/README +0 -5
- data/rails_generators/dust_albums/templates/app/controllers/albums_controller.rb +0 -56
- data/rails_generators/dust_albums/templates/app/controllers/photos_controller.rb +0 -89
- data/rails_generators/dust_albums/templates/app/controllers/view_albums_controller.rb +0 -17
- data/rails_generators/dust_albums/templates/app/helpers/albums_helper.rb +0 -2
- data/rails_generators/dust_albums/templates/app/helpers/photos_helper.rb +0 -2
- data/rails_generators/dust_albums/templates/app/helpers/view_albums_helper.rb +0 -2
- data/rails_generators/dust_albums/templates/app/models/album.rb +0 -42
- data/rails_generators/dust_albums/templates/app/models/photo.rb +0 -18
- data/rails_generators/dust_albums/templates/app/views/albums/_form.html.erb +0 -52
- data/rails_generators/dust_albums/templates/app/views/albums/_search.html.erb +0 -6
- data/rails_generators/dust_albums/templates/app/views/albums/_upload_script.html.erb +0 -37
- data/rails_generators/dust_albums/templates/app/views/albums/edit.html.erb +0 -5
- data/rails_generators/dust_albums/templates/app/views/albums/index.html.erb +0 -61
- data/rails_generators/dust_albums/templates/app/views/albums/manage.html.erb +0 -65
- data/rails_generators/dust_albums/templates/app/views/albums/new.html.erb +0 -6
- data/rails_generators/dust_albums/templates/app/views/albums/show.html.erb +0 -56
- data/rails_generators/dust_albums/templates/app/views/albums/show.js.erb +0 -1
- data/rails_generators/dust_albums/templates/app/views/photos/_form.html.erb +0 -23
- data/rails_generators/dust_albums/templates/app/views/photos/_photo.html.erb +0 -25
- data/rails_generators/dust_albums/templates/app/views/photos/_search.html.erb +0 -6
- data/rails_generators/dust_albums/templates/app/views/photos/array.js.erb +0 -3
- data/rails_generators/dust_albums/templates/app/views/photos/edit.html.erb +0 -28
- data/rails_generators/dust_albums/templates/app/views/photos/index.html.erb +0 -85
- data/rails_generators/dust_albums/templates/app/views/photos/new.html.erb +0 -7
- data/rails_generators/dust_albums/templates/app/views/photos/show.html.erb +0 -26
- data/rails_generators/dust_albums/templates/app/views/photos/show.js.erb +0 -9
- data/rails_generators/dust_albums/templates/app/views/view_albums/index.html.erb +0 -31
- data/rails_generators/dust_albums/templates/app/views/view_albums/show.html.erb +0 -31
- data/rails_generators/dust_albums/templates/images/browse.png +0 -0
- data/rails_generators/dust_albums/templates/images/cancel.png +0 -0
- data/rails_generators/dust_albums/templates/images/save_position.png +0 -0
- data/rails_generators/dust_albums/templates/images/upload.png +0 -0
- data/rails_generators/dust_albums/templates/initializers/flash_session_cookie_middleware.rb +0 -17
- data/rails_generators/dust_albums/templates/initializers/session_store_middleware.rb +0 -1
- data/rails_generators/dust_albums/templates/javascript/dragsort.js +0 -288
- data/rails_generators/dust_albums/templates/javascript/dust_album.js +0 -28
- data/rails_generators/dust_albums/templates/javascript/uploadify/jquery.uploadify.v2.1.0.js +0 -258
- data/rails_generators/dust_albums/templates/javascript/uploadify/swfobject.js +0 -4
- data/rails_generators/dust_albums/templates/javascript/uploadify/uploadify.swf +0 -0
- data/rails_generators/dust_albums/templates/migration/albums_migration.rb +0 -39
- data/rails_generators/dust_albums/templates/stylesheets/dust_album.css +0 -16
- data/rails_generators/dust_albums/templates/stylesheets/dust_album_app.css +0 -15
- data/rails_generators/dust_albums/templates/stylesheets/uploadify.css +0 -84
- data/rails_generators/dust_config/USAGE +0 -23
- data/rails_generators/dust_config/dust_config_generator.rb +0 -32
- data/rails_generators/dust_config/templates/config.yml +0 -8
- data/rails_generators/dust_config/templates/load_config.rb +0 -2
- data/rails_generators/dust_scaffold/USAGE +0 -51
- data/rails_generators/dust_scaffold/dust_scaffold_generator.rb +0 -291
- data/rails_generators/dust_scaffold/templates/actions/create.rb +0 -9
- data/rails_generators/dust_scaffold/templates/actions/destroy.rb +0 -6
- data/rails_generators/dust_scaffold/templates/actions/edit.rb +0 -3
- data/rails_generators/dust_scaffold/templates/actions/index.rb +0 -3
- data/rails_generators/dust_scaffold/templates/actions/new.rb +0 -3
- data/rails_generators/dust_scaffold/templates/actions/show.rb +0 -3
- data/rails_generators/dust_scaffold/templates/actions/update.rb +0 -9
- data/rails_generators/dust_scaffold/templates/controller.rb +0 -9
- data/rails_generators/dust_scaffold/templates/fixtures.yml +0 -9
- data/rails_generators/dust_scaffold/templates/helper.rb +0 -2
- data/rails_generators/dust_scaffold/templates/migration.rb +0 -20
- data/rails_generators/dust_scaffold/templates/model.rb +0 -37
- data/rails_generators/dust_scaffold/templates/tests/rspec/actions/create.rb +0 -11
- data/rails_generators/dust_scaffold/templates/tests/rspec/actions/destroy.rb +0 -6
- data/rails_generators/dust_scaffold/templates/tests/rspec/actions/edit.rb +0 -4
- data/rails_generators/dust_scaffold/templates/tests/rspec/actions/index.rb +0 -4
- data/rails_generators/dust_scaffold/templates/tests/rspec/actions/new.rb +0 -4
- data/rails_generators/dust_scaffold/templates/tests/rspec/actions/show.rb +0 -4
- data/rails_generators/dust_scaffold/templates/tests/rspec/actions/update.rb +0 -11
- data/rails_generators/dust_scaffold/templates/tests/rspec/controller.rb +0 -8
- data/rails_generators/dust_scaffold/templates/tests/rspec/model.rb +0 -7
- data/rails_generators/dust_scaffold/templates/tests/shoulda/actions/create.rb +0 -13
- data/rails_generators/dust_scaffold/templates/tests/shoulda/actions/destroy.rb +0 -8
- data/rails_generators/dust_scaffold/templates/tests/shoulda/actions/edit.rb +0 -6
- data/rails_generators/dust_scaffold/templates/tests/shoulda/actions/index.rb +0 -6
- data/rails_generators/dust_scaffold/templates/tests/shoulda/actions/new.rb +0 -6
- data/rails_generators/dust_scaffold/templates/tests/shoulda/actions/show.rb +0 -6
- data/rails_generators/dust_scaffold/templates/tests/shoulda/actions/update.rb +0 -13
- data/rails_generators/dust_scaffold/templates/tests/shoulda/controller.rb +0 -5
- data/rails_generators/dust_scaffold/templates/tests/shoulda/model.rb +0 -7
- data/rails_generators/dust_scaffold/templates/tests/testunit/actions/create.rb +0 -11
- data/rails_generators/dust_scaffold/templates/tests/testunit/actions/destroy.rb +0 -6
- data/rails_generators/dust_scaffold/templates/tests/testunit/actions/edit.rb +0 -4
- data/rails_generators/dust_scaffold/templates/tests/testunit/actions/index.rb +0 -4
- data/rails_generators/dust_scaffold/templates/tests/testunit/actions/new.rb +0 -4
- data/rails_generators/dust_scaffold/templates/tests/testunit/actions/show.rb +0 -4
- data/rails_generators/dust_scaffold/templates/tests/testunit/actions/update.rb +0 -11
- data/rails_generators/dust_scaffold/templates/tests/testunit/controller.rb +0 -5
- data/rails_generators/dust_scaffold/templates/tests/testunit/model.rb +0 -7
- data/rails_generators/dust_scaffold/templates/view_controller.rb +0 -17
- data/rails_generators/dust_scaffold/templates/views/erb/_form.html.erb +0 -16
- data/rails_generators/dust_scaffold/templates/views/erb/_search.html.erb +0 -6
- data/rails_generators/dust_scaffold/templates/views/erb/edit.html.erb +0 -4
- data/rails_generators/dust_scaffold/templates/views/erb/index.html.erb +0 -24
- data/rails_generators/dust_scaffold/templates/views/erb/new.html.erb +0 -5
- data/rails_generators/dust_scaffold/templates/views/erb/show.html.erb +0 -23
- data/rails_generators/dust_scaffold/templates/views/front_end/index.html.erb +0 -14
- data/rails_generators/dust_scaffold/templates/views/front_end/show.html.erb +0 -17
@@ -1,196 +0,0 @@
|
|
1
|
-
class DustAlbumsGenerator < Rails::Generator::Base
|
2
|
-
|
3
|
-
attr_accessor :parent, :child
|
4
|
-
|
5
|
-
def initialize(runtime_args, runtime_options = {})
|
6
|
-
super
|
7
|
-
usage if @args.empty?
|
8
|
-
|
9
|
-
@parent = @args.first.downcase.singularize || 'album'
|
10
|
-
@child = @args.last.downcase.singularize || 'photo'
|
11
|
-
end
|
12
|
-
|
13
|
-
def manifest
|
14
|
-
record do |m|
|
15
|
-
app(m)
|
16
|
-
migrations(m)
|
17
|
-
css(m)
|
18
|
-
javascript(m)
|
19
|
-
images(m)
|
20
|
-
initializers(m)
|
21
|
-
routes(m)
|
22
|
-
|
23
|
-
m.readme 'README'
|
24
|
-
end
|
25
|
-
end
|
26
|
-
|
27
|
-
def app(m)
|
28
|
-
m.template "app/controllers/albums_controller.rb", "app/controllers/#{parent_plural_name}_controller.rb"
|
29
|
-
m.template "app/controllers/photos_controller.rb", "app/controllers/#{child_plural_name}_controller.rb"
|
30
|
-
m.template "app/controllers/view_albums_controller.rb", "app/controllers/view_#{parent_plural_name}_controller.rb"
|
31
|
-
|
32
|
-
m.template "app/helpers/albums_helper.rb", "app/helpers/#{parent_plural_name}_helper.rb"
|
33
|
-
m.template "app/helpers/photos_helper.rb", "app/helpers/#{child_plural_name}_helper.rb"
|
34
|
-
m.template "app/helpers/view_albums_helper.rb", "app/helpers/view_#{parent_plural_name}_helper.rb"
|
35
|
-
|
36
|
-
m.template "app/models/album.rb", "app/models/#{parent_singular_name}.rb"
|
37
|
-
m.template "app/models/photo.rb", "app/models/#{child_singular_name}.rb"
|
38
|
-
|
39
|
-
m.directory "app/views/#{parent_plural_name}"
|
40
|
-
m.template "app/views/albums/_form.html.erb", "app/views/#{parent_plural_name}/_form.html.erb"
|
41
|
-
m.template "app/views/albums/_search.html.erb", "app/views/#{parent_plural_name}/_search.html.erb"
|
42
|
-
m.template "app/views/albums/_upload_script.html.erb", "app/views/#{parent_plural_name}/_upload_script.html.erb"
|
43
|
-
m.template "app/views/albums/edit.html.erb", "app/views/#{parent_plural_name}/edit.html.erb"
|
44
|
-
m.template "app/views/albums/index.html.erb", "app/views/#{parent_plural_name}/index.html.erb"
|
45
|
-
m.template "app/views/albums/manage.html.erb", "app/views/#{parent_plural_name}/manage.html.erb"
|
46
|
-
m.template "app/views/albums/new.html.erb", "app/views/#{parent_plural_name}/new.html.erb"
|
47
|
-
m.template "app/views/albums/show.html.erb", "app/views/#{parent_plural_name}/show.html.erb"
|
48
|
-
m.template "app/views/albums/show.js.erb", "app/views/#{parent_plural_name}/show.js.erb"
|
49
|
-
|
50
|
-
m.directory "app/views/#{child_plural_name}"
|
51
|
-
m.template "app/views/photos/_form.html.erb", "app/views/#{child_plural_name}/_form.html.erb"
|
52
|
-
m.template "app/views/photos/_search.html.erb", "app/views/#{child_plural_name}/_search.html.erb"
|
53
|
-
m.template "app/views/photos/_photo.html.erb", "app/views/#{child_plural_name}/_#{child_singular_name}.html.erb"
|
54
|
-
m.template "app/views/photos/array.js.erb", "app/views/#{child_plural_name}/array.js.erb"
|
55
|
-
m.template "app/views/photos/edit.html.erb", "app/views/#{child_plural_name}/edit.html.erb"
|
56
|
-
m.template "app/views/photos/index.html.erb", "app/views/#{child_plural_name}/index.html.erb"
|
57
|
-
m.template "app/views/photos/new.html.erb", "app/views/#{child_plural_name}/new.html.erb"
|
58
|
-
m.template "app/views/photos/show.html.erb", "app/views/#{child_plural_name}/show.html.erb"
|
59
|
-
m.template "app/views/photos/show.js.erb", "app/views/#{child_plural_name}/show.js.erb"
|
60
|
-
|
61
|
-
m.directory "app/views/view_#{parent_plural_name}"
|
62
|
-
m.template "app/views/view_albums/index.html.erb", "app/views/view_#{parent_plural_name}/index.html.erb"
|
63
|
-
m.template "app/views/view_albums/show.html.erb", "app/views/view_#{parent_plural_name}/show.html.erb"
|
64
|
-
end
|
65
|
-
|
66
|
-
def migrations(m)
|
67
|
-
m.migration_template "migration/albums_migration.rb", "db/migrate", :migration_file_name => "create_#{parent_plural_name}"
|
68
|
-
end
|
69
|
-
|
70
|
-
def css(m)
|
71
|
-
m.template "stylesheets/dust_album.css", "public/stylesheets/dust_#{parent_singular_name}.css"
|
72
|
-
m.template "stylesheets/uploadify.css", "public/stylesheets/#{parent_singular_name}_uploadify.css"
|
73
|
-
m.template "stylesheets/dust_album_app.css", "public/stylesheets/dust_#{parent_singular_name}_app.css"
|
74
|
-
end
|
75
|
-
|
76
|
-
def javascript(m)
|
77
|
-
m.template "javascript/dragsort.js", "public/javascripts/dragsort.js"
|
78
|
-
m.template "javascript/dust_album.js", "public/javascripts/dust_#{parent_singular_name}.js"
|
79
|
-
|
80
|
-
src_dir = File.join(@source_root, 'javascript', 'uploadify')
|
81
|
-
dst_dir = File.join(RAILS_ROOT, 'public', 'javascripts')
|
82
|
-
|
83
|
-
FileUtils.cp_r src_dir, dst_dir, :verbose => true
|
84
|
-
end
|
85
|
-
|
86
|
-
def images(m)
|
87
|
-
m.template "images/cancel.png", "public/images/cancel.png"
|
88
|
-
m.template "images/browse.png", "public/images/browse.png"
|
89
|
-
m.template "images/upload.png", "public/images/upload.png"
|
90
|
-
m.template "images/save_position.png", "public/images/save_position.png"
|
91
|
-
end
|
92
|
-
|
93
|
-
def initializers(m)
|
94
|
-
m.template "initializers/flash_session_cookie_middleware.rb", "config/initializers/flash_session_cookie_middleware.rb"
|
95
|
-
m.template "initializers/session_store_middleware.rb", "config/initializers/session_store_middleware.rb"
|
96
|
-
end
|
97
|
-
|
98
|
-
def routes(m)
|
99
|
-
m.route :name => "view_#{parent_plural_name}",
|
100
|
-
:url => "all/#{parent_plural_name}",
|
101
|
-
:controller => "view_#{parent_plural_name}",
|
102
|
-
:action => 'index'
|
103
|
-
m.route :name => "view_#{parent_singular_name}",
|
104
|
-
:url => "#{child_plural_name}-for/:filename",
|
105
|
-
:controller => "view_#{parent_plural_name}",
|
106
|
-
:action => 'show'
|
107
|
-
m.route :name => "manage_#{child_plural_name}",
|
108
|
-
:url => "manage-#{child_plural_name}/:id",
|
109
|
-
:controller => "#{parent_plural_name}",
|
110
|
-
:action => 'manage'
|
111
|
-
|
112
|
-
m.route_resources "#{child_plural_name}"
|
113
|
-
m.route_resources "#{parent_plural_name}"
|
114
|
-
end
|
115
|
-
|
116
|
-
#NAMING METHODS
|
117
|
-
def parent_singular_name
|
118
|
-
parent.underscore
|
119
|
-
end
|
120
|
-
|
121
|
-
def child_singular_name
|
122
|
-
child.underscore
|
123
|
-
end
|
124
|
-
|
125
|
-
def parent_plural_name
|
126
|
-
parent.underscore.pluralize
|
127
|
-
end
|
128
|
-
|
129
|
-
def child_plural_name
|
130
|
-
child.underscore.pluralize
|
131
|
-
end
|
132
|
-
|
133
|
-
def parent_class_name
|
134
|
-
parent.camelize
|
135
|
-
end
|
136
|
-
|
137
|
-
def child_class_name
|
138
|
-
child.camelize
|
139
|
-
end
|
140
|
-
|
141
|
-
def parent_plural_class_name
|
142
|
-
parent_plural_name.camelize
|
143
|
-
end
|
144
|
-
|
145
|
-
def child_plural_class_name
|
146
|
-
child_plural_name.camelize
|
147
|
-
end
|
148
|
-
|
149
|
-
def banner
|
150
|
-
<<-EOS
|
151
|
-
Creates two albums and photos with any given naming convention.
|
152
|
-
|
153
|
-
USAGE: #{$0} #{spec.name} parent_name (i.e. albums) child_name (i.e. photos)
|
154
|
-
EOS
|
155
|
-
end
|
156
|
-
|
157
|
-
end
|
158
|
-
|
159
|
-
module Rails
|
160
|
-
module Generator
|
161
|
-
module Commands
|
162
|
-
|
163
|
-
class Base
|
164
|
-
def route_code(route_options)
|
165
|
-
"map.#{route_options[:name]} '#{route_options[:url]}', :controller => '#{route_options[:controller]}', :action => '#{route_options[:action]}'"
|
166
|
-
end
|
167
|
-
end
|
168
|
-
|
169
|
-
# Here's a readable version of the long string used above in route_code;
|
170
|
-
# but it should be kept on one line to avoid inserting extra whitespace
|
171
|
-
# into routes.rb when the generator is run:
|
172
|
-
# "map.#{route_options[:name]} '#{route_options[:url]}',
|
173
|
-
# :controller => '#{route_options[:controller]}',
|
174
|
-
# :action => '#{route_options[:action]}'"
|
175
|
-
|
176
|
-
class Create
|
177
|
-
def route(route_options)
|
178
|
-
sentinel = 'ActionController::Routing::Routes.draw do |map|'
|
179
|
-
logger.route route_code(route_options)
|
180
|
-
gsub_file 'config/routes.rb', /(#{Regexp.escape(sentinel)})/mi do |m|
|
181
|
-
"#{m}\n #{route_code(route_options)}\n"
|
182
|
-
end
|
183
|
-
end
|
184
|
-
end
|
185
|
-
|
186
|
-
class Destroy
|
187
|
-
def route(route_options)
|
188
|
-
logger.remove_route route_code(route_options)
|
189
|
-
to_remove = "\n #{route_code(route_options)}"
|
190
|
-
gsub_file 'config/routes.rb', /(#{to_remove})/mi, ''
|
191
|
-
end
|
192
|
-
end
|
193
|
-
|
194
|
-
end
|
195
|
-
end
|
196
|
-
end
|
@@ -1,56 +0,0 @@
|
|
1
|
-
class <%=parent_plural_class_name%>Controller < ApplicationController
|
2
|
-
|
3
|
-
filter_resource_access
|
4
|
-
|
5
|
-
layout 'cms'
|
6
|
-
|
7
|
-
def index
|
8
|
-
@<%=parent_plural_name%> = <%=parent_class_name%>.page(params[:search], params[:page])
|
9
|
-
end
|
10
|
-
|
11
|
-
def show
|
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
|
-
end
|
15
|
-
|
16
|
-
def new
|
17
|
-
@<%=parent_singular_name%> = <%=parent_class_name%>.new
|
18
|
-
end
|
19
|
-
|
20
|
-
def create
|
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
|
-
else
|
26
|
-
render :action => 'new'
|
27
|
-
end
|
28
|
-
end
|
29
|
-
|
30
|
-
def edit
|
31
|
-
@<%=parent_singular_name%> = <%=parent_class_name%>.find(params[:id])
|
32
|
-
end
|
33
|
-
|
34
|
-
def update
|
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
|
-
else
|
40
|
-
render :action => 'edit'
|
41
|
-
end
|
42
|
-
end
|
43
|
-
|
44
|
-
def destroy
|
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
|
-
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
|
56
|
-
end
|
@@ -1,89 +0,0 @@
|
|
1
|
-
class <%=child_plural_class_name%>Controller < 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
|
-
@<%=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
|
-
end
|
12
|
-
|
13
|
-
def show
|
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%>
|
17
|
-
end
|
18
|
-
|
19
|
-
def new
|
20
|
-
@<%=child_singular_name%> = <%=child_class_name%>.new
|
21
|
-
end
|
22
|
-
|
23
|
-
def create
|
24
|
-
newparams = coerce(params)
|
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%>."
|
28
|
-
respond_to do |format|
|
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%>) } }
|
31
|
-
end
|
32
|
-
else
|
33
|
-
render :action => 'new'
|
34
|
-
end
|
35
|
-
end
|
36
|
-
|
37
|
-
def edit
|
38
|
-
if params[:edit] == '<%=child_singular_name%>'
|
39
|
-
render :layout => false
|
40
|
-
@<%=child_singular_name%> = <%=child_class_name%>.find(params[:id])
|
41
|
-
else
|
42
|
-
@<%=child_singular_name%> = <%=child_class_name%>.find(params[:id])
|
43
|
-
end
|
44
|
-
end
|
45
|
-
|
46
|
-
def update
|
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%>)
|
51
|
-
else
|
52
|
-
render :action => 'edit'
|
53
|
-
end
|
54
|
-
end
|
55
|
-
|
56
|
-
def destroy
|
57
|
-
if request.post?
|
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
|
62
|
-
end
|
63
|
-
flash[:notice] = "<%=child_plural_class_name%> Successfully deleted!"
|
64
|
-
end
|
65
|
-
redirect_to(<%=parent_singular_name%>_path(@<%=child_singular_name%>.<%=parent_singular_name%>))
|
66
|
-
end
|
67
|
-
end
|
68
|
-
|
69
|
-
def array
|
70
|
-
menu_sort(params[:ul])
|
71
|
-
flash[:notice] = "Successfully Sorted <%=child_plural_class_name%>."
|
72
|
-
end
|
73
|
-
|
74
|
-
private
|
75
|
-
def coerce(params)
|
76
|
-
if params[:<%=child_singular_name%>].nil?
|
77
|
-
h = Hash.new
|
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
|
83
|
-
h
|
84
|
-
else
|
85
|
-
params
|
86
|
-
end
|
87
|
-
end
|
88
|
-
|
89
|
-
end
|
@@ -1,17 +0,0 @@
|
|
1
|
-
class View<%=parent_plural_class_name%>Controller < ApplicationController
|
2
|
-
|
3
|
-
def index
|
4
|
-
@<%=parent_plural_name%> = <%=parent_class_name%>.page(params[:search], params[:page])
|
5
|
-
end
|
6
|
-
|
7
|
-
def show
|
8
|
-
if <%=parent_class_name%>.find_by_filename(params[:filename]) == nil
|
9
|
-
@<%=parent_singular_name%> = <%=parent_class_name%>.find(:first)
|
10
|
-
render :file => "#{RAILS_ROOT}/public/404.html", :layout => false, :status => 404
|
11
|
-
else
|
12
|
-
@<%=parent_singular_name%> = <%=parent_class_name%>.find_by_filename(params[:filename])
|
13
|
-
@<%=child_plural_name%> = @<%=parent_singular_name%>.<%=child_plural_name%>.page(params[:page])
|
14
|
-
end
|
15
|
-
end
|
16
|
-
|
17
|
-
end
|
@@ -1,42 +0,0 @@
|
|
1
|
-
class <%=parent_class_name%> < ActiveRecord::Base
|
2
|
-
|
3
|
-
has_many :<%=child_plural_name%>, :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 => "/<%=child_plural_name%>-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 => "/<%=child_plural_name%>-for/#{self.filename}",
|
37
|
-
:active => self.active
|
38
|
-
)
|
39
|
-
@menu_item.save
|
40
|
-
end
|
41
|
-
|
42
|
-
end
|
@@ -1,18 +0,0 @@
|
|
1
|
-
class <%=child_class_name%> < ActiveRecord::Base
|
2
|
-
|
3
|
-
acts_as_nested_set
|
4
|
-
|
5
|
-
belongs_to :<%=parent_singular_name%>
|
6
|
-
has_attached_file :file, :styles => {:large => '800>', :medium => "300x300>", :thumb => "100x100#" }
|
7
|
-
validates_presence_of :<%=parent_singular_name%>
|
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.<%=parent_singular_name%>_page(page)
|
16
|
-
roots.paginate :per_page => 24, :page => page
|
17
|
-
end
|
18
|
-
end
|
@@ -1,52 +0,0 @@
|
|
1
|
-
<%%= stylesheet( 'dust_<%=parent_singular_name%>','<%=parent_singular_name%>_uploadify') %>
|
2
|
-
|
3
|
-
<%% form_for @<%=parent_singular_name%>, :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 %>
|
@@ -1,6 +0,0 @@
|
|
1
|
-
<div id="searchbox">
|
2
|
-
<%% form_tag <%=parent_plural_name%>_path, :method => 'get' do %>
|
3
|
-
<%%= text_field_tag :search, params[:search], :class => "input-text", :placeholder => 'Search <%=parent_plural_class_name%>' %>
|
4
|
-
<%%= image_submit_tag "admin/blank.png", :class => "image-submit"%>
|
5
|
-
<%% end %>
|
6
|
-
</div>
|
@@ -1,37 +0,0 @@
|
|
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
|
-
$('#<%=child_singular_name%>_file').click(function(event) {
|
7
|
-
event.preventDefault();
|
8
|
-
});
|
9
|
-
|
10
|
-
$('#<%=child_singular_name%>_file').uploadify({
|
11
|
-
'uploader' : '/javascripts/uploadify/uploadify.swf',
|
12
|
-
'script' : '/<%=child_plural_name%>/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.<%=child_singular_name%>);},
|
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
|
-
'<%=parent_singular_name%>_id' : '<%%= @<%=parent_singular_name%>.id %>',
|
27
|
-
'title' : 'change me!',
|
28
|
-
'format' : 'json'
|
29
|
-
}
|
30
|
-
});
|
31
|
-
|
32
|
-
$('#<%=child_singular_name%>_submit').click(function(event){
|
33
|
-
event.preventDefault();
|
34
|
-
$('#<%=child_singular_name%>_file').uploadifyUpload();
|
35
|
-
});
|
36
|
-
});
|
37
|
-
</script>
|
@@ -1,61 +0,0 @@
|
|
1
|
-
<%% title "<%=parent_plural_class_name%>" %>
|
2
|
-
<%% heading "<%=parent_plural_class_name%>" %>
|
3
|
-
|
4
|
-
<%%= stylesheet( 'dust_<%=parent_singular_name%>','<%=parent_singular_name%>_uploadify') %>
|
5
|
-
|
6
|
-
<div class="button_bar">
|
7
|
-
<%%= render :partial => 'search' %>
|
8
|
-
<%%=link_to('new <%=parent_singular_name%>', new_<%=parent_singular_name%>_path, :class => 'newfile tip', :title => "New <%=parent_class_name%>")%>
|
9
|
-
</div>
|
10
|
-
|
11
|
-
<div class='<%=child_singular_name%>list'>
|
12
|
-
|
13
|
-
<%%= will_paginate @<%=parent_plural_name%> %>
|
14
|
-
|
15
|
-
<table class="<%=child_plural_name%>">
|
16
|
-
<tr style='color:#222;'>
|
17
|
-
<th></th>
|
18
|
-
<th>
|
19
|
-
<%=parent_class_name%> Title
|
20
|
-
</th>
|
21
|
-
<th>
|
22
|
-
Created At
|
23
|
-
</th>
|
24
|
-
<th></th>
|
25
|
-
</tr>
|
26
|
-
<%% @<%=parent_plural_name%>.each do |<%=parent_singular_name%>| %>
|
27
|
-
<tr class='<%%= cycle('odd', 'even')%>'>
|
28
|
-
|
29
|
-
<td>
|
30
|
-
<%% if <%=parent_singular_name%>.<%=child_plural_name%>.empty? %>
|
31
|
-
<%%= link_to "add <%=child_plural_name%> to #{<%=parent_singular_name%>.title}", <%=parent_singular_name%> %>
|
32
|
-
<%% else %>
|
33
|
-
<%% @<%=child_singular_name%> = <%=parent_singular_name%>.<%=child_plural_name%>.find(:first) %>
|
34
|
-
<%%= link_to image_tag(@<%=child_singular_name%>.file.url(:thumb)), <%=parent_singular_name%> %>
|
35
|
-
<%% end -%>
|
36
|
-
</td>
|
37
|
-
<td>
|
38
|
-
<%%= <%=parent_singular_name%>.title%>
|
39
|
-
</td>
|
40
|
-
<td>
|
41
|
-
<%%= <%=parent_singular_name%>.created_at.to_s(:m_d_y) %>
|
42
|
-
</td>
|
43
|
-
<td>
|
44
|
-
<div style='float:right'>
|
45
|
-
<%%=link_to "", edit_<%=parent_singular_name%>_path(<%=parent_singular_name%>), :class => 'edit' %>
|
46
|
-
<%%=link_to "", <%=parent_singular_name%>, :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 @<%=parent_plural_name%> %>
|
60
|
-
|
61
|
-
|
@@ -1,65 +0,0 @@
|
|
1
|
-
<%%= stylesheet( 'dust_<%=parent_singular_name%>','<%=parent_singular_name%>_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='<%=child_singular_name%>list'>
|
14
|
-
<h1><%%= link_to @<%=parent_singular_name%>.title, <%=parent_singular_name%>_path(@<%=parent_singular_name%>) %></h1>
|
15
|
-
|
16
|
-
<%% form_tag '/<%=child_plural_name%>/destroy' do %>
|
17
|
-
|
18
|
-
<table class='<%=child_plural_name%>'>
|
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
|
-
<%% @<%=parent_singular_name%>.<%=child_plural_name%>.each do |<%=child_singular_name%>| %>
|
35
|
-
<tr class='<%%= cycle('odd', 'even')%>'>
|
36
|
-
<td>
|
37
|
-
<%%= check_box_tag "<%=child_singular_name%>_ids[]", <%=child_singular_name%>.id %>
|
38
|
-
</td>
|
39
|
-
<td>
|
40
|
-
<%%= image_tag(<%=child_singular_name%>.file.url(:thumb), :height => "60") %>
|
41
|
-
|
42
|
-
<div style="display:none"><div id="<%%=<%=child_singular_name%>.id%>"><%%= image_tag(<%=child_singular_name%>.file.url(:original)) %></div></div>
|
43
|
-
</td>
|
44
|
-
<td>
|
45
|
-
<%%= <%=child_singular_name%>.file_file_name %>
|
46
|
-
</td>
|
47
|
-
<td>
|
48
|
-
<%%= number_to_human_size(<%=child_singular_name%>.file_file_size) %>
|
49
|
-
</td>
|
50
|
-
<td>
|
51
|
-
<%%= <%=child_singular_name%>.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>
|