bullet_train-super_scaffolding 1.5.1 → 1.5.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: 5b401a89cc8733d82b955c7a8364fd8d4f5baf0db63ab606dcbcf60686c5ba33
4
- data.tar.gz: 8368208e9fb8fb26726b09baaf5dccc9990f6791c143ceedac03e82d846e2615
3
+ metadata.gz: 69058843f0779cdd62cd70d3c1a628efc280339ec7f8056c9e1ee4a0cf3eeac0
4
+ data.tar.gz: d8b6eba75ba033cdfed28dfac6541c4708195d2fbdcb06fa3fe9c1f4c86d4149
5
5
  SHA512:
6
- metadata.gz: 11500e4a8fd203a0f84d3ba2235293c4195be193920f4c646c4cd72a9bd01972bb23c3f3b07b5c9798c5a9db98b8460c9f8637e348f45608a512acfcbc7258fe
7
- data.tar.gz: da6529b8e728292c20192119a374693b5b9c9d2603d41c75014e30a91eaeda172ddefe48287d56abbb7a8344247e01e62cab6e394332a414cf62baad93ef6777
6
+ metadata.gz: 6f3beaf757781c0522f677b6d40a27bf8cd5804e8079cd4b6e13bf10e3ad7e1119c022fd5ad1a7aa7b58625feee6bd00e079e7bf25b336f2171e1c140acadc3f
7
+ data.tar.gz: d57c47406f32696055be9834fd388de04ac2df32d3a0f86fd162ce91dce0cb7c684c7cc089625126fc2aa613874f849208d164f365b80d5ee84bbafae49de65a
@@ -1,5 +1,5 @@
1
1
  module BulletTrain
2
2
  module SuperScaffolding
3
- VERSION = "1.5.1"
3
+ VERSION = "1.5.2"
4
4
  end
5
5
  end
@@ -167,6 +167,8 @@ class Scaffolding::Attribute
167
167
  "text"
168
168
  when "number_field"
169
169
  "number"
170
+ when "address_field"
171
+ "address"
170
172
  else
171
173
  raise "Invalid field type: #{type}."
172
174
  end
@@ -121,6 +121,7 @@ elsif ARGV.first.present?
121
121
  puts "Bullet Train uses the following field partials for Super Scaffolding".blue
122
122
  puts ""
123
123
  field_partials = {
124
+ address_field: "string",
124
125
  boolean: "boolean",
125
126
  buttons: "string",
126
127
  cloudinary_image: "string",
@@ -870,8 +870,11 @@ class Scaffolding::Transformer
870
870
  <td#{cell_attributes}><%= render 'shared/attributes/#{attribute.partial_name}', attribute: :#{attribute.is_vanilla? ? attribute.name : attribute.name_without_id_suffix}#{", #{table_cell_options.join(", ")}" if table_cell_options.any?} %></td>
871
871
  ERB
872
872
 
873
- if attribute.type == "password_field"
873
+ case attribute.type
874
+ when "password_field"
874
875
  field_content.gsub!(/\s%>/, ", options: { password: true } %>")
876
+ when "address_field"
877
+ field_content.gsub!(/\s%>/, ", one_line: true %>")
875
878
  end
876
879
 
877
880
  unless ["Team", "User"].include?(child)
@@ -958,6 +961,20 @@ class Scaffolding::Transformer
958
961
  if attribute.type == "file_field"
959
962
  scaffold_add_line_to_file(file, "#{attribute.name}_removal: [],", RUBY_NEW_ARRAYS_HOOK, prepend: true)
960
963
  end
964
+ elsif attribute.type == "address_field"
965
+ address_strong_params = <<~RUBY
966
+ #{attribute.name}_attributes: [
967
+ :id,
968
+ :_destroy,
969
+ :address_one,
970
+ :address_two,
971
+ :city,
972
+ :country_id,
973
+ :region_id,
974
+ :postal_code
975
+ ],
976
+ RUBY
977
+ scaffold_add_line_to_file(file, address_strong_params, RUBY_NEW_ARRAYS_HOOK, prepend: true)
961
978
  else
962
979
  scaffold_add_line_to_file(file, ":#{attribute.name},", RUBY_NEW_FIELDS_HOOK, prepend: true)
963
980
  if attribute.type == "file_field"
@@ -969,6 +986,28 @@ class Scaffolding::Transformer
969
986
  scaffold_add_line_to_file("./app/controllers/account/scaffolding/completely_concrete/tangible_things_controller.rb", attribute.special_processing, RUBY_NEW_FIELDS_PROCESSING_HOOK, prepend: true) if attribute.special_processing
970
987
  end
971
988
 
989
+ #
990
+ # ASSOCIATED MODELS
991
+ #
992
+
993
+ unless cli_options["skip-form"] || attribute.options[:readonly]
994
+
995
+ # set default values for associated models.
996
+ case attribute.type
997
+ when "address_field"
998
+ scaffold_add_line_to_file("./app/controllers/account/scaffolding/completely_concrete/tangible_things_controller.rb", "before_action :set_default_#{attribute.name}, except: :index", "ApplicationController", increase_indent: true)
999
+
1000
+ method_content = <<~RUBY
1001
+
1002
+ def set_default_#{attribute.name}
1003
+ @tangible_thing.#{attribute.name} ||= Address.new
1004
+ end
1005
+ RUBY
1006
+ scaffold_add_line_to_file("./app/controllers/account/scaffolding/completely_concrete/tangible_things_controller.rb", method_content, "end", prepend: true, increase_indent: true, exact_match: true)
1007
+ end
1008
+
1009
+ end
1010
+
972
1011
  #
973
1012
  # API SERIALIZER
974
1013
  #
@@ -1246,6 +1285,9 @@ class Scaffolding::Transformer
1246
1285
  scaffold_add_line_to_file("./app/models/scaffolding/completely_concrete/tangible_thing.rb", "after_validation :remove_#{attribute.name}, if: :#{attribute.name}_removal?", CALLBACKS_HOOK, prepend: true)
1247
1286
  when "trix_editor"
1248
1287
  scaffold_add_line_to_file("./app/models/scaffolding/completely_concrete/tangible_thing.rb", "has_rich_text :#{attribute.name}", HAS_ONE_HOOK, prepend: true)
1288
+ when "address_field"
1289
+ scaffold_add_line_to_file("./app/models/scaffolding/completely_concrete/tangible_thing.rb", "has_one :#{attribute.name}, class_name: \"Address\", as: :addressable", HAS_ONE_HOOK, prepend: true)
1290
+ scaffold_add_line_to_file("./app/models/scaffolding/completely_concrete/tangible_thing.rb", "accepts_nested_attributes_for :#{attribute.name}", HAS_ONE_HOOK, prepend: true)
1249
1291
  when "buttons"
1250
1292
  if attribute.is_boolean?
1251
1293
  scaffold_add_line_to_file("./app/models/scaffolding/completely_concrete/tangible_thing.rb", "validates :#{attribute.name}, inclusion: [true, false]", VALIDATIONS_HOOK, prepend: true)
data/lib/scaffolding.rb CHANGED
@@ -7,6 +7,7 @@ module Scaffolding
7
7
 
8
8
  def self.valid_attribute_type?(type)
9
9
  [
10
+ "address_field",
10
11
  "boolean",
11
12
  "buttons",
12
13
  # TODO: We're leaving cloudinary_image here for now for backwards compatibility.
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: bullet_train-super_scaffolding
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.5.1
4
+ version: 1.5.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Andrew Culver
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2023-10-02 00:00:00.000000000 Z
11
+ date: 2023-10-03 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: standard