common_core_js 0.3.1 → 0.3.2

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
  SHA256:
3
- metadata.gz: 2219c80f29355076e17de37d99966e7b491aa09f255a911ec907b32a983bfa1c
4
- data.tar.gz: 00dab2e16fc5145aff949648dcdddd60993aa99862b18319117d521c9ab78b16
3
+ metadata.gz: b3c68ef2ddc0f4e98ca5b54d0c646a918b2f70d091fe89db9951a61879af34d2
4
+ data.tar.gz: 5ea645a245a197d42dabf6f697a7f94e5227d6c8416da47d8dfe875fdc28cbea
5
5
  SHA512:
6
- metadata.gz: 731c8e6ef809fcade1810f67a389606f0abb62a58fe54dfcb8baa6a6b741986511cc0df2a180f390a4b55c3aee52682b91a2a64902629ac2b4fef57ef7d737a3
7
- data.tar.gz: 5a34083277277efbf9b4ef9ed7a949156489d4fbc71a14b00105ff0a169ff9a0b469e6b2ceb90a8727d86fc6f8a3ff2ac3291aeac9aaf45f650fd098fb1e9b50
6
+ metadata.gz: 7490de5c8f29a6a80960c50ecbb37a02122cafcc96b345c200f1cdc4cb3cf5f50f15e2fb4609f6f4a920b814c9fb123b9024a8d226a1e0f225bebe5246fe9cbb
7
+ data.tar.gz: fccfc40f5851a9a0bffdc5410085073afa8798320b4abf7a770c1dd7e3070ff871e341ba613f67b7afed11ea2a69c9c685dd130b41bc301ca89386490c5dd77a
data/LICENSE CHANGED
@@ -1,8 +1,8 @@
1
1
  Permission is hereby granted to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
2
2
 
3
- Any users of this software agree to work to dismantle systemic racism in American society, seek justice for black, brown, trans-people, women, and LTBQIAA+ representation and inclusion.
3
+ Any users of this software agree to work to dismantle systemic racism, seek justice for black, brown, transgender people, women, and LTBQIAA+ representation and inclusion.
4
4
 
5
- Organizations using this software agree to center the narratives of black, brown, and trans people in the self vision and imagary.
5
+ Organizations using this software agree to center the narratives of black, brown, and transgender people people.
6
6
 
7
7
  The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
8
8
 
@@ -1,3 +1,3 @@
1
1
  module CommonCoreJs
2
- VERSION = '0.3.1'
2
+ VERSION = '0.3.2'
3
3
  end
@@ -1,7 +1,36 @@
1
1
  require 'rails/generators/erb/scaffold/scaffold_generator'
2
2
  require 'ffaker'
3
3
 
4
+
5
+
4
6
  module CommonCore
7
+
8
+ module GeneratorHelper
9
+ def text_area_output(col, field_length)
10
+ lines = field_length % 40
11
+ if lines > 5
12
+ lines = 5
13
+ end
14
+
15
+ ".row
16
+ .form-group.col-md-4
17
+ = f.text_area :#{col.to_s}, class: 'form-control', cols: 40, rows: '#{lines}'
18
+ %label.form-text
19
+ #{col.to_s.humanize}\n"
20
+ end
21
+
22
+
23
+
24
+ def field_output(col, type = nil, width)
25
+ ".row
26
+ .form-group.col-md-4
27
+ = f.text_field :#{col.to_s}, value: @#{singular}.#{col.to_s}, size: #{width}, class: 'form-control', type: '#{type}'
28
+ %label.form-text
29
+ #{col.to_s.humanize}\n"
30
+ end
31
+ end
32
+
33
+
5
34
  class ScaffoldGenerator < Erb::Generators::ScaffoldGenerator
6
35
  hook_for :form_builder, :as => :scaffold
7
36
 
@@ -9,6 +38,9 @@ module CommonCore
9
38
  attr_accessor :path, :singular, :plural, :singular_class, :nest_with
10
39
 
11
40
 
41
+ include GeneratorHelper
42
+
43
+
12
44
  def initialize(*meta_args) #:nodoc:
13
45
  super
14
46
 
@@ -19,12 +51,7 @@ module CommonCore
19
51
  exit
20
52
  end
21
53
 
22
- begin
23
- @columns = object.columns.map(&:name).map(&:to_sym).reject{|x| x==:updated_at || x==:created_at || x==:id}
24
- rescue StandardError => e
25
- puts "Ooops... it looks like is an object for #{class_name}. Please create the database table with fields first. "
26
- exit
27
- end
54
+
28
55
 
29
56
  args = meta_args[0]
30
57
  @singular = args[0].tableize.singularize # should be in form hello_world
@@ -56,6 +83,18 @@ module CommonCore
56
83
  end
57
84
  end
58
85
 
86
+ auth_assoc = @auth.gsub("current_","")
87
+ auth_assoc_field = auth_assoc + "_id"
88
+
89
+
90
+ begin
91
+ @columns = object.columns.map(&:name).map(&:to_sym).reject{|field| field==:updated_at ||
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
97
+
59
98
  flags = meta_args[1]
60
99
  flags.each do |f|
61
100
  case (f)
@@ -323,9 +362,7 @@ module CommonCore
323
362
 
324
363
  def all_form_fields
325
364
  res = @columns.map { |col|
326
- # if eval("#{singular_class}.columns_hash['#{col}']").nil?
327
- # byebug
328
- # end
365
+
329
366
 
330
367
  type = eval("#{singular_class}.columns_hash['#{col}']").type
331
368
  limit = eval("#{singular_class}.columns_hash['#{col}']").limit
@@ -335,40 +372,61 @@ module CommonCore
335
372
  when :integer
336
373
  # look for a belongs_to on this object
337
374
  if col.to_s.ends_with?("_id")
375
+ # guess the association name label
376
+
338
377
 
339
378
  assoc_name = col.to_s.gsub("_id","")
340
- assoc = eval("#{singular_class}.reflect_on_association(':#{assoc_name}')")
379
+ assoc = eval("#{singular_class}.reflect_on_association(:#{assoc_name})")
380
+ if assoc.nil?
381
+ puts "*** Oops. on the #{singular_class} object, there doesn't seem to be an association called '#{assoc_name}'"
382
+ exit
383
+ end
384
+
385
+ if assoc.active_record.column_names.include?("name")
386
+ display_column = "name"
387
+ elsif assoc.active_record.column_names.include?("to_label")
388
+ display_column = "to_label"
389
+ elsif assoc.active_record.column_names.include?("full_name")
390
+ display_column = "full_name"
391
+ elsif assoc.active_record.column_names.include?("display_name")
392
+ display_column = "display_name"
393
+ elsif assoc.active_record.column_names.include?("email")
394
+ display_column = "email"
395
+ end
396
+
341
397
  ".row
342
398
  .form-group.col-md-4
343
- = f.collection_select(:#{col.to_s}, #{assoc_name.titleize}.all, :id, :to_label, {:prompt => true}, class: 'form-control')
399
+ = f.collection_select(:#{col.to_s}, #{assoc_name.titleize}.all, :id, :#{display_column}, {prompt: true, selected: @#{singular}.#{col.to_s} , class: 'form-control')
344
400
  %label.small.form-text.text-muted
345
401
  #{col.to_s.humanize}"
346
402
 
347
403
  else
348
404
  ".row
349
405
  .form-group.col-md-4
350
- = f.text_field :#{col.to_s}, class: 'form-control', size: 4, type: 'number'
406
+ = f.text_field :#{col.to_s}, value: @#{singular}.#{col.to_s}, class: 'form-control', size: 4, type: 'number'
351
407
  %label.form-text
352
408
  #{col.to_s.humanize}\n"
353
409
  end
354
410
  when :string
355
- width = (limit && limit < 40) ? limit : (40)
356
- ".row
357
- .form-group.col-md-4
358
- = f.text_field :#{col.to_s}, size: #{width}, class: 'form-control'
359
- %label.form-text
360
- #{col.to_s.humanize}\n"
411
+ limit ||= 40
412
+ if limit < 50
413
+ field_output(col, nil, limit)
414
+ else
415
+ text_area_output(col, limit)
416
+ end
417
+
361
418
  when :text
362
- # width = (limit && limit < 40) ? limit : (40)
363
- ".row
364
- .form-group.col-md-4
365
- = f.text_area :#{col.to_s}, rows: 4, cols: 40, class: 'form-control'
366
- %label.form-text
367
- #{col.humanize}\n"
368
- when :datetime
419
+ limit ||= 40
420
+ if limit < 50
421
+ field_output(col, nil, limit)
422
+ else
423
+ text_area_output(col, limit)
424
+ end
425
+
426
+ when :datetime
369
427
  ".row
370
428
  .form-group.col-md-4
371
- = f.text_field :#{col.to_s}, class: 'form-control', type: 'datetime-local'
429
+ = f.text_field :#{col.to_s}, value: @#{singular}.#{col.to_s}, class: 'form-control', type: 'datetime-local'
372
430
  %label.form-text
373
431
  #{col.to_s.humanize}\n"
374
432
  end
@@ -376,6 +434,7 @@ module CommonCore
376
434
  return res
377
435
  end
378
436
 
437
+
379
438
  def all_line_fields
380
439
  res = "%tr{'data-id': #{singular}.id, 'data-edit': 'false'}\n"
381
440
 
@@ -395,7 +454,8 @@ module CommonCore
395
454
  assoc = eval("#{singular_class}.reflect_on_association(:#{assoc_name})")
396
455
 
397
456
  if assoc.nil?
398
- raise "can't find assocation for #{assoc_name}"
457
+ puts "*** Oops. on the #{singular_class} object, there doesn't seem to be an association called '#{assoc_name}'"
458
+ exit
399
459
  end
400
460
 
401
461
  " %td
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.1
4
+ version: 0.3.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jason Fleetwood-Boldt
@@ -143,6 +143,7 @@ files:
143
143
  - app/assets/stylesheets/common_core_js/common_core.scss
144
144
  - app/controllers/common_core_js/application_controller.rb
145
145
  - app/helpers/common_core_js/application_helper.rb
146
+ - app/helpers/common_core_js/generator_helper.rb
146
147
  - app/jobs/common_core_js/application_job.rb
147
148
  - app/mailers/common_core_js/application_mailer.rb
148
149
  - app/models/common_core_js/application_record.rb