easy_admin_ui 0.4.0 → 0.5.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (80) hide show
  1. data/README +4 -15
  2. data/Rakefile +1 -1
  3. data/VERSION +1 -1
  4. data/{assets/icons → app/assets/images/easy_admin_ui}/classify.png +0 -0
  5. data/{assets/icons → app/assets/images/easy_admin_ui}/connect.png +0 -0
  6. data/{assets/icons → app/assets/images/easy_admin_ui}/delete.png +0 -0
  7. data/{assets/icons → app/assets/images/easy_admin_ui}/disconnect.png +0 -0
  8. data/{assets/icons → app/assets/images/easy_admin_ui}/pencil.png +0 -0
  9. data/{assets/icons → app/assets/images/easy_admin_ui}/show.png +0 -0
  10. data/app/assets/stylesheets/easy_admin_ui/easy_admin_ui.sass +47 -0
  11. data/app/views/easy_admin_ui/destroy.js.erb +1 -0
  12. data/{templates → app/views}/easy_admin_ui/edit.html.erb +0 -0
  13. data/{templates → app/views}/easy_admin_ui/index.html.erb +0 -0
  14. data/{templates → app/views}/easy_admin_ui/new.html.erb +0 -0
  15. data/{templates → app/views}/easy_admin_ui/show.html.erb +0 -0
  16. data/easy_admin_ui.gemspec +80 -21
  17. data/lib/easy_admin_ui/core_ext.rb +1 -3
  18. data/lib/easy_admin_ui/rails/engine.rb +10 -0
  19. data/lib/easy_admin_ui/tasks.rb +0 -10
  20. data/lib/easy_admin_ui/view_helpers.rb +3 -3
  21. data/lib/easy_admin_ui.rb +1 -9
  22. data/vendor/plugins/make_resourceful/.gitignore +1 -0
  23. data/vendor/plugins/make_resourceful/DEFAULTS +148 -0
  24. data/vendor/plugins/make_resourceful/LICENSE +7 -0
  25. data/vendor/plugins/make_resourceful/README.rdoc +239 -0
  26. data/vendor/plugins/make_resourceful/Rakefile +31 -0
  27. data/vendor/plugins/make_resourceful/VERSION +1 -0
  28. data/vendor/plugins/make_resourceful/generators/resourceful_scaffold/resourceful_scaffold_generator.rb +87 -0
  29. data/vendor/plugins/make_resourceful/generators/resourceful_scaffold/templates/controller.rb +5 -0
  30. data/vendor/plugins/make_resourceful/generators/resourceful_scaffold/templates/fixtures.yml +10 -0
  31. data/vendor/plugins/make_resourceful/generators/resourceful_scaffold/templates/functional_test.rb +50 -0
  32. data/vendor/plugins/make_resourceful/generators/resourceful_scaffold/templates/helper.rb +2 -0
  33. data/vendor/plugins/make_resourceful/generators/resourceful_scaffold/templates/migration.rb +13 -0
  34. data/vendor/plugins/make_resourceful/generators/resourceful_scaffold/templates/model.rb +2 -0
  35. data/vendor/plugins/make_resourceful/generators/resourceful_scaffold/templates/unit_test.rb +7 -0
  36. data/vendor/plugins/make_resourceful/generators/resourceful_scaffold/templates/view__form.haml +5 -0
  37. data/vendor/plugins/make_resourceful/generators/resourceful_scaffold/templates/view_edit.haml +11 -0
  38. data/vendor/plugins/make_resourceful/generators/resourceful_scaffold/templates/view_index.haml +5 -0
  39. data/vendor/plugins/make_resourceful/generators/resourceful_scaffold/templates/view_new.haml +9 -0
  40. data/vendor/plugins/make_resourceful/generators/resourceful_scaffold/templates/view_partial.haml +12 -0
  41. data/vendor/plugins/make_resourceful/generators/resourceful_scaffold/templates/view_show.haml +14 -0
  42. data/vendor/plugins/make_resourceful/init.rb +3 -0
  43. data/vendor/plugins/make_resourceful/lib/resourceful/base.rb +63 -0
  44. data/vendor/plugins/make_resourceful/lib/resourceful/builder.rb +385 -0
  45. data/vendor/plugins/make_resourceful/lib/resourceful/default/accessors.rb +402 -0
  46. data/vendor/plugins/make_resourceful/lib/resourceful/default/actions.rb +101 -0
  47. data/vendor/plugins/make_resourceful/lib/resourceful/default/callbacks.rb +51 -0
  48. data/vendor/plugins/make_resourceful/lib/resourceful/default/responses.rb +118 -0
  49. data/vendor/plugins/make_resourceful/lib/resourceful/default/urls.rb +137 -0
  50. data/vendor/plugins/make_resourceful/lib/resourceful/maker.rb +84 -0
  51. data/vendor/plugins/make_resourceful/lib/resourceful/response.rb +33 -0
  52. data/vendor/plugins/make_resourceful/lib/resourceful/serialize.rb +185 -0
  53. data/vendor/plugins/make_resourceful/spec/accessors_spec.rb +474 -0
  54. data/vendor/plugins/make_resourceful/spec/actions_spec.rb +310 -0
  55. data/vendor/plugins/make_resourceful/spec/base_spec.rb +12 -0
  56. data/vendor/plugins/make_resourceful/spec/builder_spec.rb +332 -0
  57. data/vendor/plugins/make_resourceful/spec/callbacks_spec.rb +71 -0
  58. data/vendor/plugins/make_resourceful/spec/integration_spec.rb +394 -0
  59. data/vendor/plugins/make_resourceful/spec/maker_spec.rb +91 -0
  60. data/vendor/plugins/make_resourceful/spec/response_spec.rb +37 -0
  61. data/vendor/plugins/make_resourceful/spec/responses_spec.rb +314 -0
  62. data/vendor/plugins/make_resourceful/spec/rspec-rails/LICENSE +37 -0
  63. data/vendor/plugins/make_resourceful/spec/rspec-rails/redirect_to.rb +113 -0
  64. data/vendor/plugins/make_resourceful/spec/rspec-rails/render_template.rb +90 -0
  65. data/vendor/plugins/make_resourceful/spec/serialize_spec.rb +133 -0
  66. data/vendor/plugins/make_resourceful/spec/spec_helper.rb +319 -0
  67. data/vendor/plugins/make_resourceful/spec/urls_spec.rb +282 -0
  68. data/vendor/plugins/make_resourceful/spec/views/things/create.rjs +1 -0
  69. data/vendor/plugins/make_resourceful/spec/views/things/destroy.rjs +1 -0
  70. data/vendor/plugins/make_resourceful/spec/views/things/edit.html.erb +4 -0
  71. data/vendor/plugins/make_resourceful/spec/views/things/edit.rjs +1 -0
  72. data/vendor/plugins/make_resourceful/spec/views/things/index.html.erb +4 -0
  73. data/vendor/plugins/make_resourceful/spec/views/things/index.rjs +1 -0
  74. data/vendor/plugins/make_resourceful/spec/views/things/new.html.erb +4 -0
  75. data/vendor/plugins/make_resourceful/spec/views/things/new.rjs +1 -0
  76. data/vendor/plugins/make_resourceful/spec/views/things/show.html.erb +4 -0
  77. data/vendor/plugins/make_resourceful/spec/views/things/show.rjs +1 -0
  78. data/vendor/plugins/make_resourceful/spec/views/things/update.rjs +1 -0
  79. metadata +75 -16
  80. data/assets/css/easy_admin_ui.css +0 -69
@@ -0,0 +1,385 @@
1
+ require 'resourceful/response'
2
+ require 'resourceful/serialize'
3
+ require 'resourceful/default/actions'
4
+
5
+ module Resourceful
6
+ # The Maker#make_resourceful block is evaluated in the context
7
+ # of an instance of this class.
8
+ # It provides various methods for customizing the behavior of the actions
9
+ # built by make_resourceful.
10
+ #
11
+ # All instance methods of this class are available in the +make_resourceful+ block.
12
+ class Builder
13
+ # The klass of the controller on which the builder is working.
14
+ attr :controller, true
15
+
16
+ # The constructor is only meant to be called internally.
17
+ #
18
+ # This takes the klass (class object) of a controller
19
+ # and constructs a Builder ready to apply the make_resourceful
20
+ # additions to the controller.
21
+ def initialize(kontroller)
22
+ @controller = kontroller
23
+ @inherited = !kontroller.read_inheritable_attribute(:resourceful_responses).blank?
24
+ @action_module = Resourceful::Default::Actions.dup
25
+ @ok_actions = []
26
+ @callbacks = {:before => {}, :after => {}}
27
+ @responses = {}
28
+ @publish = {}
29
+ @parents = []
30
+ @custom_member_actions = []
31
+ @custom_collection_actions = []
32
+ end
33
+
34
+ # This method is only meant to be called internally.
35
+ #
36
+ # Applies all the changes that have been declared
37
+ # via the instance methods of this Builder
38
+ # to the kontroller passed in to the constructor.
39
+ def apply
40
+ apply_publish
41
+
42
+ kontroller = @controller
43
+ Resourceful::ACTIONS.each do |action_named|
44
+ # See if this is a method listed by #actions
45
+ unless @ok_actions.include? action_named
46
+ # If its not listed, then remove the method
47
+ # No one can hit it... if its DEAD!
48
+ @action_module.send :remove_method, action_named
49
+ end
50
+ end
51
+
52
+ kontroller.hidden_actions.reject! &@ok_actions.method(:include?)
53
+ kontroller.send :include, @action_module
54
+
55
+ kontroller.read_inheritable_attribute(:resourceful_callbacks).merge! @callbacks
56
+ kontroller.read_inheritable_attribute(:resourceful_responses).merge! @responses
57
+ kontroller.write_inheritable_attribute(:made_resourceful, true)
58
+
59
+ kontroller.write_inheritable_attribute(:parents, @parents)
60
+ kontroller.before_filter :load_object, :only => (@ok_actions & SINGULAR_PRELOADED_ACTIONS) + @custom_member_actions
61
+ kontroller.before_filter :load_objects, :only => (@ok_actions & PLURAL_ACTIONS) + @custom_collection_actions
62
+ kontroller.before_filter :load_parent_object, :only => @ok_actions + @custom_member_actions + @custom_collection_actions
63
+ end
64
+
65
+ # :call-seq:
66
+ # actions(*available_actions)
67
+ # actions :all
68
+ #
69
+ # Adds the default RESTful actions to the controller.
70
+ #
71
+ # If the only argument is <tt>:all</tt>,
72
+ # adds all the actions listed in Resourceful::ACTIONS[link:classes/Resourceful.html]
73
+ # (or Resourceful::SINGULAR_ACTIONS[link:classes/Resourceful.html]
74
+ # for a singular controller).
75
+ #
76
+ # Otherwise, this adds all actions
77
+ # whose names were passed as arguments.
78
+ #
79
+ # For example:
80
+ #
81
+ # actions :show, :new, :create
82
+ #
83
+ # This adds the +show+, +new+, and +create+ actions
84
+ # to the controller.
85
+ #
86
+ # The available actions are defined in Default::Actions.
87
+ def actions(*available_actions)
88
+ # FIXME HACK
89
+ # made all methods private, so plural?, too.
90
+ # Did not want to make an exception for that and i do not like it to
91
+ # come up on actions_methods.
92
+ # TODO: maybe we can define plural? as class_method
93
+ if available_actions.first == :all
94
+ if controller.respond_to?(:new_without_capture)
95
+ available_actions = controller.new_without_capture.send(:plural?) ? ACTIONS : SINGULAR_ACTIONS
96
+ else
97
+ available_actions = controller.new.send(:plural?) ? ACTIONS : SINGULAR_ACTIONS
98
+ end
99
+ end
100
+
101
+ available_actions.each { |action| @ok_actions << action.to_sym }
102
+ end
103
+ alias build actions
104
+
105
+ # :call-seq:
106
+ # member_actions(*available_actions)
107
+ #
108
+ # Registers custom member actions which will use the load_object before_filter.
109
+ # These actions are not created, but merely registered for filtering.
110
+ def member_actions(*available_actions)
111
+ available_actions.each { |action| @custom_member_actions << action.to_sym }
112
+ end
113
+
114
+ # :call-seq:
115
+ # collection_actions(*available_actions)
116
+ #
117
+ # Registers custom collection actions which will use the load_objects before_filter.
118
+ # These actions are not created, but merely registered for filtering.
119
+ def collection_actions(*available_actions)
120
+ available_actions.each { |action| @custom_collection_actions << action.to_sym }
121
+ end
122
+
123
+ # :call-seq:
124
+ # before(*events) { ... }
125
+ #
126
+ # Sets up a block of code to run before one or more events.
127
+ #
128
+ # All the default actions can be used as +before+ events:
129
+ # <tt>:index</tt>, <tt>:show</tt>, <tt>:create</tt>, <tt>:update</tt>, <tt>:new</tt>, <tt>:edit</tt>, and <tt>:destroy</tt>.
130
+ #
131
+ # +before+ events are run after any objects are loaded[link:classes/Resourceful/Default/Accessors.html#M000015],
132
+ # but before any database operations or responses.
133
+ #
134
+ # For example:
135
+ #
136
+ # before :show, :edit do
137
+ # @page_title = current_object.title
138
+ # end
139
+ #
140
+ # This will set the <tt>@page_title</tt> variable
141
+ # to the current object's title
142
+ # for the show and edit actions.
143
+ #
144
+ # Successive before blocks for the same action will be chained and executed
145
+ # in order when the event occurs.
146
+ #
147
+ # For example:
148
+ #
149
+ # before :show, :edit do
150
+ # @page_title = current_object.title
151
+ # end
152
+ #
153
+ # before :show do
154
+ # @side_bar = true
155
+ # end
156
+ #
157
+ # These before blocks will both be executed for the show action and in the
158
+ # same order as they were defined.
159
+ def before(*events, &block)
160
+ add_callback :before, *events, &block
161
+ end
162
+
163
+ # :call-seq:
164
+ # after(*events) { ... }
165
+ #
166
+ # Sets up a block of code to run after one or more events.
167
+ #
168
+ # There are two sorts of +after+ events.
169
+ # <tt>:create</tt>, <tt>:update</tt>, and <tt>:destroy</tt>
170
+ # are run after their respective database operations
171
+ # have been completed successfully.
172
+ # <tt>:create_fails</tt>, <tt>:update_fails</tt>, and <tt>:destroy_fails</tt>,
173
+ # on the other hand,
174
+ # are run after the database operations fail.
175
+ #
176
+ # +after+ events are run after the database operations
177
+ # but before any responses.
178
+ #
179
+ # For example:
180
+ #
181
+ # after :create_fails, :update_fails do
182
+ # current_object.password = nil
183
+ # end
184
+ #
185
+ # This will nillify the password of the current object
186
+ # if the object creation/modification failed.
187
+ def after(*events, &block)
188
+ add_callback :after, *events, &block
189
+ end
190
+
191
+ # :call-seq:
192
+ # response_for(*actions) { ... }
193
+ # response_for(*actions) { |format| ... }
194
+ #
195
+ # Sets up a block of code to run
196
+ # instead of the default responses for one or more events.
197
+ #
198
+ # If the block takes a format parameter,
199
+ # it has the same semantics as Rails' +respond_to+ method.
200
+ # Various format methods are called on the format object
201
+ # with blocks that say what to do for each format.
202
+ # For example:
203
+ #
204
+ # response_for :index do |format|
205
+ # format.html
206
+ # format.atom do
207
+ # headers['Content-Type'] = 'application/atom+xml; charset=utf-8'
208
+ # render :action => 'atom', :layout => false
209
+ # end
210
+ # end
211
+ #
212
+ # This doesn't do anything special for the HTML
213
+ # other than ensure that the proper view will be rendered,
214
+ # but for ATOM it sets the proper content type
215
+ # and renders the atom template.
216
+ #
217
+ # If you only need to set the HTML response,
218
+ # you can omit the format parameter.
219
+ # For example:
220
+ #
221
+ # response_for :new do
222
+ # render :action => 'edit'
223
+ # end
224
+ #
225
+ # This is the same as
226
+ #
227
+ # response_for :new do |format|
228
+ # format.html { render :action => 'edit' }
229
+ # end
230
+ #
231
+ # The default responses are defined by
232
+ # Default::Responses.included[link:classes/Resourceful/Default/Responses.html#M000011].
233
+ def response_for(*actions, &block)
234
+ raise "Must specify one or more actions for response_for." if actions.empty?
235
+
236
+ if block.arity < 1
237
+ response_for(*actions) do |format|
238
+ format.html(&block)
239
+ end
240
+ else
241
+ response = Response.new
242
+ block.call response
243
+
244
+ actions.each do |action|
245
+ @responses[action.to_sym] = response.formats
246
+ end
247
+ end
248
+ end
249
+
250
+ # :call-seq:
251
+ # publish *formats, options = {}, :attributes => [ ... ]
252
+ #
253
+ # publish allows you to easily expose information about resourcess in a variety of formats.
254
+ # The +formats+ parameter is a list of formats
255
+ # in which to publish the resources.
256
+ # The formats supported by default are +xml+, +yaml+, and +json+,
257
+ # but other formats may be added by defining +to_format+ methods
258
+ # for the Array and Hash classes
259
+ # and registering the mime type with Rails' Mime::Type.register[http://api.rubyonrails.org/classes/Mime/Type.html#M001115].
260
+ # See Resourceful::Serialize for more details..
261
+ #
262
+ # The <tt>:attributes</tt> option is mandatory.
263
+ # It takes an array of attributes (as symbols) to make public.
264
+ # These attributes can refer to any method on current_object;
265
+ # they aren't limited to database fields.
266
+ # For example:
267
+ #
268
+ # # posts_controller.rb
269
+ # publish :yaml, :attributes => [:title, :created_at, :rendered_content]
270
+ #
271
+ # Then GET /posts/12.yaml would render
272
+ #
273
+ # ---
274
+ # post:
275
+ # title: Cool Stuff
276
+ # rendered_content: |-
277
+ # <p>This is a post.</p>
278
+ # <p>It's about <strong>really</strong> cool stuff.</p>
279
+ # created_at: 2007-04-28 04:32:08 -07:00
280
+ #
281
+ # The <tt>:attributes</tt> array can even contain attributes
282
+ # that are themselves models.
283
+ # In this case, you must use a hash to specify their attributes as well.
284
+ # For example:
285
+ #
286
+ # # person_controller.rb
287
+ # publish :xml, :json, :attributes => [
288
+ # :name, :favorite_color, {
289
+ # :pet_cat => [:name, :breed],
290
+ # :hat => [:type]
291
+ # }]
292
+ #
293
+ # Then GET /people/18.xml would render
294
+ #
295
+ # <?xml version="1.0" encoding="UTF-8"?>
296
+ # <person>
297
+ # <name>Nathan</name>
298
+ # <favorite-color>blue</favorite_color>
299
+ # <pet-cat>
300
+ # <name>Jasmine</name>
301
+ # <breed>panther</breed>
302
+ # </pet-cat>
303
+ # <hat>
304
+ # <type>top</type>
305
+ # </hat>
306
+ # </person>
307
+ #
308
+ # publish will also allow the +index+ action
309
+ # to render lists of objects.
310
+ # An example would be too big,
311
+ # but play with it a little on your own to see.
312
+ #
313
+ # publish takes only one optional option: <tt>only</tt>.
314
+ # This specifies which action to publish the resources for.
315
+ # By default, they're published for both +show+ and +index+.
316
+ # For example:
317
+ #
318
+ # # cats_controller.rb
319
+ # publish :json, :only => :index, :attributes => [:name, :breed]
320
+ #
321
+ # Then GET /cats.json would work, but GET /cats/294.json would fail.
322
+ def publish(*formats)
323
+ options = {
324
+ :only => [:show, :index]
325
+ }.merge(Hash === formats.last ? formats.pop : {})
326
+ raise "Must specify :attributes option" unless options[:attributes]
327
+
328
+ Array(options.delete(:only)).each do |action|
329
+ @publish[action] ||= []
330
+ formats.each do |format|
331
+ format = format.to_sym
332
+ @publish[action] << [format, proc do
333
+ render_action = [:json, :xml].include?(format) ? format : :text
334
+ render render_action => (plural_action? ? current_objects : current_object).serialize(format, options)
335
+ end]
336
+ end
337
+ end
338
+ end
339
+
340
+ # Specifies parent resources for the current resource.
341
+ # Each of these parents will be loaded automatically
342
+ # if the proper id parameter is given.
343
+ # For example,
344
+ #
345
+ # # cake_controller.rb
346
+ # belongs_to :baker, :customer
347
+ #
348
+ # Then on GET /bakers/12/cakes,
349
+ #
350
+ # params[:baker_id] #=> 12
351
+ # parent? #=> true
352
+ # parent_name #=> "baker"
353
+ # parent_model #=> Baker
354
+ # parent_object #=> Baker.find(12)
355
+ # current_objects #=> Baker.find(12).cakes
356
+ #
357
+ def belongs_to(*parents)
358
+ @parents = parents.map(&:to_s)
359
+ end
360
+
361
+ # This method is only meant to be called internally.
362
+ #
363
+ # Returns whether or not the Builder's controller
364
+ # inherits make_resourceful settings from a parent controller.
365
+ def inherited?
366
+ @inherited
367
+ end
368
+
369
+ private
370
+
371
+ def apply_publish
372
+ @publish.each do |action, types|
373
+ @responses[action.to_sym] ||= []
374
+ @responses[action.to_sym] += types
375
+ end
376
+ end
377
+
378
+ def add_callback(type, *events, &block)
379
+ events.each do |event|
380
+ @callbacks[type][event.to_sym] ||= []
381
+ @callbacks[type][event.to_sym] << block
382
+ end
383
+ end
384
+ end
385
+ end