common_core_js 0.3.4 → 0.3.9
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.
- checksums.yaml +4 -4
- data/FUNDING.yml +4 -0
- data/README.md +12 -5
- data/app/helpers/{common_core_js/application_helper.rb → common_core_helper.rb} +15 -17
- data/app/helpers/common_core_js/controller_helper.rb +21 -0
- data/app/views/common/_common_edit_form.haml +4 -0
- data/app/views/common/_common_update.js.erb +2 -1
- data/lib/common_core_js/version.rb +1 -1
- data/lib/generators/common_core/scaffold_generator.rb +98 -32
- data/lib/generators/common_core/templates/_line.haml +4 -2
- data/lib/generators/common_core/templates/_list.haml +2 -2
- data/lib/generators/common_core/templates/base_controller.rb +3 -0
- data/lib/generators/common_core/templates/controller.rb +21 -12
- data/lib/generators/common_core/templates/create.js.erb +1 -1
- metadata +5 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: e52d23ca84e6aaeb8632f16b726dca47569602e8a30f67930a22aa1c92b85441
|
4
|
+
data.tar.gz: e203d956052682ec9e6a41049f001678ef1c6a1a4db90760e48e4f290ca7e2fe
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 770808dd3227c4dc7dc6c5cce6d4582f5105c59943839c5424dec7bb4d01f52ca7968a64b4615f96e968198d1f429106e0240c09909485bd9fd8b2f26d6702f0
|
7
|
+
data.tar.gz: 48dc5ad547294ab2ce9b41b5db7b2f3ea00738d27a4eb60d3c7e6abfc3c7ce0b93097d88aee4fbfecc2c7c33ff968d488ae32e5d05b307c5f63abed0cf8a3dec
|
data/FUNDING.yml
ADDED
data/README.md
CHANGED
@@ -8,25 +8,32 @@ Yes, it's opinionated. Yes, it's metaprogramming. A lot of metaprogramming. Ruby
|
|
8
8
|
No, I would not use this to build an intricate app. Yes, it's a great tool for prototyping. Yes, I think prototyping is a lost art.
|
9
9
|
|
10
10
|
|
11
|
-
|
11
|
+
## THE SALES PITCH:
|
12
12
|
* Build plug-and-play scaffolding mixing HAML with jQuery-based Javascript
|
13
13
|
* Automatically Reads Your Models (make them before building your scaffolding!)
|
14
|
-
* Excellent for CRUD, lists with pagination, searching, sorting
|
14
|
+
* Excellent for CRUD, lists with pagination, searching, ~~sorting.~~
|
15
15
|
* Wonderful for prototyping.
|
16
16
|
* Plays nicely with Devise, Kaminari, Haml-Rails, Rspec.
|
17
|
-
* Create specs
|
17
|
+
* Create specs automatically along with the controllers.
|
18
18
|
* Nest your routes model-by-model for built-in poor man's authentication
|
19
19
|
* Throw the scaffolding away when your app is ready to graduate to its next phase.
|
20
20
|
|
21
|
+
## THE BLOG POST
|
21
22
|
|
22
|
-
|
23
|
+
It's really easy to get started by following along with this blog post that creates three simple tables (User, Event, and Format).
|
24
|
+
|
25
|
+
Feel free to build your own tables when you get to the sections for building the 'Event' scaffold:
|
26
|
+
|
27
|
+
https://blog.jasonfleetwoodboldt.com/common-core-js
|
28
|
+
|
29
|
+
## HOW EASY?
|
23
30
|
|
24
31
|
|
25
32
|
```
|
26
33
|
rails generate common_core:scaffold Thing
|
27
34
|
```
|
28
35
|
|
29
|
-
|
36
|
+
## TO INSTALL
|
30
37
|
|
31
38
|
- Add common_core_js to your Gemfile
|
32
39
|
|
@@ -1,5 +1,10 @@
|
|
1
|
-
module
|
2
|
-
|
1
|
+
module CommonCoreHelper
|
2
|
+
|
3
|
+
def timezonize(tz)
|
4
|
+
tz = tz.to_i
|
5
|
+
(tz >= 0 ? "+" : "-") + sprintf('%02d',tz.abs) + ":00"
|
6
|
+
end
|
7
|
+
|
3
8
|
|
4
9
|
def datetime_field_localized(form_object, field_name, value, label, timezone = nil )
|
5
10
|
res = form_object.label(label,
|
@@ -10,12 +15,13 @@ module CommonCoreJs
|
|
10
15
|
type: 'datetime-local',
|
11
16
|
value: date_to_current_timezone(value, timezone))
|
12
17
|
|
13
|
-
res <<
|
18
|
+
res << timezonize(timezone)
|
14
19
|
res
|
15
20
|
end
|
16
21
|
|
17
22
|
|
18
23
|
def date_field_localized(form_object, field_name, value, label, timezone = nil )
|
24
|
+
|
19
25
|
res = form_object.label(label,
|
20
26
|
field_name,
|
21
27
|
class: 'small form-text text-muted')
|
@@ -36,31 +42,24 @@ module CommonCoreJs
|
|
36
42
|
type: 'time',
|
37
43
|
value: date_to_current_timezone(value, timezone))
|
38
44
|
|
39
|
-
res <<
|
45
|
+
res << timezonize(tz)
|
40
46
|
res
|
41
47
|
end
|
42
48
|
|
43
49
|
def current_timezone
|
44
|
-
if
|
50
|
+
if controller.try(:current_timezone)
|
51
|
+
controller.current_timezone
|
52
|
+
elsif defined?(current_user)
|
45
53
|
if current_user.try(:timezone)
|
46
|
-
Time.now.in_time_zone(current_user.timezone).strftime("%z").to_i/100
|
54
|
+
Time.now.in_time_zone(current_user.timezone.to_i).strftime("%z").to_i/100
|
47
55
|
else
|
48
56
|
Time.now.strftime("%z").to_i/100
|
49
57
|
end
|
50
58
|
else
|
51
|
-
raise "no method current_user is available or it does not implement timezone; please implement/override the method current_timezone"
|
59
|
+
raise "no method current_user is available or it does not implement timezone; please implement/override the method current_timezone IN YOUR CONTROLLER"
|
52
60
|
end
|
53
61
|
end
|
54
62
|
|
55
|
-
def human_timezone(time_string, timezone)
|
56
|
-
time = time_string.in_time_zone(timezone)
|
57
|
-
|
58
|
-
if time.zone.match?(/^\w/)
|
59
|
-
time.zone
|
60
|
-
else
|
61
|
-
time.formatted_offset
|
62
|
-
end
|
63
|
-
end
|
64
63
|
|
65
64
|
def date_to_current_timezone(date, timezone = nil)
|
66
65
|
# if the timezone is nil, use the server date'
|
@@ -76,5 +75,4 @@ module CommonCoreJs
|
|
76
75
|
return nil
|
77
76
|
end
|
78
77
|
end
|
79
|
-
end
|
80
78
|
end
|
@@ -0,0 +1,21 @@
|
|
1
|
+
module CommonCoreJs
|
2
|
+
module ControllerHelper
|
3
|
+
def modify_date_inputs_on_params(modified_params)
|
4
|
+
use_timezone = current_account.timezone || Time.now.strftime("%z")
|
5
|
+
|
6
|
+
modified_params = modified_params.tap do |params|
|
7
|
+
params.keys.each{|k|
|
8
|
+
if k.ends_with?("_at") || k.ends_with?("_date")
|
9
|
+
|
10
|
+
begin
|
11
|
+
params[k] = DateTime.strptime("#{params[k]} #{use_timezone}", '%Y-%m-%dT%H:%M %z')
|
12
|
+
rescue StandardError
|
13
|
+
|
14
|
+
end
|
15
|
+
end
|
16
|
+
}
|
17
|
+
end
|
18
|
+
modified_params
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
@@ -1,6 +1,7 @@
|
|
1
1
|
<% if object.errors.any? %>
|
2
2
|
<% pass_through_locals ||= {} %>
|
3
|
-
$(".<%= singular %>-table tr[data-id=<%= object.id %>][data-edit='true']").html("<%= j render
|
3
|
+
$(".<%= singular %>-table tr[data-id=<%= object.id %>][data-edit='true']").html("<%= j render partial: 'edit', locals: {singular.to_sym => object, url: url, colspan: controller.default_colspan}.merge(pass_through_locals || {}) %>")
|
4
|
+
|
4
5
|
$(".flash-notices").html("<%= j render 'layouts/flash_notices' %>");
|
5
6
|
<% else %>
|
6
7
|
$(".<%= singular %>-table tr[data-id=<%= object.id %>]:not([data-edit='true'])").replaceWith("<%= j render partial: 'line', locals: {singular.to_sym => object } %>").fadeIn()
|
@@ -84,16 +84,9 @@ module CommonCore
|
|
84
84
|
end
|
85
85
|
|
86
86
|
auth_assoc = @auth.gsub("current_","")
|
87
|
-
auth_assoc_field = auth_assoc + "_id"
|
88
|
-
|
89
87
|
|
90
|
-
|
91
|
-
|
92
|
-
field==:created_at || field==:id || field == auth_assoc_field.to_sym }
|
93
|
-
rescue StandardError => e
|
94
|
-
puts "Ooops... it looks like is an object for #{class_name}. Please create the database table with fields first. "
|
95
|
-
exit
|
96
|
-
end
|
88
|
+
@no_delete = false
|
89
|
+
@no_create = false
|
97
90
|
|
98
91
|
flags = meta_args[1]
|
99
92
|
flags.each do |f|
|
@@ -106,6 +99,10 @@ module CommonCore
|
|
106
99
|
@specs_only = true
|
107
100
|
when "--no-specs"
|
108
101
|
@no_specs = true
|
102
|
+
when "--no-delete"
|
103
|
+
@no_delete = true
|
104
|
+
when "--no-create"
|
105
|
+
@no_create = true
|
109
106
|
end
|
110
107
|
end
|
111
108
|
|
@@ -114,18 +111,56 @@ module CommonCore
|
|
114
111
|
exit
|
115
112
|
end
|
116
113
|
|
114
|
+
|
115
|
+
# only used for the before_action
|
117
116
|
if @auth_identifier.nil? && !@auth.nil?
|
118
117
|
@auth_identifier = @auth.gsub("current_", "")
|
119
118
|
end
|
120
119
|
|
120
|
+
# when in self auth, the object is the same as the authenticated object
|
121
|
+
if @auth && auth_identifier == @singular
|
122
|
+
@self_auth = true
|
123
|
+
end
|
124
|
+
|
121
125
|
if !@nest.nil?
|
122
126
|
@nested_args = @nest.split("/")
|
123
|
-
|
124
127
|
@nested_args_plural = {}
|
125
128
|
@nested_args.each do |a|
|
126
129
|
@nested_args_plural[a] = a + "s"
|
127
130
|
end
|
128
131
|
end
|
132
|
+
|
133
|
+
# the @object_owner will always be object that will 'own' the object
|
134
|
+
# for new and create
|
135
|
+
|
136
|
+
if @auth && ! @self_auth && @nested_args.none?
|
137
|
+
@object_owner_sym = @auth.gsub("current_", "").to_sym
|
138
|
+
@object_owner_eval = @auth
|
139
|
+
else
|
140
|
+
@object_owner_sym = @nested_args.last.to_sym
|
141
|
+
@object_owner_eval = "@#{@nested_args.last}"
|
142
|
+
end
|
143
|
+
|
144
|
+
|
145
|
+
|
146
|
+
# create the columns
|
147
|
+
auth_assoc_field = auth_assoc + "_id"
|
148
|
+
|
149
|
+
ownership_field = eval("#{singular_class}.reflect_on_association(:#{@object_owner_sym})").name.to_s + "_id"
|
150
|
+
|
151
|
+
|
152
|
+
exclude_fields = [auth_assoc_field.to_sym, ownership_field.to_sym, :id, :created_at, :updated_at, :encrypted_password, :reset_password_token,
|
153
|
+
:reset_password_sent_at, :remember_created_at, :confirmation_token, :confirmed_at,
|
154
|
+
:confirmation_sent_at, :unconfirmed_email]
|
155
|
+
begin
|
156
|
+
@columns = object.columns.map(&:name).map(&:to_sym).reject{|field| exclude_fields.include?(field) }
|
157
|
+
rescue StandardError => e
|
158
|
+
puts "Ooops... it looks like is an object for #{class_name}. Please create the database table with fields first. "
|
159
|
+
exit
|
160
|
+
end
|
161
|
+
|
162
|
+
|
163
|
+
|
129
164
|
end
|
130
165
|
|
131
166
|
def formats
|
@@ -141,6 +176,9 @@ module CommonCore
|
|
141
176
|
|
142
177
|
unless @specs_only
|
143
178
|
template "controller.rb", File.join("app/controllers#{namespace_with_dash}", "#{plural}_controller.rb")
|
179
|
+
if @namespace && defined?(controller_descends_from) == nil
|
180
|
+
template "base_controller.rb", File.join("app/controllers#{namespace_with_dash}", "base_controller.rb")
|
181
|
+
end
|
144
182
|
end
|
145
183
|
|
146
184
|
unless @no_specs
|
@@ -223,6 +261,14 @@ module CommonCore
|
|
223
261
|
end
|
224
262
|
|
225
263
|
|
264
|
+
def path_helper_full
|
265
|
+
"#{@namespace+"_" if @namespace}#{(@nested_args.join("_") + "_" if @nested_args.any?)}#{singular}_path"
|
266
|
+
end
|
267
|
+
|
268
|
+
def path_helper_args
|
269
|
+
[(@nested_args if @nested_args.any?).collect{|a| "@#{a}"} , singular].join(",")
|
270
|
+
end
|
271
|
+
|
226
272
|
def path_helper_singular
|
227
273
|
"#{@namespace+"_" if @namespace}#{(@nested_args.join("_") + "_" if @nested_args.any?)}#{singular}_path"
|
228
274
|
end
|
@@ -252,7 +298,7 @@ module CommonCore
|
|
252
298
|
end
|
253
299
|
|
254
300
|
def nested_arity_for_path
|
255
|
-
@nested_args.join(", ") #metaprgramming into arity for the Rails path helper
|
301
|
+
[@nested_args[0..-1].collect{|a| "@#{a}"}].join(", ") #metaprgramming into arity for the Rails path helper
|
256
302
|
end
|
257
303
|
|
258
304
|
def object_scope
|
@@ -270,7 +316,9 @@ module CommonCore
|
|
270
316
|
|
271
317
|
def all_objects_root
|
272
318
|
if @auth
|
273
|
-
if @
|
319
|
+
if @self_auth
|
320
|
+
@singular_class + ".where(id: #{@auth}.id)"
|
321
|
+
elsif @nested_args.none?
|
274
322
|
@auth + ".#{plural}"
|
275
323
|
else
|
276
324
|
"@" + @nested_args.last + ".#{plural}"
|
@@ -285,8 +333,12 @@ module CommonCore
|
|
285
333
|
end
|
286
334
|
|
287
335
|
def all_objects_variable
|
336
|
+
|
288
337
|
# needs the authenticated root user
|
289
|
-
"#{@auth}.#{ @nested_args.map{|a| "#{@nested_args_plural[a]}.find(@#{a})"}.join('.') + "." if @nested_args.any?}#{plural}"
|
338
|
+
# "#{@auth}.#{ @nested_args.map{|a| "#{@nested_args_plural[a]}.find(@#{a})"}.join('.') + "." if @nested_args.any?}#{plural}"
|
339
|
+
|
340
|
+
all_objects_root + ".page(params[:page])"
|
341
|
+
|
290
342
|
end
|
291
343
|
|
292
344
|
def auth_object
|
@@ -344,15 +396,6 @@ module CommonCore
|
|
344
396
|
:erb
|
345
397
|
end
|
346
398
|
|
347
|
-
|
348
|
-
def create_merge_params
|
349
|
-
if @auth
|
350
|
-
"#{@auth_identifier}: #{@auth}"
|
351
|
-
else
|
352
|
-
""
|
353
|
-
end
|
354
|
-
end
|
355
|
-
|
356
399
|
def model_has_strings?
|
357
400
|
false
|
358
401
|
end
|
@@ -383,6 +426,7 @@ module CommonCore
|
|
383
426
|
puts "*** Oops. on the #{singular_class} object, there doesn't seem to be an association called '#{assoc_name}'"
|
384
427
|
exit
|
385
428
|
end
|
429
|
+
assoc_class_name = eval("#{singular_class}.reflect_on_association(:#{assoc_name})").class_name
|
386
430
|
|
387
431
|
if assoc.active_record.column_names.include?("name")
|
388
432
|
display_column = "name"
|
@@ -394,11 +438,14 @@ module CommonCore
|
|
394
438
|
display_column = "display_name"
|
395
439
|
elsif assoc.active_record.column_names.include?("email")
|
396
440
|
display_column = "email"
|
441
|
+
else
|
442
|
+
puts "Can't find a display_column on {singular_class} object"
|
397
443
|
end
|
398
444
|
|
445
|
+
|
399
446
|
".row
|
400
447
|
%div{class: \"form-group col-md-4 \#{'alert-danger' if #{singular}.errors.details.keys.include?(:#{assoc_name.to_s})}\"}
|
401
|
-
= f.collection_select(:#{col.to_s}, #{
|
448
|
+
= f.collection_select(:#{col.to_s}, #{assoc_class_name}.all, :id, :#{display_column}, {prompt: true, selected: @#{singular}.#{col.to_s} }, class: 'form-control')
|
402
449
|
%label.small.form-text.text-muted
|
403
450
|
#{col.to_s.humanize}"
|
404
451
|
|
@@ -410,16 +457,16 @@ module CommonCore
|
|
410
457
|
#{col.to_s.humanize}\n"
|
411
458
|
end
|
412
459
|
when :string
|
413
|
-
limit ||=
|
414
|
-
if limit
|
460
|
+
limit ||= 256
|
461
|
+
if limit <= 256
|
415
462
|
field_output(col, nil, limit)
|
416
463
|
else
|
417
464
|
text_area_output(col, limit)
|
418
465
|
end
|
419
466
|
|
420
467
|
when :text
|
421
|
-
limit ||=
|
422
|
-
if limit
|
468
|
+
limit ||= 256
|
469
|
+
if limit <= 256
|
423
470
|
field_output(col, nil, limit)
|
424
471
|
else
|
425
472
|
text_area_output(col, limit)
|
@@ -428,15 +475,15 @@ module CommonCore
|
|
428
475
|
when :datetime
|
429
476
|
".row
|
430
477
|
%div{class: \"form-group col-md-4 \#{'alert-danger' if #{singular}.errors.details.keys.include?(:#{col.to_s})}\"}
|
431
|
-
= datetime_field_localized(f, :#{col.to_s}, @#{singular}.#{col.to_s}, '#{col.to_s.humanize}', #{@auth
|
478
|
+
= datetime_field_localized(f, :#{col.to_s}, @#{singular}.#{col.to_s}, '#{col.to_s.humanize}', #{@auth ? @auth+'.timezone' : 'nil'})"
|
432
479
|
when :date
|
433
480
|
".row
|
434
481
|
%div{class: \"form-group col-md-4 \#{'alert-danger' if #{singular}.errors.details.keys.include?(:#{col.to_s})}\"}
|
435
|
-
= date_field_localized(f, :#{col.to_s}, @#{singular}.#{col.to_s}, '#{col.to_s.humanize}', #{@auth
|
482
|
+
= date_field_localized(f, :#{col.to_s}, @#{singular}.#{col.to_s}, '#{col.to_s.humanize}', #{@auth ? @auth+'.timezone' : 'nil'})"
|
436
483
|
when :time
|
437
484
|
".row
|
438
485
|
%div{class: \"form-group col-md-4 \#{'alert-danger' if #{singular}.errors.details.keys.include?(:#{col.to_s})}\"}
|
439
|
-
= time_field_localized(f, :#{col.to_s}, @#{singular}.#{col.to_s}, '#{col.to_s.humanize}', #{@auth
|
486
|
+
= time_field_localized(f, :#{col.to_s}, @#{singular}.#{col.to_s}, '#{col.to_s.humanize}', #{@auth ? @auth+'.timezone' : 'nil'})"
|
440
487
|
|
441
488
|
end
|
442
489
|
|
@@ -499,7 +546,7 @@ module CommonCore
|
|
499
546
|
when :datetime
|
500
547
|
" %td
|
501
548
|
- unless #{singular}.#{col}.nil?
|
502
|
-
= #{singular}.#{col}.in_time_zone(current_timezone).strftime('%m/%d/%Y @ %l:%M %p ') +
|
549
|
+
= #{singular}.#{col}.in_time_zone(current_timezone).strftime('%m/%d/%Y @ %l:%M %p ') + timezonize(current_timezone)
|
503
550
|
- else
|
504
551
|
%span.alert-danger
|
505
552
|
MISSING
|
@@ -515,7 +562,7 @@ module CommonCore
|
|
515
562
|
when :time
|
516
563
|
" %td
|
517
564
|
- unless #{singular}.#{col}.nil?
|
518
|
-
= #{singular}.#{col}.in_time_zone(current_timezone).strftime('%l:%M %p ') +
|
565
|
+
= #{singular}.#{col}.in_time_zone(current_timezone).strftime('%l:%M %p ') + timezonize(current_timezone)
|
519
566
|
- else
|
520
567
|
%span.alert-danger
|
521
568
|
MISSING
|
@@ -527,6 +574,25 @@ module CommonCore
|
|
527
574
|
end
|
528
575
|
|
529
576
|
|
577
|
+
def controller_descends_from
|
578
|
+
if defined?(@namespace.titlecase + "::BaseController")
|
579
|
+
@namespace.titlecase + "::BaseController"
|
580
|
+
else
|
581
|
+
"ApplicationController"
|
582
|
+
end
|
583
|
+
end
|
584
|
+
|
585
|
+
|
586
|
+
def destroy_action
|
587
|
+
return false if @self_auth
|
588
|
+
return !@no_delete
|
589
|
+
end
|
590
|
+
|
591
|
+
def create_action
|
592
|
+
return false if @self_auth
|
593
|
+
return !@no_create
|
594
|
+
end
|
595
|
+
|
530
596
|
|
531
597
|
private # thor does something fancy like sending the class all of its own methods during some strange run sequence
|
532
598
|
# does not like public methods
|
@@ -1,5 +1,7 @@
|
|
1
1
|
<%= all_line_fields %>
|
2
2
|
%td
|
3
|
-
|
3
|
+
<% if destroy_action %>
|
4
|
+
= link_to "Delete <i class='fa fa-1x fa-remove'></i>".html_safe, <%= path_helper_full %>(<%= path_helper_args %>), remote: true, method: :delete, data: {confirm: 'Are you sure?'}, disable_with: "Loading...", class: "delete-<%= singular %>-button btn btn-primary "
|
5
|
+
<% end %>
|
4
6
|
|
5
|
-
= link_to "Edit <i class='fa fa-1x fa-list-alt'></i>".html_safe, edit_<%=
|
7
|
+
= link_to "Edit <i class='fa fa-1x fa-list-alt'></i>".html_safe, edit_<%= path_helper_full %>(<%= path_helper_args %>), remote: true , disable_with: "Loading...", class: "edit-<%= singular %>-button btn btn-primary "
|
@@ -1,9 +1,9 @@
|
|
1
1
|
|
2
|
+
<% if create_action %>
|
2
3
|
= link_to "New <%= singular.gsub('_',' ') %>", new_<%= path_helper_singular %>(<%= nested_arity_for_path %>), disable_with: "Loading...", remote: true, class: "new-<%= singular %>-button btn btn-primary pull-right"
|
3
|
-
|
4
4
|
.clearfix
|
5
5
|
.new-<%= singular %>-form{style: "display: none; position: relative;"}
|
6
|
-
|
6
|
+
<% end %>
|
7
7
|
|
8
8
|
|
9
9
|
%table.table.table-striped.<%= singular %>-table
|
@@ -1,12 +1,13 @@
|
|
1
|
-
class <%= controller_class_name %> <
|
2
|
-
<% unless @auth_identifier
|
1
|
+
class <%= controller_class_name %> < <%= controller_descends_from %>
|
2
|
+
<% unless @auth_identifier == '' %>
|
3
3
|
before_action :authenticate_<%= auth_identifier %>!
|
4
4
|
|
5
5
|
<% end %>
|
6
6
|
<% if any_nested? %> <% @nested_args.each do |arg| %>
|
7
7
|
before_action :load_<%= arg %><% end %> <% end %>
|
8
8
|
before_action :load_<%= singular_name %>, only: [:show, :edit, :update, :destroy]
|
9
|
-
|
9
|
+
helper :common_core
|
10
|
+
include CommonCoreJs::ControllerHelpers
|
10
11
|
|
11
12
|
<% if any_nested? %><% nest_chain = [] %> <% @nested_args.each do |arg| %>
|
12
13
|
<% if nest_chain.empty?
|
@@ -19,29 +20,37 @@ class <%= controller_class_name %> < ApplicationController
|
|
19
20
|
@<%= arg %> = <%= this_scope %>.find(params[:<%= arg %>_id])
|
20
21
|
end<% end %> <% end %>
|
21
22
|
|
23
|
+
|
24
|
+
<% if !@self_auth %>
|
22
25
|
def load_<%= singular_name %>
|
23
26
|
@<%= singular_name %> = <%= object_scope %>.find(params[:id])
|
24
27
|
end
|
25
|
-
|
28
|
+
<% else %>
|
29
|
+
def load_<%= singular_name %>
|
30
|
+
@<%= singular_name %> = <%= auth_object %>
|
31
|
+
end<% end %>
|
26
32
|
|
27
33
|
def index
|
34
|
+
<% if !@self_auth %>
|
28
35
|
@<%= plural_name %> = <%= object_scope %><% if model_has_strings? %>.where(<%=class_name %>.arel_table[:email].matches("%#{@__general_string}%"))<% end %>.page(params[:page])
|
29
|
-
|
36
|
+
<% else %>
|
37
|
+
@<%= plural_name %> = [<%= auth_object %>]
|
38
|
+
<% end %>
|
30
39
|
respond_to do |format|
|
31
40
|
format.js<% if @with_index %>
|
32
41
|
format.html {render 'all.haml'}<% end %>
|
33
42
|
end
|
34
43
|
end
|
35
44
|
|
36
|
-
def new
|
37
|
-
@<%= singular_name %> = <%= class_name %>.new(<%=
|
45
|
+
<% if create_action %> def new
|
46
|
+
@<%= singular_name %> = <%= class_name %>.new(<%= @object_owner_sym %>: <%= @object_owner_eval %>)
|
38
47
|
respond_to do |format|
|
39
48
|
format.js
|
40
49
|
end
|
41
50
|
end
|
42
51
|
|
43
52
|
def create
|
44
|
-
modified_params = modify_date_inputs_on_params(<%=singular_name %>_params.dup<% if
|
53
|
+
modified_params = modify_date_inputs_on_params(<%=singular_name %>_params.dup<% if !@object_owner_sym.empty? %>.merge!(<%= @object_owner_sym %>: <%= @object_owner_eval %> )<% end %>, <%= @auth %>)
|
45
54
|
@<%=singular_name %> = <%=class_name %>.create(modified_params)
|
46
55
|
respond_to do |format|
|
47
56
|
if @<%= singular_name %>.save
|
@@ -50,7 +59,7 @@ class <%= controller_class_name %> < ApplicationController
|
|
50
59
|
end
|
51
60
|
format.js
|
52
61
|
end
|
53
|
-
end
|
62
|
+
end<% end %>
|
54
63
|
|
55
64
|
def show
|
56
65
|
respond_to do |format|
|
@@ -66,14 +75,14 @@ class <%= controller_class_name %> < ApplicationController
|
|
66
75
|
|
67
76
|
def update
|
68
77
|
respond_to do |format|
|
69
|
-
if !@<%=singular_name %>.update(modify_date_inputs_on_params(<%= singular %>_params,
|
78
|
+
if !@<%=singular_name %>.update(modify_date_inputs_on_params(<%= singular %>_params, <%= @auth %> ))
|
70
79
|
flash[:alert] = "<%=singular_name.titlecase %> could not be saved"
|
71
80
|
end
|
72
81
|
format.js {}
|
73
82
|
end
|
74
83
|
end
|
75
84
|
|
76
|
-
|
85
|
+
<% if destroy_action %>def destroy
|
77
86
|
respond_to do |format|
|
78
87
|
begin
|
79
88
|
@<%=singular_name%>.destroy
|
@@ -82,7 +91,7 @@ class <%= controller_class_name %> < ApplicationController
|
|
82
91
|
end
|
83
92
|
format.js {}
|
84
93
|
end
|
85
|
-
end
|
94
|
+
end<% end %>
|
86
95
|
|
87
96
|
def <%=singular_name%>_params
|
88
97
|
params.require(:<%=singular_name%>).permit( <%= @columns %> )
|
@@ -1 +1 @@
|
|
1
|
-
<%%= render partial: 'common/common_create', locals: {object: @<%= singular %>, singular: "<%= singular %>", plural: "<%= plural %>"} %>
|
1
|
+
<%%= render partial: 'common/common_create', locals: {object: @<%= singular %>, singular: "<%= singular %>", plural: "<%= plural %>"<%= ", " + nested_assignments if nested_assignments %>} %>
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: common_core_js
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.3.
|
4
|
+
version: 0.3.9
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Jason Fleetwood-Boldt
|
@@ -131,6 +131,7 @@ files:
|
|
131
131
|
- ".generators"
|
132
132
|
- ".gitignore"
|
133
133
|
- ".rakeTasks"
|
134
|
+
- FUNDING.yml
|
134
135
|
- Gemfile
|
135
136
|
- Gemfile.lock
|
136
137
|
- LICENSE
|
@@ -142,7 +143,8 @@ files:
|
|
142
143
|
- app/assets/stylesheets/common_core_js/application.css
|
143
144
|
- app/assets/stylesheets/common_core_js/common_core.scss
|
144
145
|
- app/controllers/common_core_js/application_controller.rb
|
145
|
-
- app/helpers/
|
146
|
+
- app/helpers/common_core_helper.rb
|
147
|
+
- app/helpers/common_core_js/controller_helper.rb
|
146
148
|
- app/jobs/common_core_js/application_job.rb
|
147
149
|
- app/mailers/common_core_js/application_mailer.rb
|
148
150
|
- app/models/common_core_js/application_record.rb
|
@@ -176,6 +178,7 @@ files:
|
|
176
178
|
- lib/generators/common_core/templates/_list.haml
|
177
179
|
- lib/generators/common_core/templates/_new.haml
|
178
180
|
- lib/generators/common_core/templates/all.haml
|
181
|
+
- lib/generators/common_core/templates/base_controller.rb
|
179
182
|
- lib/generators/common_core/templates/common_core.js
|
180
183
|
- lib/generators/common_core/templates/common_core.scss
|
181
184
|
- lib/generators/common_core/templates/controller.rb
|