easy_admin_ui 0.4.0 → 0.5.0
Sign up to get free protection for your applications and to get access to all the features.
- data/README +4 -15
- data/Rakefile +1 -1
- data/VERSION +1 -1
- data/{assets/icons → app/assets/images/easy_admin_ui}/classify.png +0 -0
- data/{assets/icons → app/assets/images/easy_admin_ui}/connect.png +0 -0
- data/{assets/icons → app/assets/images/easy_admin_ui}/delete.png +0 -0
- data/{assets/icons → app/assets/images/easy_admin_ui}/disconnect.png +0 -0
- data/{assets/icons → app/assets/images/easy_admin_ui}/pencil.png +0 -0
- data/{assets/icons → app/assets/images/easy_admin_ui}/show.png +0 -0
- data/app/assets/stylesheets/easy_admin_ui/easy_admin_ui.sass +47 -0
- data/app/views/easy_admin_ui/destroy.js.erb +1 -0
- data/{templates → app/views}/easy_admin_ui/edit.html.erb +0 -0
- data/{templates → app/views}/easy_admin_ui/index.html.erb +0 -0
- data/{templates → app/views}/easy_admin_ui/new.html.erb +0 -0
- data/{templates → app/views}/easy_admin_ui/show.html.erb +0 -0
- data/easy_admin_ui.gemspec +80 -21
- data/lib/easy_admin_ui/core_ext.rb +1 -3
- data/lib/easy_admin_ui/rails/engine.rb +10 -0
- data/lib/easy_admin_ui/tasks.rb +0 -10
- data/lib/easy_admin_ui/view_helpers.rb +3 -3
- data/lib/easy_admin_ui.rb +1 -9
- data/vendor/plugins/make_resourceful/.gitignore +1 -0
- data/vendor/plugins/make_resourceful/DEFAULTS +148 -0
- data/vendor/plugins/make_resourceful/LICENSE +7 -0
- data/vendor/plugins/make_resourceful/README.rdoc +239 -0
- data/vendor/plugins/make_resourceful/Rakefile +31 -0
- data/vendor/plugins/make_resourceful/VERSION +1 -0
- data/vendor/plugins/make_resourceful/generators/resourceful_scaffold/resourceful_scaffold_generator.rb +87 -0
- data/vendor/plugins/make_resourceful/generators/resourceful_scaffold/templates/controller.rb +5 -0
- data/vendor/plugins/make_resourceful/generators/resourceful_scaffold/templates/fixtures.yml +10 -0
- data/vendor/plugins/make_resourceful/generators/resourceful_scaffold/templates/functional_test.rb +50 -0
- data/vendor/plugins/make_resourceful/generators/resourceful_scaffold/templates/helper.rb +2 -0
- data/vendor/plugins/make_resourceful/generators/resourceful_scaffold/templates/migration.rb +13 -0
- data/vendor/plugins/make_resourceful/generators/resourceful_scaffold/templates/model.rb +2 -0
- data/vendor/plugins/make_resourceful/generators/resourceful_scaffold/templates/unit_test.rb +7 -0
- data/vendor/plugins/make_resourceful/generators/resourceful_scaffold/templates/view__form.haml +5 -0
- data/vendor/plugins/make_resourceful/generators/resourceful_scaffold/templates/view_edit.haml +11 -0
- data/vendor/plugins/make_resourceful/generators/resourceful_scaffold/templates/view_index.haml +5 -0
- data/vendor/plugins/make_resourceful/generators/resourceful_scaffold/templates/view_new.haml +9 -0
- data/vendor/plugins/make_resourceful/generators/resourceful_scaffold/templates/view_partial.haml +12 -0
- data/vendor/plugins/make_resourceful/generators/resourceful_scaffold/templates/view_show.haml +14 -0
- data/vendor/plugins/make_resourceful/init.rb +3 -0
- data/vendor/plugins/make_resourceful/lib/resourceful/base.rb +63 -0
- data/vendor/plugins/make_resourceful/lib/resourceful/builder.rb +385 -0
- data/vendor/plugins/make_resourceful/lib/resourceful/default/accessors.rb +402 -0
- data/vendor/plugins/make_resourceful/lib/resourceful/default/actions.rb +101 -0
- data/vendor/plugins/make_resourceful/lib/resourceful/default/callbacks.rb +51 -0
- data/vendor/plugins/make_resourceful/lib/resourceful/default/responses.rb +118 -0
- data/vendor/plugins/make_resourceful/lib/resourceful/default/urls.rb +137 -0
- data/vendor/plugins/make_resourceful/lib/resourceful/maker.rb +84 -0
- data/vendor/plugins/make_resourceful/lib/resourceful/response.rb +33 -0
- data/vendor/plugins/make_resourceful/lib/resourceful/serialize.rb +185 -0
- data/vendor/plugins/make_resourceful/spec/accessors_spec.rb +474 -0
- data/vendor/plugins/make_resourceful/spec/actions_spec.rb +310 -0
- data/vendor/plugins/make_resourceful/spec/base_spec.rb +12 -0
- data/vendor/plugins/make_resourceful/spec/builder_spec.rb +332 -0
- data/vendor/plugins/make_resourceful/spec/callbacks_spec.rb +71 -0
- data/vendor/plugins/make_resourceful/spec/integration_spec.rb +394 -0
- data/vendor/plugins/make_resourceful/spec/maker_spec.rb +91 -0
- data/vendor/plugins/make_resourceful/spec/response_spec.rb +37 -0
- data/vendor/plugins/make_resourceful/spec/responses_spec.rb +314 -0
- data/vendor/plugins/make_resourceful/spec/rspec-rails/LICENSE +37 -0
- data/vendor/plugins/make_resourceful/spec/rspec-rails/redirect_to.rb +113 -0
- data/vendor/plugins/make_resourceful/spec/rspec-rails/render_template.rb +90 -0
- data/vendor/plugins/make_resourceful/spec/serialize_spec.rb +133 -0
- data/vendor/plugins/make_resourceful/spec/spec_helper.rb +319 -0
- data/vendor/plugins/make_resourceful/spec/urls_spec.rb +282 -0
- data/vendor/plugins/make_resourceful/spec/views/things/create.rjs +1 -0
- data/vendor/plugins/make_resourceful/spec/views/things/destroy.rjs +1 -0
- data/vendor/plugins/make_resourceful/spec/views/things/edit.html.erb +4 -0
- data/vendor/plugins/make_resourceful/spec/views/things/edit.rjs +1 -0
- data/vendor/plugins/make_resourceful/spec/views/things/index.html.erb +4 -0
- data/vendor/plugins/make_resourceful/spec/views/things/index.rjs +1 -0
- data/vendor/plugins/make_resourceful/spec/views/things/new.html.erb +4 -0
- data/vendor/plugins/make_resourceful/spec/views/things/new.rjs +1 -0
- data/vendor/plugins/make_resourceful/spec/views/things/show.html.erb +4 -0
- data/vendor/plugins/make_resourceful/spec/views/things/show.rjs +1 -0
- data/vendor/plugins/make_resourceful/spec/views/things/update.rjs +1 -0
- metadata +75 -16
- data/assets/css/easy_admin_ui.css +0 -69
@@ -0,0 +1,239 @@
|
|
1
|
+
= make_resourceful
|
2
|
+
===== Take back control of your Controllers. Make them awesome. Make them sleek. Make them resourceful.
|
3
|
+
|
4
|
+
REST is a fine pattern for designing controllers,
|
5
|
+
but it can be pretty repetitive.
|
6
|
+
Who wants to write out the same actions and copy the same model lookup logic
|
7
|
+
all over their application?
|
8
|
+
|
9
|
+
make_resourceful handles all that for you.
|
10
|
+
It sets up all your RESTful actions and responses with next to no code.
|
11
|
+
Everything has full, sensible default functionality.
|
12
|
+
|
13
|
+
Of course, no controller _only_ uses the defaults.
|
14
|
+
So make_resourceful can be massively customized,
|
15
|
+
while still keeping your controllers trim and readable.
|
16
|
+
|
17
|
+
== Get it!
|
18
|
+
|
19
|
+
Rails
|
20
|
+
|
21
|
+
$ ruby script/plugin install git://github.com/hcatlin/make_resourceful.git
|
22
|
+
|
23
|
+
Git
|
24
|
+
|
25
|
+
$ git clone git://github.com/hcatlin/make_resourceful.git
|
26
|
+
|
27
|
+
== Use it!
|
28
|
+
|
29
|
+
The easiest way to start with make_resourceful
|
30
|
+
is to run the resource_scaffold generator.
|
31
|
+
It uses the same syntax as the Rails scaffold_resource generator:
|
32
|
+
|
33
|
+
$ script/generate resource_scaffold post title:string body:text
|
34
|
+
|
35
|
+
It does, however, require {Haml}[http://haml-lang.com].
|
36
|
+
You _are_ using Haml, right? No?
|
37
|
+
I'll wait here while you go fall in love with it.
|
38
|
+
|
39
|
+
If you want to try make_resourceful on one of your current controllers,
|
40
|
+
just replace the mess of repetition with this:
|
41
|
+
|
42
|
+
class FooController < ApplicationController
|
43
|
+
make_resourceful do
|
44
|
+
actions :all
|
45
|
+
end
|
46
|
+
end
|
47
|
+
|
48
|
+
Those three lines will replace the entire default controller
|
49
|
+
that comes out of the scaffold_resource generator.
|
50
|
+
|
51
|
+
=== Really?
|
52
|
+
|
53
|
+
Yes.
|
54
|
+
|
55
|
+
=== Can I do nested resources?
|
56
|
+
|
57
|
+
make_resourceful do
|
58
|
+
actions :all
|
59
|
+
belongs_to :post
|
60
|
+
end
|
61
|
+
|
62
|
+
=== What if I want to use fancy permalinks?
|
63
|
+
|
64
|
+
def current_object
|
65
|
+
@current_object ||= current_model.find_by_permalink(params[:id])
|
66
|
+
end
|
67
|
+
|
68
|
+
=== What about paging?
|
69
|
+
|
70
|
+
def current_objects
|
71
|
+
@current_objects ||= current_model.find(:all,
|
72
|
+
:order => "created_at DESC", :page => {:current => params[:page], :size => 10 } )
|
73
|
+
end
|
74
|
+
|
75
|
+
=== What if I want to do something in the middle of an action?
|
76
|
+
|
77
|
+
before :show, :index do
|
78
|
+
@page_title = "Awesome!"
|
79
|
+
end
|
80
|
+
|
81
|
+
after :create_fails do
|
82
|
+
@page_title = "Not So Awesome!"
|
83
|
+
end
|
84
|
+
|
85
|
+
=== What about all of my awesome respond_to blocks for my XML APIs and RJS responses?
|
86
|
+
|
87
|
+
response_for :show do |format|
|
88
|
+
format.html
|
89
|
+
format.js
|
90
|
+
format.xml
|
91
|
+
end
|
92
|
+
|
93
|
+
response_for :update_fails do |format|
|
94
|
+
format.html { render :action => 'edit' }
|
95
|
+
format.json { render :json => false.to_json, :status => 422 }
|
96
|
+
end
|
97
|
+
|
98
|
+
=== So I guess I have to write responses for all my actions?
|
99
|
+
|
100
|
+
Nope! make_resourceful makes them do the right thing by default.
|
101
|
+
You only need to customize them if you want to do something special.
|
102
|
+
|
103
|
+
=== Seriously?!
|
104
|
+
|
105
|
+
Yes!
|
106
|
+
|
107
|
+
== Grok it!
|
108
|
+
|
109
|
+
=== +make_resourceful+ the Method
|
110
|
+
|
111
|
+
The +make_resourceful+ block is where most of the action happens.
|
112
|
+
Here you specify which actions you want to auto-generate,
|
113
|
+
what code you want to run for given callbacks,
|
114
|
+
and so forth.
|
115
|
+
|
116
|
+
You also use the block to declare various bits of information about your controller.
|
117
|
+
For instance, if the controller is nested, you'd call +belongs_to+.
|
118
|
+
If you wanted to expose your models as some sort of text format,
|
119
|
+
you'd call +publish+.
|
120
|
+
|
121
|
+
Check out the documentation of Resourceful::Builder
|
122
|
+
for more information on the methods you can call here.
|
123
|
+
|
124
|
+
=== Helper Methods
|
125
|
+
|
126
|
+
make_resourceful provides lots of useful methods
|
127
|
+
that can be used in your callbacks and in your views.
|
128
|
+
They range from accessing the records you're looking up
|
129
|
+
to easily generating URLs for a record
|
130
|
+
to getting information about the action itself.
|
131
|
+
|
132
|
+
Two of the most useful methods are +current_object+ and +current_objects+
|
133
|
+
(note the subtle plurality difference).
|
134
|
+
+current_objects+ only works for +index+,
|
135
|
+
and returns all the records in the current model.
|
136
|
+
+current_object+ works for all actions other than +index+,
|
137
|
+
and returns the record that's currently being dealt with.
|
138
|
+
|
139
|
+
The full documentation of the helper methods
|
140
|
+
is in Resourceful::Default::Accessors and Resourceful::Default::URLs.
|
141
|
+
|
142
|
+
=== Nested Resources
|
143
|
+
|
144
|
+
make_resourceful supports easy management of nested resources.
|
145
|
+
This is set up with the Resourceful::Builder#belongs_to declaration.
|
146
|
+
Pass in the name of the parent model,
|
147
|
+
|
148
|
+
belongs_to :user
|
149
|
+
|
150
|
+
and everything will be taken care of.
|
151
|
+
When +index+ is run for GET /users/12/albums,
|
152
|
+
parent_object
|
153
|
+
will get <tt>User.find(params[:user_id])</tt>,
|
154
|
+
and current_objects
|
155
|
+
will get <tt>parent_object.albums</tt>.
|
156
|
+
When +create+ is run for POST /users/12/albums,
|
157
|
+
the newly created Album will automatically belong to the user
|
158
|
+
with id 12.
|
159
|
+
|
160
|
+
The normal non-scoped actions still work, too.
|
161
|
+
GET /albums/15 runs just fine.
|
162
|
+
make_resourceful knows that since there's no <tt>params[:user_id]</tt>,
|
163
|
+
you just want to deal with the album.
|
164
|
+
|
165
|
+
You can even have a single resource nested under several different resources.
|
166
|
+
Just pass multiple parent names to the Resourceful::Builder#belongs_to, like
|
167
|
+
|
168
|
+
belongs_to :user, :artist
|
169
|
+
|
170
|
+
Then /users/15/albums and /artists/7/albums will both work.
|
171
|
+
|
172
|
+
This does, however, mean that make_resourceful only supports one level of nesting.
|
173
|
+
There's no automatic handling of /users/15/collections/437/albums.
|
174
|
+
However, this is really the best way to organize most resources anyway;
|
175
|
+
see this {article}[http://weblog.jamisbuck.org/2007/2/5/nesting-resources].
|
176
|
+
|
177
|
+
If you really need a deeply nested controller,
|
178
|
+
it should be easy enough to set up on your own.
|
179
|
+
Just override current_model.
|
180
|
+
See the next section for more details.
|
181
|
+
|
182
|
+
=== Overriding Methods
|
183
|
+
|
184
|
+
Not only are helper methods useful to the developer to use,
|
185
|
+
they're used internally by the actions created by make_resourceful.
|
186
|
+
Thus one of the main ways make_resourceful can be customized
|
187
|
+
is by overriding accessors.
|
188
|
+
|
189
|
+
For instance, if you want to only look up the 10 most recent records for +index+,
|
190
|
+
you're override +current_objects+.
|
191
|
+
If you wanted to use a different model than that suggested by the name of the controller,
|
192
|
+
you'd override +current_model+.
|
193
|
+
|
194
|
+
When you're overriding methods that do SQL lookups, though, be a little cautious.
|
195
|
+
By default, these methods cache their values in instance variables
|
196
|
+
so that multiple SQL queries aren't run on multiple calls.
|
197
|
+
When overriding them, it's wise for you to do the same.
|
198
|
+
For instance,
|
199
|
+
|
200
|
+
def current_object
|
201
|
+
@current_object ||= current_model.find_by_name(params[:name])
|
202
|
+
end
|
203
|
+
|
204
|
+
=== For More Information...
|
205
|
+
|
206
|
+
Haven't found all the information you need in the RDoc?
|
207
|
+
Still a little confused about something?
|
208
|
+
Don't despair, there are still more resources available!
|
209
|
+
|
210
|
+
* Read the source code!
|
211
|
+
It's very straightforward,
|
212
|
+
and make_resourceful is built to encourage overriding methods
|
213
|
+
and hacking the source.
|
214
|
+
* Nathan Weizenbaum has some good blog posts about make_resourceful.
|
215
|
+
They may be a little outdated, but they should still be useful and explanatory.
|
216
|
+
* On nesting and associations: {here}[http://nex-3.com/posts/55-nesting-and-make_resourceful].
|
217
|
+
* An overview of make_resourceful 0.2.0 and 0.2.2: {here}[http://localhost:3000/posts/54-make_resourceful-0-2-0].
|
218
|
+
* On Resourceful::Builder#publish
|
219
|
+
and Resourceful::Serialize:
|
220
|
+
{here}[http://nex-3.com/posts/35-make_resourceful-the-basics-of-publish] and
|
221
|
+
{here}[http://nex-3.com/posts/36-make_resourceful-publish-extras].
|
222
|
+
* There's an excellent, active Google Group http://groups.google.com/group/make_resourceful
|
223
|
+
where people will be happy to answer your questions.
|
224
|
+
|
225
|
+
---
|
226
|
+
|
227
|
+
Copyright 2007-2010 Hampton Catlin and Nathan Weizenbaum.
|
228
|
+
Contributions by:
|
229
|
+
|
230
|
+
* Russell Norris
|
231
|
+
* Jonathan Linowes
|
232
|
+
* Cristi Balan
|
233
|
+
* Mike Ferrier
|
234
|
+
* James Golick
|
235
|
+
* Don Petersen
|
236
|
+
* Alex Ross
|
237
|
+
* Tom Stuart
|
238
|
+
* Glenn Powell
|
239
|
+
* Johannes Jörg Schmidt
|
@@ -0,0 +1,31 @@
|
|
1
|
+
require 'rake'
|
2
|
+
require 'rake/rdoctask'
|
3
|
+
require 'spec/rake/spectask'
|
4
|
+
|
5
|
+
desc 'Default: run specs.'
|
6
|
+
task :default => :spec
|
7
|
+
|
8
|
+
spec_files = Rake::FileList["spec/**/*_spec.rb"]
|
9
|
+
|
10
|
+
desc "Run specs"
|
11
|
+
Spec::Rake::SpecTask.new do |t|
|
12
|
+
t.spec_files = spec_files
|
13
|
+
t.spec_opts = ["-c"]
|
14
|
+
end
|
15
|
+
|
16
|
+
desc "Generate code coverage"
|
17
|
+
Spec::Rake::SpecTask.new(:coverage) do |t|
|
18
|
+
t.spec_files = spec_files
|
19
|
+
t.rcov = true
|
20
|
+
t.rcov_opts = ['--exclude', 'spec,/var/lib/gems']
|
21
|
+
end
|
22
|
+
|
23
|
+
desc 'Generate documentation for the make_resourceful plugin.'
|
24
|
+
Rake::RDocTask.new(:rdoc) do |rdoc|
|
25
|
+
rdoc.rdoc_dir = 'rdoc'
|
26
|
+
rdoc.title = 'make_resourceful'
|
27
|
+
rdoc.options << '--line-numbers' << '--inline-source'
|
28
|
+
rdoc.main = 'README'
|
29
|
+
rdoc.rdoc_files.include(FileList.new('*').exclude(/[^A-Z0-9]/))
|
30
|
+
rdoc.rdoc_files.include('lib/**/*.rb')
|
31
|
+
end
|
@@ -0,0 +1 @@
|
|
1
|
+
0.9.9
|
@@ -0,0 +1,87 @@
|
|
1
|
+
class ResourcefulScaffoldGenerator < Rails::Generator::NamedBase
|
2
|
+
attr_reader :controller_class_path,
|
3
|
+
:controller_file_path,
|
4
|
+
:controller_class_nesting,
|
5
|
+
:controller_class_nesting_depth,
|
6
|
+
:controller_class_name,
|
7
|
+
:controller_underscore_name,
|
8
|
+
:controller_plural_name
|
9
|
+
alias_method :controller_file_name, :controller_underscore_name
|
10
|
+
alias_method :controller_table_name, :controller_plural_name
|
11
|
+
|
12
|
+
def initialize(runtime_args, runtime_options = {})
|
13
|
+
super
|
14
|
+
|
15
|
+
base_name, @controller_class_path, @controller_file_path, @controller_class_nesting, @controller_class_nesting_depth = extract_modules(@name.pluralize)
|
16
|
+
@controller_class_name_without_nesting, @controller_underscore_name, @controller_plural_name = inflect_names(base_name)
|
17
|
+
|
18
|
+
if @controller_class_nesting.empty?
|
19
|
+
@controller_class_name = @controller_class_name_without_nesting
|
20
|
+
else
|
21
|
+
@controller_class_name = "#{@controller_class_nesting}::#{@controller_class_name_without_nesting}"
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
def manifest
|
26
|
+
record do |m|
|
27
|
+
# Check for class naming collisions.
|
28
|
+
m.class_collisions(controller_class_path, "#{controller_class_name}Controller", "#{controller_class_name}Helper")
|
29
|
+
m.class_collisions(class_path, "#{class_name}")
|
30
|
+
|
31
|
+
# Controller, helper, views, and test directories.
|
32
|
+
m.directory(File.join('app/models', class_path))
|
33
|
+
m.directory(File.join('app/controllers', controller_class_path))
|
34
|
+
m.directory(File.join('app/helpers', controller_class_path))
|
35
|
+
m.directory(File.join('app/views', controller_class_path, controller_file_name))
|
36
|
+
m.directory(File.join('test/functional', controller_class_path))
|
37
|
+
m.directory(File.join('test/unit', class_path))
|
38
|
+
m.directory(File.join('test/fixtures', class_path))
|
39
|
+
|
40
|
+
# Views
|
41
|
+
for action in scaffold_views
|
42
|
+
m.template("view_#{action}.haml", File.join('app/views', controller_class_path, controller_file_name, "#{action}.html.haml"))
|
43
|
+
end
|
44
|
+
m.template('view_partial.haml', File.join('app/views', controller_class_path, controller_file_name, "_#{singular_name}.html.haml"))
|
45
|
+
|
46
|
+
# Helper
|
47
|
+
m.template('helper.rb', File.join('app/helpers', controller_class_path, "#{controller_file_name}_helper.rb"))
|
48
|
+
|
49
|
+
# Model
|
50
|
+
m.template('model.rb', File.join('app/models', class_path, "#{file_name}.rb"))
|
51
|
+
|
52
|
+
unless options[:skip_migration]
|
53
|
+
m.migration_template('migration.rb', 'db/migrate',
|
54
|
+
:assigns => {
|
55
|
+
:migration_name => "Create#{class_name.pluralize.gsub(/::/, '')}",
|
56
|
+
:attributes => attributes
|
57
|
+
},
|
58
|
+
:migration_file_name => "create_#{file_path.gsub(/\//, '_').pluralize}")
|
59
|
+
end
|
60
|
+
|
61
|
+
# Controller
|
62
|
+
m.template('controller.rb', File.join('app/controllers', controller_class_path, "#{controller_file_name}_controller.rb"))
|
63
|
+
|
64
|
+
# Tests
|
65
|
+
m.template('functional_test.rb', File.join('test/functional', controller_class_path, "#{controller_file_name}_controller_test.rb"))
|
66
|
+
m.template('unit_test.rb', File.join('test/unit', class_path, "#{file_name}_test.rb"))
|
67
|
+
m.template('fixtures.yml', File.join('test/fixtures', "#{table_name}.yml"))
|
68
|
+
|
69
|
+
# Route
|
70
|
+
m.route_resources controller_file_name
|
71
|
+
end
|
72
|
+
end
|
73
|
+
|
74
|
+
protected
|
75
|
+
|
76
|
+
def banner
|
77
|
+
"Usage: #{$0} resourcefulscaffold ModelName [field:type, field:type]"
|
78
|
+
end
|
79
|
+
|
80
|
+
def scaffold_views
|
81
|
+
%w[ index show new edit _form ]
|
82
|
+
end
|
83
|
+
|
84
|
+
def model_name
|
85
|
+
class_name.demodulize
|
86
|
+
end
|
87
|
+
end
|
data/vendor/plugins/make_resourceful/generators/resourceful_scaffold/templates/functional_test.rb
ADDED
@@ -0,0 +1,50 @@
|
|
1
|
+
require File.dirname(__FILE__) + '<%= '/..' * controller_class_nesting_depth %>/../test_helper'
|
2
|
+
require '<%= controller_file_path %>_controller'
|
3
|
+
|
4
|
+
# Re-raise errors caught by the controller.
|
5
|
+
class <%= controller_class_name %>Controller; def rescue_action(e) raise e end; end
|
6
|
+
|
7
|
+
class <%= controller_class_name %>ControllerTest < ActionController::TestCase
|
8
|
+
|
9
|
+
def test_should_get_index
|
10
|
+
get :index
|
11
|
+
assert_response :success
|
12
|
+
assert assigns(:<%= table_name %>)
|
13
|
+
end
|
14
|
+
|
15
|
+
def test_should_get_new
|
16
|
+
get :new
|
17
|
+
assert_response :success
|
18
|
+
end
|
19
|
+
|
20
|
+
def test_should_create_<%= file_name %>
|
21
|
+
old_count = <%= class_name %>.count
|
22
|
+
post :create, :<%= file_name %> => { }
|
23
|
+
assert_equal old_count + 1, <%= class_name %>.count
|
24
|
+
|
25
|
+
assert_redirected_to <%= file_name %>_path(assigns(:<%= file_name %>))
|
26
|
+
end
|
27
|
+
|
28
|
+
def test_should_show_<%= file_name %>
|
29
|
+
get :show, :id => 1
|
30
|
+
assert_response :success
|
31
|
+
end
|
32
|
+
|
33
|
+
def test_should_get_edit
|
34
|
+
get :edit, :id => 1
|
35
|
+
assert_response :success
|
36
|
+
end
|
37
|
+
|
38
|
+
def test_should_update_<%= file_name %>
|
39
|
+
put :update, :id => 1, :<%= file_name %> => { }
|
40
|
+
assert_redirected_to <%= file_name %>_path(assigns(:<%= file_name %>))
|
41
|
+
end
|
42
|
+
|
43
|
+
def test_should_destroy_<%= file_name %>
|
44
|
+
old_count = <%= class_name %>.count
|
45
|
+
delete :destroy, :id => 1
|
46
|
+
assert_equal old_count-1, <%= class_name %>.count
|
47
|
+
|
48
|
+
assert_redirected_to <%= table_name %>_path
|
49
|
+
end
|
50
|
+
end
|
@@ -0,0 +1,13 @@
|
|
1
|
+
class <%= migration_name %> < ActiveRecord::Migration
|
2
|
+
def self.up
|
3
|
+
create_table :<%= table_name %>, :force => true do |t|
|
4
|
+
<% for attribute in attributes -%>
|
5
|
+
t.column :<%= attribute.name %>, :<%= attribute.type %>
|
6
|
+
<% end -%>
|
7
|
+
end
|
8
|
+
end
|
9
|
+
|
10
|
+
def self.down
|
11
|
+
drop_table :<%= table_name %>
|
12
|
+
end
|
13
|
+
end
|
@@ -0,0 +1,11 @@
|
|
1
|
+
%h1 Editing <%= singular_name %>
|
2
|
+
|
3
|
+
= error_messages_for :<%= singular_name %>
|
4
|
+
|
5
|
+
- form_for(:<%= singular_name %>, :url => object_url, :html => { :method => :put }) do |f|
|
6
|
+
= render :partial => "form", :locals => {:f => f}
|
7
|
+
%p= submit_tag "Update"
|
8
|
+
|
9
|
+
= link_to 'Show', object_path
|
10
|
+
|
|
11
|
+
= link_to 'Back', objects_path
|
data/vendor/plugins/make_resourceful/generators/resourceful_scaffold/templates/view_partial.haml
ADDED
@@ -0,0 +1,12 @@
|
|
1
|
+
%div[<%= singular_name %>]
|
2
|
+
<% for attribute in attributes -%>
|
3
|
+
%p.<%= attribute.name %>
|
4
|
+
%strong <%= attribute.column.human_name %>
|
5
|
+
= h <%= singular_name %>.<%= attribute.name %>
|
6
|
+
<% end -%>
|
7
|
+
|
8
|
+
= link_to 'Show', object_path(<%= singular_name %>)
|
9
|
+
|
|
10
|
+
= link_to 'Edit', edit_object_path(<%= singular_name %>)
|
11
|
+
|
|
12
|
+
= link_to 'Destroy', object_path(<%= singular_name %>), :confirm => 'Really destroy <%= singular_name %>?', :method => :delete
|
@@ -0,0 +1,14 @@
|
|
1
|
+
%h1 Viewing <%= singular_name %>
|
2
|
+
|
3
|
+
%div[current_object]
|
4
|
+
<% for attribute in attributes -%>
|
5
|
+
%p.<%= attribute.name %>
|
6
|
+
%strong <%= attribute.column.human_name %>
|
7
|
+
= h current_object.<%= attribute.name %>
|
8
|
+
<% end -%>
|
9
|
+
|
10
|
+
= link_to 'Edit', edit_object_path
|
11
|
+
|
|
12
|
+
= link_to 'Destroy', object_path, :confirm => 'Really destroy <%= singular_name %>?', :method => :delete
|
13
|
+
|
|
14
|
+
= link_to 'Back', objects_path
|
@@ -0,0 +1,63 @@
|
|
1
|
+
# The module containing all the code for make_resourceful.
|
2
|
+
#
|
3
|
+
# For methods available in the +make_resourceful+ block,
|
4
|
+
# see Resourceful::Builder.
|
5
|
+
#
|
6
|
+
# For helper methods and methods you can override
|
7
|
+
# to customize the behavior of your actions,
|
8
|
+
# see Resourceful::Default::Accessors
|
9
|
+
# and Resourceful::Default::URLs.
|
10
|
+
module Resourceful
|
11
|
+
# We want to define some stuff before we load other modules
|
12
|
+
|
13
|
+
# The default actions generated by make_resourceful.
|
14
|
+
ACTIONS = [:index, :show, :edit, :update, :create, :new, :destroy]
|
15
|
+
|
16
|
+
# The actions that modify the database.
|
17
|
+
MODIFYING_ACTIONS = [:update, :create, :destroy]
|
18
|
+
|
19
|
+
# The actions that act on multiple records.
|
20
|
+
PLURAL_ACTIONS = [:index]
|
21
|
+
|
22
|
+
# The actions that act on just one record.
|
23
|
+
SINGULAR_ACTIONS = ACTIONS - PLURAL_ACTIONS
|
24
|
+
|
25
|
+
# The actions that act on just one record.
|
26
|
+
SINGULAR_PRELOADED_ACTIONS = SINGULAR_ACTIONS - [:new, :create]
|
27
|
+
end
|
28
|
+
|
29
|
+
require 'resourceful/default/accessors'
|
30
|
+
require 'resourceful/default/responses'
|
31
|
+
require 'resourceful/default/callbacks'
|
32
|
+
require 'resourceful/default/urls'
|
33
|
+
|
34
|
+
# All modules included by this module
|
35
|
+
# are made available to the controller as accessors.
|
36
|
+
module Resourceful::Base
|
37
|
+
@@made_resourceful_callbacks = []
|
38
|
+
|
39
|
+
# This method is meant to be called by included classes.
|
40
|
+
# It takes a block of the same form as that given to Maker#make_resourceful.
|
41
|
+
# The Maker will then run that block
|
42
|
+
# along with the blocks given by the individual controllers.
|
43
|
+
def self.made_resourceful(&block)
|
44
|
+
if block
|
45
|
+
@@made_resourceful_callbacks << block
|
46
|
+
else
|
47
|
+
@@made_resourceful_callbacks
|
48
|
+
end
|
49
|
+
end
|
50
|
+
|
51
|
+
include Resourceful::Default::Accessors
|
52
|
+
include Resourceful::Default::Responses
|
53
|
+
include Resourceful::Default::Callbacks
|
54
|
+
include Resourceful::Default::URLs
|
55
|
+
|
56
|
+
# FIXME HACK
|
57
|
+
# making methods assigned to controller private
|
58
|
+
# prevents access from dispatcher.
|
59
|
+
private *Resourceful::Default::Accessors.public_instance_methods
|
60
|
+
private *Resourceful::Default::Responses.public_instance_methods
|
61
|
+
private *Resourceful::Default::Callbacks.public_instance_methods
|
62
|
+
private *Resourceful::Default::URLs.public_instance_methods
|
63
|
+
end
|