express_admin 1.7.32 → 1.8.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 2b7203cd11047e5af24b9b0b5e18712dc795a31b
4
- data.tar.gz: d38502cbb43733b0148b3d6a83853fb7ffb473c8
3
+ metadata.gz: 4a8259fa012044052d609f7a6881237554b0ccdf
4
+ data.tar.gz: 44f29a68c1ec5dab242ed703807bbb6058a22062
5
5
  SHA512:
6
- metadata.gz: e8a44e05cf7bec13d68307f375234f18cff805bc37924525e0ccfc0849ade392cca1f06f3ad291a08f9ab50f3eb3631b90d9b6ff2c71a8827674a9e17ebb6315
7
- data.tar.gz: 3e20299dc4a5a07c4b6a2d1974404a2202cf59fe66a289844cee901ea4e0acb94a74c4cceee2d7dfa27cd19d3897f68b2972bcd06f7ec90a6db456ae8d2fe7ee
6
+ metadata.gz: 067926317358129976bb254f20e684c46724d639251b93385099c80f274fae24fe665419949deb9bdfffcecac6298c73e78a32d9f9b14a3ff894a10ff02a76fd
7
+ data.tar.gz: 0d864ebea27d88057a800508ff14fd50da9a89475454fb2c829d9c6dba38de8dccd9752b587cde35a802459ebf9c40ab93ff8b02886906b3778b8f8488d7572a
@@ -29,7 +29,13 @@ module ExpressAdmin
29
29
  controller_class = "#{modules.join("/").classify.pluralize}Controller".constantize
30
30
  rescue NameError => e
31
31
  # if plural fails, use singular
32
- controller_class = "#{modules.join("/").classify}Controller".constantize
32
+ begin
33
+ controller_class = "#{modules.join("/").classify}Controller".constantize
34
+ rescue NameError => e2
35
+ # if we get here, the first exception wasn't what we thought
36
+ # it was something else and we should politely let the developer know
37
+ raise e
38
+ end
33
39
  end
34
40
  if controller_class.respond_to?(:resource_class)
35
41
  resource_class = controller_class.resource_class
@@ -87,14 +87,14 @@ module ExpressAdmin
87
87
  build_resource
88
88
  load_collection
89
89
  respond_to do |format|
90
- format.html { render index_view, layout: defaults[:layout] }
90
+ format.html { render index_view, layout: index_layout }
91
91
  end
92
92
  end
93
93
 
94
94
  def new
95
95
  build_resource
96
96
  respond_to do |format|
97
- format.html { render new_view, layout: defaults[:layout] }
97
+ format.html { render new_view, layout: new_layout }
98
98
  end
99
99
  end
100
100
 
@@ -102,11 +102,13 @@ module ExpressAdmin
102
102
  build_resource(resource_params)
103
103
  if resource.save
104
104
  respond_to do |format|
105
- format.html { redirect_to resource_path }
105
+ format.html { redirect_to after_create_path }
106
+ format.js { render create_view, status: :created }
106
107
  end
107
108
  else
108
109
  respond_to do |format|
109
- format.html { render new_view, layout: defaults[:layout] }
110
+ format.html { render new_view, layout: new_layout }
111
+ format.js { render create_view, status: :unprocessable_entity }
110
112
  end
111
113
  end
112
114
  end
@@ -115,14 +117,14 @@ module ExpressAdmin
115
117
  load_resource
116
118
  load_collection
117
119
  respond_to do |format|
118
- format.html { render show_view, layout: defaults[:layout] }
120
+ format.html { render show_view, layout: show_layout }
119
121
  end
120
122
  end
121
123
 
122
124
  def edit
123
125
  load_resource
124
126
  respond_to do |format|
125
- format.html { render edit_view, layout: defaults[:layout] }
127
+ format.html { render edit_view, layout: edit_layout }
126
128
  end
127
129
  end
128
130
 
@@ -130,11 +132,13 @@ module ExpressAdmin
130
132
  load_resource
131
133
  if resource.update_attributes(resource_params)
132
134
  respond_to do |format|
133
- format.html { redirect_to resource_path }
135
+ format.html { redirect_to after_update_path }
136
+ format.js { render update_view, status: :ok }
134
137
  end
135
138
  else
136
139
  respond_to do |format|
137
- format.html { render edit_view, layout: defaults[:layout] }
140
+ format.html { render edit_view, layout: edit_layout }
141
+ format.js { render update_view, status: :unprocessable_entity }
138
142
  end
139
143
  end
140
144
  end
@@ -143,12 +147,24 @@ module ExpressAdmin
143
147
  load_resource
144
148
  resource.destroy!
145
149
  respond_to do |format|
146
- format.html { redirect_to collection_path }
150
+ format.html { redirect_to after_destroy_path }
147
151
  end
148
152
  end
149
153
 
150
154
  protected
151
155
 
156
+ def after_update_path
157
+ resource_path
158
+ end
159
+
160
+ def after_create_path
161
+ resource_path
162
+ end
163
+
164
+ def after_destroy_path
165
+ collection_path
166
+ end
167
+
152
168
  def edit_view
153
169
  :edit
154
170
  end
@@ -165,6 +181,23 @@ module ExpressAdmin
165
181
  :index
166
182
  end
167
183
 
184
+ def create_view
185
+ :create
186
+ end
187
+
188
+ def update_view
189
+ :udpate
190
+ end
191
+
192
+ def default_layout
193
+ defaults[:layout]
194
+ end
195
+
196
+ alias new_layout default_layout
197
+ alias edit_layout default_layout
198
+ alias show_layout default_layout
199
+ alias index_layout default_layout
200
+
168
201
  def resource_path
169
202
  proxy = route_proxy
170
203
  proxy ||= self
@@ -334,6 +367,8 @@ module ExpressAdmin
334
367
  (parent_resource_names + [collection_name, 'path']).join('_')
335
368
  end
336
369
 
370
+ # defines a current_<something> for each parent
371
+ # resource in a nested resource situation
337
372
  def expose_parent_resources
338
373
  parent_resources = parent_resource_names
339
374
  return if parent_resources.blank?
@@ -345,12 +380,17 @@ module ExpressAdmin
345
380
  unless self.methods.include?(current_parent)
346
381
  if previous_parent.nil?
347
382
  self.class_eval do
383
+
348
384
  define_method(current_parent) do
349
- parent_class = parent_module_name.constantize
350
385
  current_class_name = parent_name.camelize
351
- current_class = parent_class.const_defined?(current_class_name) ?
352
- parent_class.const_get(current_class_name) :
353
- "::#{parent_name.camelize}".constantize
386
+ parent_module = parent_module_name.constantize rescue nil
387
+ current_class =
388
+ if parent_module && # try to find the class in the parent module
389
+ parent_module.const_defined?(current_class_name)
390
+ parent_module.const_get(current_class_name)
391
+ else
392
+ "::#{current_class_name.camelize}".constantize
393
+ end
354
394
  current_class.find(parent_id)
355
395
  end
356
396
  end
@@ -378,8 +418,17 @@ module ExpressAdmin
378
418
  end
379
419
  end
380
420
 
381
- def extract_path_info_from_routes
382
- recognized_path = nil
421
+ def extract_path_info_from_application_routes
422
+ begin
423
+ recognized_path = Rails.application.routes.recognize_path(request.path)
424
+ rescue ActionController::RoutingError => e
425
+ end
426
+ end
427
+
428
+ # TODO: to accurately reproduce the fall through matching
429
+ # we need to do this in order of mounting within the
430
+ # application routes.
431
+ def extract_path_info_from_engine_routes
383
432
  Rails::Engine.subclasses.each do |engine|
384
433
  engine_instance = engine.instance
385
434
  engine_route = Rails.application.routes.routes.find do |r|
@@ -392,13 +441,11 @@ module ExpressAdmin
392
441
  rescue ActionController::RoutingError => e
393
442
  end
394
443
  end
395
- if recognized_path.nil?
396
- begin
397
- recognized_path = Rails.application.routes.recognize_path(request.path)
398
- rescue ActionController::RoutingError => e
399
- end
400
- end
401
- recognized_path
444
+ end
445
+
446
+ def extract_path_info_from_routes
447
+ extract_path_info_from_application_routes ||
448
+ extract_path_info_from_engine_routes
402
449
  end
403
450
 
404
451
  def resource_ids_hash
@@ -1,3 +1,3 @@
1
1
  module ExpressAdmin
2
- VERSION = "1.7.32"
2
+ VERSION = "1.8.0"
3
3
  end
Binary file
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: express_admin
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.7.32
4
+ version: 1.8.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Steven Talcott Smith
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-02-23 00:00:00.000000000 Z
11
+ date: 2016-03-17 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: express_templates
@@ -760,3 +760,4 @@ test_files:
760
760
  - test/lib/generators/express_admin/scaffold_generator_test.rb
761
761
  - test/support/test_menu.yml
762
762
  - test/test_helper.rb
763
+ has_rdoc: