hot-glue 0.5.4 → 0.5.5

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: 4770a6dafa96c7d17e2104d7349caf126a7922c660b3055b29c6a7eab6e7d851
4
- data.tar.gz: cd730bb99e9d9dad8ca5ee22a504a9e91ace01123ce900e11c7ccffae3e26630
3
+ metadata.gz: eedf5dcbc79766ed47352778020a633eb34324ecefb715b5e9b5476f119f80e6
4
+ data.tar.gz: 95e59bd0f9dc73b62c7b1d4a653a9384fed801ec9b8d672f44cc9e4636b56dc9
5
5
  SHA512:
6
- metadata.gz: 5f59544515a51f85e494bd7a1ec7ee4586ab761919554f53ad751b845906e412a5cd80f65e1447183d79246e295abbb1fe468814ef572cd93888970603aafb7a
7
- data.tar.gz: 045115777e9399ddffd06f9b400d44cc1d5e230579ea9d2017213cf74ae786efe2ae42d52639dbc60b496d0628f8a955c0d03807cd7262203de1961e0ecf87c8
6
+ metadata.gz: 99c381f75071b812279eb0cda17d4e0086fafba3385e37283e838610fb2e8574d3659c7e130ef4ac2531309a564d3c4b7a1a1064475c4d370ba7de942d67dcfd
7
+ data.tar.gz: 5fd29976555c4dc94814afeec9759c8156db92d6df9c178ece27d7b9bbd9570db5e764f75c3b2c61a7c26391950718c181fa0b03224858e41f836654fc9a6a01
data/.gitignore CHANGED
@@ -16,11 +16,18 @@ Gemfile.lock
16
16
 
17
17
  db/*.sqlite3
18
18
 
19
- spec/dummy/app/views/
20
- spec/dummy/app/controllers/
21
- spec/dummy/specs/
19
+ dummy/app/views/
20
+ dummy/app/controllers/
21
+ dummy/specs/
22
+
23
+ dummy/node_modules/
24
+ dummy/log/
25
+ dummy/Gemfile.lock
26
+ dummy/config/hot_glue.yml
22
27
 
23
- spec/dummy/node_modules/
24
- spec/dummy/log/
25
28
 
26
29
  coverage/
30
+
31
+
32
+ spec/dummy/
33
+ dummy/spec/system/
data/README.md CHANGED
@@ -29,10 +29,10 @@ How is it different than Rails scaffolding?
29
29
 
30
30
  Although inspired by the Rails scaffold generators (built-in to Rails), Hot Glue does something similiar but has made opinionated decisions that deviate from the normal Rails scaffold:
31
31
 
32
- 1. The Hot Glue scaffolds are complete packages and pre-optimized for 'edit-in-place.' (the Rails scaffolds still generate views that make you flip between pages to do create/update operations)
33
- 2. Hot Glue does not create your models along with your scaffolding. Instead, create them first using `rails model new`
34
- 3. Hot Glue *reads* the fields on your database and the relationships defined on your models, so unlike the Rails scaffolding you must do that step before building your scaffolding.
35
- 4. Hot Glue has many more features for building layouts quickly, like choosing which fields to include or exclude and how to lay them out on the page, for stiching together related objects (nesting and child portals), and more.
32
+ 1. The Hot Glue scaffolds are complete packages and pre-optimized for 'edit-in-place.' (the Rails scaffolds still generates views that make you flip between pages to do create/update operations)
33
+ 2. Hot Glue does not create your models along with your scaffolding. Instead, create them first using `rails generate model X`
34
+ 3. Hot Glue *reads* the fields on your database *and* the relationships defined on your models. Unlike the Rails scaffolding you must add relationships and migration your DB before building your scaffolding.
35
+ 4. Hot Glue has many more features for building layouts quickly, like choosing which fields to include or exclude and how to lay them out on the page, for stitching together related objects (nesting and child portals), and more.
36
36
 
37
37
  Other than the opinionated differences and additional features, Hot Glue produces code that is fundamentally very similiar and works consistent with the Rails 7 ways of working.
38
38
 
@@ -138,7 +138,7 @@ sed -i '' -e 's/, html: { method: :post })/, html: { method: :post, "data-turbo"
138
138
  git add . && git commit -m 'devise view fixes' &&
139
139
  rails generate model User name:string &&
140
140
  rails generate devise User && git add . && git commit -m "adds Users model with devise" &&
141
- rails db:migrate &&
141
+ && ./bin/setup && rails db:migrate &&
142
142
  git add . && git commit -m "schema file"
143
143
  ```
144
144
 
@@ -905,6 +905,33 @@ Child portals have the headings omitted automatically (there is a heading identi
905
905
 
906
906
  # VERSION HISTORY
907
907
 
908
+ #### 2022-12-27 - v0.5.5
909
+
910
+ - Experimental support for Tailwind. Note I was not able to get Tailwind actually working in my app, and I'm not sure about how to think about the many flavors of Tailwind (all of which seem to be paid?). If anyone can lend a hand, the objects are now cleanly refactored so that the CSS logic is separated.
911
+
912
+ - Support for UUIDs. Database UUIDs are treated as foreign keys and behave like integers ending with _id (they are treated as foreign keys whether or not they end with _id where as integers are treated as foreign keys only if they end with _id)
913
+
914
+ - At the namespace level, you can now have a file called `_nav.html.erb` like this example for a two-tab bootstrap nav (you'll need to create this file manually).
915
+ - Here, our two tabs are called "Domains" and "Widgets"
916
+
917
+ ```
918
+ <ul class="nav nav-tabs">
919
+ <li class="nav-item">
920
+ <%= link_to "Domains", domains_path, class: "nav-link #{'active' if nav == 'domains'}" %>
921
+ </li>
922
+ <li class="nav-item">
923
+ <%= link_to "Widgets", widgets_path, class: "nav-link #{'active' if nav == 'widget'}" %>
924
+ </li>
925
+ </ul>
926
+ ```
927
+
928
+ If the file is present, Hot Glue will automatically add this to the top of, for example, the "domains" index page:
929
+
930
+ ```
931
+ <%= render partial: "owner/nav", locals: {nav: "domains"} %>
932
+ ```
933
+ Use this to build a Bootstrap nav that correctly turns each tab active when navigated to.
934
+
908
935
  #### 2022-11-27 - v0.5.4 - new flag --with-turbo-streams will append callbacks after_update_commit and after_destroy_commit to the MODEL you are building with to use turbo to target the scaffolding being built and programmatically update it
909
936
 
910
937
  Adds `--with-turbo-streams`. Use `--with-turbo-streams` to create hot (live reload) interfaces. See docs above.
@@ -1,5 +1,5 @@
1
1
  require 'rails/generators/erb/scaffold/scaffold_generator'
2
- require_relative './helpers'
2
+
3
3
  require 'ffaker'
4
4
 
5
5
  module HotGlue
@@ -15,15 +15,15 @@ module HotGlue
15
15
 
16
16
  def initialize(*args) #:nodoc:
17
17
  super
18
- @layout = options['layout'] || "hotglue"
18
+ layout = options['layout'] || "hotglue"
19
19
  @theme = options['theme']
20
- if @layout == "hotglue" && options['theme'].nil?
20
+ if layout == "hotglue" && options['theme'].nil?
21
21
  puts "You have selected to install Hot Glue without a theme. You can either use the --layout=bootstrap to install NO HOT GLUE THEME, or to use a Hot Glue theme please choose: like_boostrap, like_menlo_park, like_cupertino, like_mountain_view, dark_knight"
22
22
  return
23
23
  end
24
24
 
25
- if @layout == 'boostrap'
26
- puts "IMPORTANT: You have selected to install Hot Glue with Bootstrap layout (legacy). Be sure to always use ``--layout=bootstrap` when building your scaffold. No Hot Glue theme will be installed at this time.` "
25
+ if layout == 'boostrap'
26
+ puts "IMPORTANT: You have selected to install Hot Glue with Bootstrap layout.` "
27
27
  end
28
28
 
29
29
 
@@ -56,7 +56,7 @@ module HotGlue
56
56
 
57
57
 
58
58
  begin
59
- rails_helper_contents = File.read("spec/rails_helper.rb")
59
+ rails_helper_contents = File.read("#{'spec/dummy/' if Rails.env.test?}spec/rails_helper.rb")
60
60
  if !rails_helper_contents.include?("Capybara.default_driver =")
61
61
  rails_helper_contents << "\nCapybara.default_driver = :selenium_chrome_headless "
62
62
  puts " HOTGLUE --> added to spec/rails_helper.rb: `Capybara.default_driver = :selenium_chrome_headless` "
@@ -66,14 +66,14 @@ module HotGlue
66
66
  rails_helper_contents.gsub!("RSpec.configure do |config|", "RSpec.configure do |config| \n
67
67
  config.include FactoryBot::Syntax::Methods
68
68
  ")
69
- puts " HOTGLUE --> added to spec/rails_helper.rb: `config.include FactoryBot::Syntax::Methods` "
69
+ puts " HOTGLUE --> added to #{'spec/dummy/' if Rails.env.test?}spec/rails_helper.rb: `config.include FactoryBot::Syntax::Methods` "
70
70
  end
71
71
 
72
72
  if ! rails_helper_contents.include?("require 'support/capybara_login.rb'")
73
73
  rails_helper_contents.gsub!("require 'rspec/rails'","require 'rspec/rails' \nrequire 'support/capybara_login.rb'")
74
74
  puts " HOTGLUE --> added to spec/rails_helper.rb: `require 'support/capybara_login.rb'` "
75
75
  end
76
- File.write("spec/rails_helper.rb", rails_helper_contents)
76
+ File.write("#{'spec/dummy/' if Rails.env.test?}spec/rails_helper.rb", rails_helper_contents)
77
77
 
78
78
  rescue StandardError => e
79
79
  puts "WARNING: error writing to spec/rails_helper --- #{e.message}"
@@ -96,7 +96,7 @@ module HotGlue
96
96
 
97
97
 
98
98
  begin
99
- if @layout == "hotglue"
99
+ if layout == "hotglue"
100
100
  theme_location = "themes/hotglue_scaffold_#{@theme}.scss"
101
101
  theme_file = "hotglue_scaffold_#{@theme}.scss"
102
102
 
@@ -119,8 +119,8 @@ module HotGlue
119
119
 
120
120
 
121
121
  begin
122
- if !File.exists?("config/hot_glue.yml")
123
- yaml = {layout: @layout,
122
+ if !File.exists?("#{'spec/dummy/' if Rails.env.test?}config/hot_glue.yml")
123
+ yaml = {layout: layout,
124
124
  markup: @markup}.to_yaml
125
125
  File.write("#{'spec/dummy/' if Rails.env.test?}config/hot_glue.yml", yaml)
126
126
 
@@ -131,11 +131,11 @@ module HotGlue
131
131
 
132
132
 
133
133
  begin
134
- if !File.exists?("spec/support/capybara_login.rb")
134
+ if !File.exists?("#{'spec/dummy/' if Rails.env.test?}spec/support/capybara_login.rb")
135
135
  copy_file "capybara_login.rb", "#{'spec/dummy/' if Rails.env.test?}spec/support/capybara_login.rb"
136
136
  end
137
137
  rescue StandardError => e
138
- puts "WARNING: error writing to spec/support/capybara_login.rb --- #{e.message}"
138
+ puts "WARNING: error writing to #{Rails.env.test? ? 'spec/dummmy/' : ''}spec/support/capybara_login.rb --- #{e.message}"
139
139
  end
140
140
  end
141
141
  end
@@ -8,15 +8,18 @@ module HotGlue
8
8
  :buttons_width, :columns,
9
9
  :smart_layout, :specified_grouping_mode
10
10
 
11
- def initialize(params)
12
- @include_setting = params[:include_setting]
13
- @downnest_object = params[:downnest_object]
14
-
15
- @buttons_width = params[:buttons_width]
11
+ def initialize(include_setting: nil,
12
+ downnest_object: nil,
13
+ buttons_width: nil,
14
+ smart_layout: nil,
15
+ columns: nil)
16
+ @include_setting = include_setting
17
+ @downnest_object = downnest_object
18
+ @buttons_width = buttons_width
19
+ @columns = columns
20
+ @smart_layout = smart_layout
16
21
 
17
22
  @no_buttons = @buttons_width == 0
18
- @columns = params[:columns]
19
- @smart_layout = params[:smart_layout]
20
23
  @specified_grouping_mode = include_setting.include?(":")
21
24
  end
22
25
 
@@ -132,4 +135,4 @@ module HotGlue
132
135
 
133
136
  end
134
137
  end
135
- end
138
+ end
@@ -0,0 +1,31 @@
1
+ module LayoutStrategy
2
+ class Base
3
+ attr_accessor :builder
4
+ def initialize(scaffold_builder)
5
+ @builder = scaffold_builder
6
+ end
7
+
8
+ def button_classes; ""; end
9
+ def button_column_style; "" ; end
10
+ def button_style ; ""; end
11
+ def column_headings_col_style; "" ; end
12
+ def column_width; ""; end
13
+ def column_classes_for_line_fields; ""; end
14
+ def column_classes_for_form_fields; ""; end
15
+ def column_classes_for_column_headings; ""; end
16
+ def col_width; 100; end
17
+ def container_name; ""; end
18
+ def downnest_style ; ""; end
19
+ def downnest_column_style ; "" ; end
20
+ def each_col
21
+ return col_width if builder.columns.count == 0
22
+ (col_width/(builder.columns.count)).to_i
23
+ end
24
+ def list_classes; ""; end
25
+ def row_classes; ""; end
26
+ def row_heading_classes; ""; end
27
+ def page_begin; '<div> '; end
28
+ def page_end ; '</div> '; end
29
+ def style_with_flex_basis(x); "" ; end
30
+ end
31
+ end
@@ -0,0 +1,41 @@
1
+ class LayoutStrategy::Bootstrap < LayoutStrategy::Base
2
+ def button_classes
3
+ " " + column_classes_for_line_fields
4
+ end
5
+
6
+ def column_classes_for_form_fields
7
+ "col-md-#{builder.layout_object[:columns][:size_each]}"
8
+ end
9
+
10
+ def column_classes_for_column_headings
11
+ column_classes_for_line_fields
12
+ end
13
+
14
+ def container_name
15
+ "container-fluid"
16
+ end
17
+
18
+ def column_classes_for_line_fields
19
+ "col-sm-#{builder.layout_object[:columns][:size_each]}"
20
+ end
21
+
22
+ def column_width
23
+ builder.layout_object[:columns][:size_each]
24
+ end
25
+
26
+ def downnest_portal_column_width(downnest)
27
+ "col-sm-#{ builder.layout_object[:portals][downnest][:size] }"
28
+ end
29
+
30
+ def page_begin
31
+ '<div class="row"> <div class="col-md-12">'
32
+ end
33
+
34
+ def row_classes
35
+ "row"
36
+ end
37
+
38
+ def page_end
39
+ '</div> </div>'
40
+ end
41
+ end
@@ -0,0 +1,82 @@
1
+ class LayoutStrategy::HotGlue < LayoutStrategy::Base
2
+ def button_column_style
3
+ 'style="flex-basis: 150px'
4
+ end
5
+
6
+ def button_style
7
+ 'style="flex-basis: ' + (100 - (column_width * builder.columns.count)).floor.to_s + '%;"'
8
+ end
9
+
10
+ def column_width
11
+ each_col * builder.columns.count
12
+ end
13
+
14
+ def column_headings_col_style
15
+ " style='flex-basis: #{column_width}%'"
16
+ end
17
+
18
+ def container_name
19
+ "scaffold-container"
20
+ end
21
+
22
+ def downnest_column_style
23
+ 'style="flex-basis: ' + each_downnest_width.to_s + '%;'
24
+ end
25
+
26
+ def downnest_style
27
+ 'style="flex-basis: ' + each_downnest_width.to_s + '%"'
28
+ end
29
+
30
+ def each_downnest_width
31
+ builder.downnest_children.count == 1 ? 33 : (53/builder.downnest_children.count).floor
32
+ end
33
+
34
+ def list_classes
35
+ "scaffold-list"
36
+ end
37
+
38
+ def row_classes
39
+ "scaffold-row"
40
+ end
41
+
42
+ def column_classes_for_form_fields
43
+ "scaffold-cell"
44
+ end
45
+
46
+ def row_heading_classes
47
+ "scaffold-heading-row"
48
+ end
49
+ def column_classes_for_line_fields
50
+ "scaffold-cell"
51
+ end
52
+
53
+ def column_classes_for_column_headings
54
+ "scaffold-cell"
55
+ end
56
+
57
+ def col_width
58
+ downnest_size = case (builder.downnest_children.count)
59
+ when 0
60
+ downnest_size = 0
61
+ when 1
62
+ downnest_size = 40
63
+
64
+ else
65
+ downnest_size = 60
66
+
67
+ end
68
+ 100 - downnest_size - 5
69
+ end
70
+
71
+ def page_begin
72
+ '<div class=" scaffold-index-<%= plural %>">'
73
+ end
74
+
75
+ def page_end
76
+ '</div>'
77
+ end
78
+
79
+ def style_with_flex_basis(perc_width)
80
+ " style='flex-basis: #{perc_width}%'"
81
+ end
82
+ end
@@ -0,0 +1,28 @@
1
+
2
+
3
+ class LayoutStrategy::Tailwind < LayoutStrategy::Base
4
+ def button_classes; ""; end
5
+ def button_column_style; "" ; end
6
+ def button_style ; ""; end
7
+ def column_headings_col_style; "" ; end
8
+ def column_width; ""; end
9
+ def column_classes_for_line_fields; ""; end
10
+ def column_classes_for_form_fields; ""; end
11
+ def column_classes_for_column_headings; ""; end
12
+ def col_width; 100; end
13
+ def container_name; ""; end
14
+ def downnest_style ; ""; end
15
+ def downnest_column_style ; "" ; end
16
+ def each_col
17
+ return col_width if builder.columns.count == 0
18
+ (col_width/(builder.columns.count)).to_i
19
+ end
20
+
21
+ def list_classes; "overflow-x-auto w-full"; end
22
+ def row_classes; "grid grid-cols-4 gap-x-16 py-5 px-4 text-sm text-gray-700 border-b border-gray-200 dark:border-gray-700"; end
23
+ def row_heading_classes; "grid grid-cols-4 gap-x-16 p-4 text-sm font-medium text-gray-900 bg-gray-100 border-t border-b border-gray-200 dark:bg-gray-800 dark:border-gray-700 dark:text-white"; end
24
+ def page_begin; '<div class="overflow-hidden min-w-max"> '; end
25
+ def page_end ; '</div> '; end
26
+ def style_with_flex_basis(x); "" ; end
27
+
28
+ end
@@ -1,7 +1,7 @@
1
1
  module HotGlue
2
2
  class TemplateBase
3
- def initialize()
3
+ def initialize(layout_strategy: )
4
+ @layout_strategy = layout_strategy
4
5
  end
5
-
6
6
  end
7
- end
7
+ end
@@ -3,7 +3,7 @@ module HotGlue
3
3
 
4
4
  attr_accessor :path, :singular, :singular_class,
5
5
  :magic_buttons, :small_buttons,
6
- :show_only, :column_width, :layout, :perc_width,
6
+ :show_only, :column_width, :layout_strategy, :perc_width,
7
7
  :ownership_field, :form_labels_position,
8
8
  :inline_list_labels,
9
9
  :columns, :column_width, :col_identifier, :singular,
@@ -16,14 +16,7 @@ module HotGlue
16
16
  text.lines.collect{|line| add_spaces + line}.join("")
17
17
  end
18
18
 
19
- def magic_button_output(*args)
20
- path = args[0][:path]
21
- # path_helper_singular = args[0][:path_helper_singular]
22
- # path_helper_args = args[0][:path_helper_args]
23
- singular = args[0][:singular]
24
- magic_buttons = args[0][:magic_buttons]
25
- small_buttons = args[0][:small_buttons]
26
-
19
+ def magic_button_output(path:, singular:, magic_buttons:, small_buttons: )
27
20
  magic_buttons.collect{ |button_name|
28
21
  "<%= form_with model: #{singular}, url: #{path}, html: {style: 'display: inline', data: {\"turbo-confirm\": 'Are you sure you want to #{button_name} this #{singular}?'}} do |f| %>
29
22
  <%= f.hidden_field :#{button_name}, value: \"#{button_name}\" %>
@@ -36,13 +29,8 @@ module HotGlue
36
29
  @columns = args[0][:columns]
37
30
  @column_width = args[0][:column_width]
38
31
  @col_identifier = args[0][:col_identifier]
39
- @layout = args[0][:layout]
40
32
 
41
- if layout == "hotglue"
42
- col_style = " style='flex-basis: #{column_width}%'"
43
- else
44
- col_style = ""
45
- end
33
+ col_style = @layout_strategy.column_headings_col_style
46
34
 
47
35
  result = columns.map{ |column|
48
36
  "<div class='#{col_identifier}'" + col_style + ">" + column.map(&:to_s).map{|col_name| "#{col_name.humanize}"}.join("<br />") + "</div>"
@@ -59,16 +47,17 @@ module HotGlue
59
47
  @columns = args[0][:columns]
60
48
  @show_only = args[0][:show_only]
61
49
  @singular_class = args[0][:singular_class]
62
- @col_identifier = args[0][:col_identifier]
63
50
  @ownership_field = args[0][:ownership_field]
64
51
  @form_labels_position = args[0][:form_labels_position]
65
52
  @form_placeholder_labels = args[0][:form_placeholder_labels]
66
53
  @hawk_keys = args[0][:hawk_keys]
67
-
68
54
  @singular = args[0][:singular]
55
+
56
+ column_classes = args[0][:col_identifier]
57
+
69
58
  singular = @singular
70
59
  result = columns.map{ |column|
71
- " <div class='#{col_identifier}' >" +
60
+ " <div class='#{column_classes}' >" +
72
61
  column.map { |col|
73
62
  field_result =
74
63
  if show_only.include?(col.to_sym)
@@ -81,12 +70,14 @@ module HotGlue
81
70
  case type
82
71
  when :integer
83
72
  integer_result(col)
73
+ when :uuid
74
+ uuid_result(col)
84
75
  when :string
85
76
  string_result(col, sql_type, limit)
86
77
  when :text
87
78
  text_result(col, sql_type, limit)
88
79
  when :float
89
- field_output(col, nil, 5, col_identifier)
80
+ field_output(col, nil, 5, column_classes)
90
81
  when :datetime
91
82
  "<%= datetime_field_localized(f, :#{col}, #{singular}.#{col}, '#{ col.to_s.humanize }', #{@auth ? @auth+'.timezone' : 'nil'}) %>"
92
83
  when :date
@@ -122,36 +113,46 @@ module HotGlue
122
113
  def integer_result(col)
123
114
  # look for a belongs_to on this object
124
115
  if col.to_s.ends_with?("_id")
125
- assoc_name = col.to_s.gsub("_id","")
126
- assoc = eval("#{singular_class}.reflect_on_association(:#{assoc_name})")
127
- if assoc.nil?
128
- exit_message = "*** Oops. on the #{singular_class} object, there doesn't seem to be an association called '#{assoc_name}'"
129
- exit
130
- end
131
-
132
- is_owner = col == ownership_field
133
- assoc_class_name = assoc.active_record.name
134
- display_column = HotGlue.derrive_reference_name(assoc_class_name)
135
-
136
- if @hawk_keys[assoc.foreign_key.to_sym]
137
- hawk_definition = @hawk_keys[assoc.foreign_key.to_sym]
138
- hawk_root = hawk_definition[0]
139
- hawk_scope = hawk_definition[1]
140
- hawked_association = "#{hawk_root}.#{hawk_scope}"
141
- else
142
- hawked_association = "#{assoc.class_name}.all"
143
- end
144
-
145
- (is_owner ? "<% unless @#{assoc_name} %>\n" : "") +
146
- " <%= f.collection_select(:#{col}, #{hawked_association}, :id, :#{display_column}, {prompt: true, selected: @#{singular}.#{col} }, class: 'form-control') %>\n" +
147
- (is_owner ? "<% else %>\n <%= @#{assoc_name}.#{display_column} %>" : "") +
148
- (is_owner ? "\n<% end %>" : "")
149
-
116
+ association_result(col)
150
117
  else
151
118
  " <%= f.text_field :#{col}, value: #{@singular}.#{col}, autocomplete: 'off', size: 4, class: 'form-control', type: 'number'" + (@form_placeholder_labels ? ", placeholder: '#{col.to_s.humanize}'" : "") + " %>\n " + "\n"
152
119
  end
153
120
  end
154
121
 
122
+
123
+ def uuid_result(col)
124
+ association_result(col)
125
+ end
126
+
127
+
128
+ def association_result(col)
129
+ assoc_name = col.to_s.gsub("_id","")
130
+ assoc = eval("#{singular_class}.reflect_on_association(:#{assoc_name})")
131
+ if assoc.nil?
132
+ exit_message = "*** Oops. on the #{singular_class} object, there doesn't seem to be an association called '#{assoc_name}'"
133
+ exit
134
+ end
135
+
136
+ is_owner = col == ownership_field
137
+ assoc_class_name = assoc.active_record.name
138
+ display_column = HotGlue.derrive_reference_name(assoc_class_name)
139
+
140
+ if @hawk_keys[assoc.foreign_key.to_sym]
141
+ hawk_definition = @hawk_keys[assoc.foreign_key.to_sym]
142
+ hawk_root = hawk_definition[0]
143
+ hawk_scope = hawk_definition[1]
144
+ hawked_association = "#{hawk_root}.#{hawk_scope}"
145
+ else
146
+ hawked_association = "#{assoc.class_name}.all"
147
+ end
148
+
149
+ (is_owner ? "<% unless @#{assoc_name} %>\n" : "") +
150
+ " <%= f.collection_select(:#{col}, #{hawked_association}, :id, :#{display_column}, {prompt: true, selected: @#{singular}.#{col} }, class: 'form-control') %>\n" +
151
+ (is_owner ? "<% else %>\n <%= @#{assoc_name}.#{display_column} %>" : "") +
152
+ (is_owner ? "\n<% end %>" : "")
153
+
154
+ end
155
+
155
156
  def string_result(col, sql_type, limit)
156
157
  if sql_type == "varchar" || sql_type == "character varying"
157
158
  field_output(col, nil, limit || 40, col_identifier)
@@ -216,18 +217,14 @@ module HotGlue
216
217
  @singular_class = args[0][:singular_class]
217
218
  @singular = args[0][:singular]
218
219
  @perc_width = args[0][:perc_width]
219
- @layout = args[0][:layout]
220
- @col_identifier = args[0][:col_identifier] || (layout == "bootstrap" ? "col-md-2" : "scaffold-cell")
220
+ @col_identifier = @layout_strategy.column_classes_for_line_fields
221
+
221
222
  @inline_list_labels = args[0][:inline_list_labels] || 'omit'
222
223
 
223
224
  columns_count = columns.count + 1
224
225
  perc_width = (@perc_width).floor
225
226
 
226
- if layout == "bootstrap"
227
- style_with_flex_basis = ""
228
- else
229
- style_with_flex_basis = " style='flex-basis: #{perc_width}%'"
230
- end
227
+ style_with_flex_basis = @layout_strategy.style_with_flex_basis(perc_width)
231
228
 
232
229
  result = columns.map{ |column|
233
230
  "<div class='#{col_identifier}'#{style_with_flex_basis}>" +
@@ -238,14 +235,30 @@ module HotGlue
238
235
  limit = eval("#{singular_class}.columns_hash['#{col}']").limit
239
236
  sql_type = eval("#{singular_class}.columns_hash['#{col}']").sql_type
240
237
 
241
- field_output = case type
242
- when :integer
243
- # look for a belongs_to on this object
244
- if col.ends_with?("_id")
238
+ field_output =
239
+ case type
240
+ when :integer
241
+ # look for a belongs_to on this object
242
+ if col.ends_with?("_id")
243
+ assoc_name = col.to_s.gsub("_id","")
244
+ assoc = eval("#{singular_class}.reflect_on_association(:#{assoc_name})")
245
+
246
+ if assoc.nil?
247
+ exit_message = "*** Oops. on the #{singular_class} object, there doesn't seem to be an association called '#{assoc_name}'"
248
+ puts exit_message
249
+ exit
250
+ # raise(HotGlue::Error,exit_message)
251
+ end
252
+ assoc_class_name = assoc.active_record.name
253
+ display_column = HotGlue.derrive_reference_name(assoc_class_name)
254
+ "<%= #{singular}.#{assoc.name.to_s}.try(:#{display_column}) || '<span class=\"content alert-danger\">MISSING</span>'.html_safe %>"
255
+
256
+ else
257
+ "<%= #{singular}.#{col}%>"
258
+ end
245
259
 
260
+ when :uuid
246
261
  assoc_name = col.to_s.gsub("_id","")
247
-
248
-
249
262
  assoc = eval("#{singular_class}.reflect_on_association(:#{assoc_name})")
250
263
 
251
264
  if assoc.nil?
@@ -258,37 +271,34 @@ module HotGlue
258
271
  display_column = HotGlue.derrive_reference_name(assoc_class_name)
259
272
  "<%= #{singular}.#{assoc.name.to_s}.try(:#{display_column}) || '<span class=\"content alert-danger\">MISSING</span>'.html_safe %>"
260
273
 
261
- else
274
+ when :float
275
+ width = (limit && limit < 40) ? limit : (40)
262
276
  "<%= #{singular}.#{col}%>"
263
- end
264
- when :float
265
- width = (limit && limit < 40) ? limit : (40)
266
- "<%= #{singular}.#{col}%>"
267
- when :string
268
- width = (limit && limit < 40) ? limit : (40)
269
- "<%= #{singular}.#{col} %>"
270
- when :text
271
- "<%= #{singular}.#{col} %>"
272
- when :datetime
273
- "<% unless #{singular}.#{col}.nil? %>
277
+ when :string
278
+ width = (limit && limit < 40) ? limit : (40)
279
+ "<%= #{singular}.#{col} %>"
280
+ when :text
281
+ "<%= #{singular}.#{col} %>"
282
+ when :datetime
283
+ "<% unless #{singular}.#{col}.nil? %>
274
284
  <%= #{singular}.#{col}.in_time_zone(current_timezone).strftime('%m/%d/%Y @ %l:%M %p ') + timezonize(current_timezone) %>
275
285
  <% else %>
276
286
  <span class='alert-danger'>MISSING</span>
277
287
  <% end %>"
278
- when :date
279
- "<% unless #{singular}.#{col}.nil? %>
288
+ when :date
289
+ "<% unless #{singular}.#{col}.nil? %>
280
290
  <%= #{singular}.#{col} %>
281
291
  <% else %>
282
292
  <span class='alert-danger'>MISSING</span>
283
293
  <% end %>"
284
- when :time
285
- "<% unless #{singular}.#{col}.nil? %>
294
+ when :time
295
+ "<% unless #{singular}.#{col}.nil? %>
286
296
  <%= #{singular}.#{col}.in_time_zone(current_timezone).strftime('%l:%M %p ') + timezonize(current_timezone) %>
287
297
  <% else %>
288
298
  <span class='alert-danger'>MISSING</span>
289
299
  <% end %>"
290
- when :boolean
291
- "
300
+ when :boolean
301
+ "
292
302
  <% if #{singular}.#{col}.nil? %>
293
303
  <span class='alert-danger'>MISSING</span>
294
304
  <% elsif #{singular}.#{col} %>
@@ -297,8 +307,9 @@ module HotGlue
297
307
  NO
298
308
  <% end %>
299
309
 
300
- " when :enum
301
- enum_type = eval("#{singular_class}.columns.select{|x| x.name == '#{col}'}[0].sql_type")
310
+ "
311
+ when :enum
312
+ enum_type = eval("#{singular_class}.columns.select{|x| x.name == '#{col}'}[0].sql_type")
302
313
 
303
314
  "
304
315
  <% if #{singular}.#{col}.nil? %>
@@ -308,8 +319,7 @@ module HotGlue
308
319
  <% end %>
309
320
 
310
321
  "
311
- end #end of switch
312
-
322
+ end #end of switch
313
323
 
314
324
  label = "<br/><label class='small form-text text-muted'>#{col.to_s.humanize}</label>"
315
325
 
@@ -319,4 +329,4 @@ module HotGlue
319
329
  }.join("\n")
320
330
  end
321
331
  end
322
- end
332
+ end
@@ -7,11 +7,18 @@ require_relative './markup_templates/erb'
7
7
  # require_relative './markup_templates/slim'
8
8
 
9
9
  require_relative './layout/builder'
10
+ require_relative './layout_strategy/base'
11
+ require_relative './layout_strategy/bootstrap'
12
+ require_relative './layout_strategy/hot_glue'
13
+ require_relative './layout_strategy/tailwind'
14
+
10
15
 
11
16
  module HotGlue
12
17
  class Error < StandardError
13
18
  end
14
19
 
20
+
21
+
15
22
  def self.construct_downnest_object(input)
16
23
  res = input.split(",").map { |child|
17
24
  child_name = child.gsub("+","")
@@ -21,18 +28,14 @@ module HotGlue
21
28
  Hash[*res.collect{|hash| hash.collect{|key,value| [key,value].flatten}.flatten}.flatten]
22
29
  end
23
30
 
24
- def self.optionalized_ternary(params)
25
- namespace = params[:namespace] || nil
26
- target = params[:target]
27
- nested_set = params[:nested_set]
28
- modifier = params[:modifier] || ""
29
- with_params = params[:with_params] || false
30
- top_level = params[:top_level] || false
31
-
31
+ def self.optionalized_ternary(namespace: nil,
32
+ target:,
33
+ nested_set:,
34
+ modifier: "",
35
+ with_params: false,
36
+ top_level: false,
37
+ put_form: false)
32
38
  instance_sym = top_level ? "@" : ""
33
-
34
- put_form = params[:put_form] || false
35
-
36
39
  if nested_set.nil? || nested_set.empty?
37
40
  return modifier + "#{(namespace + '_') if namespace}#{target}_path" + (("(#{instance_sym}#{target})" if put_form) || "")
38
41
  elsif nested_set[0][:optional] == false
@@ -50,17 +53,23 @@ module HotGlue
50
53
  nonoptional[:optional] = false
51
54
  rest_of_nest = nested_set[1..-1]
52
55
 
53
- all_params = {namespace: namespace,
54
- target: target,
55
- modifier: modifier,
56
- top_level: top_level,
57
- with_params: with_params,
58
- put_form: put_form}
59
- is_present_path = HotGlue.optionalized_ternary(all_params.merge({ nested_set: [nonoptional, *rest_of_nest]}) )
60
-
61
- is_missing_path = HotGlue.optionalized_ternary(all_params.merge({ nested_set: rest_of_nest}) )
62
-
63
-
56
+ is_present_path = HotGlue.optionalized_ternary(
57
+ namespace: namespace,
58
+ target: target,
59
+ modifier: modifier,
60
+ top_level: top_level,
61
+ with_params: with_params,
62
+ put_form: put_form,
63
+ nested_set: [nonoptional, *rest_of_nest])
64
+
65
+ is_missing_path = HotGlue.optionalized_ternary(
66
+ namespace: namespace,
67
+ target: target,
68
+ modifier: modifier,
69
+ top_level: top_level,
70
+ with_params: with_params,
71
+ put_form: put_form,
72
+ nested_set: rest_of_nest )
64
73
  return "defined?(#{instance_sym + nested_set[0][:singular]}) ? #{is_present_path} : #{is_missing_path}"
65
74
  end
66
75
  end
@@ -78,8 +87,6 @@ module HotGlue
78
87
  display_column = "display_name"
79
88
  elsif assoc_class.new.respond_to?("email")
80
89
  display_column = "email"
81
- # else # SHOULD BE UNREACHABLE
82
- # raise("this should have been caught by the checker in the initializer")
83
90
  end
84
91
  display_column
85
92
  end
@@ -89,6 +96,7 @@ module HotGlue
89
96
 
90
97
  source_root File.expand_path('templates', __dir__)
91
98
  attr_accessor :path, :singular, :plural, :singular_class, :nest_with
99
+ attr_accessor :columns, :downnest_children, :layout_object
92
100
 
93
101
  class_option :singular, type: :string, default: nil
94
102
  class_option :plural, type: :string, default: nil
@@ -150,6 +158,7 @@ module HotGlue
150
158
  raise(HotGlue::Error, message)
151
159
  end
152
160
 
161
+ @meta_args = meta_args
153
162
 
154
163
  if options['specs_only'] && options['no_specs']
155
164
  raise(HotGlue::Error, "*** Oops: You seem to have specified both the --specs-only flag and --no-specs flags. this doesn't make any sense, so I am aborting. Aborting.")
@@ -180,32 +189,38 @@ module HotGlue
180
189
  yaml_from_config = YAML.load(File.read("config/hot_glue.yml"))
181
190
  @markup = yaml_from_config[:markup]
182
191
 
183
- if @markup == "erb"
184
- @template_builder = HotGlue::ErbTemplate.new
185
- elsif @markup == "slim"
186
- raise(HotGlue::Error, "SLIM IS NOT IMPLEMENTED")
187
- elsif @markup == "haml"
188
- raise(HotGlue::Error, "HAML IS NOT IMPLEMENTED")
192
+ if options['layout']
193
+ layout = options['layout']
194
+ else
195
+ layout = yaml_from_config[:layout]
189
196
 
197
+ if !['hotglue', 'bootstrap', 'tailwind'].include? layout
198
+ raise "Invalid option #{layout} in Hot glue config (config/hot_glue.yml). You must either use --layout= when generating or have a file config/hotglue.yml; specify layout as either 'hotglue' or 'bootstrap'"
199
+ end
190
200
  end
191
201
 
202
+ @layout_strategy =
203
+ case layout
204
+ when 'bootstrap'
205
+ LayoutStrategy::Bootstrap.new(self)
206
+ when 'tailwind'
207
+ LayoutStrategy::Tailwind.new(self)
208
+ when 'hotglue'
209
+ LayoutStrategy::HotGlue.new(self)
210
+ end
192
211
 
193
- if !options['layout']
194
- @layout = yaml_from_config[:layout]
195
212
 
196
- if !['hotglue', 'bootstrap'].include? @layout
197
- raise "Invalid option #{@layout} in Hot glue config (config/hot_glue.yml). You must either use --layout= when generating or have a file config/hotglue.yml; specify layout as either 'hotglue' or 'bootstrap'"
198
- end
199
- else
200
- @layout = options['layout']
213
+ if @markup == "erb"
214
+ @template_builder = HotGlue::ErbTemplate.new(layout_strategy: @layout_strategy)
215
+ elsif @markup == "slim"
216
+ raise(HotGlue::Error, "SLIM IS NOT IMPLEMENTED")
217
+ elsif @markup == "haml"
218
+ raise(HotGlue::Error, "HAML IS NOT IMPLEMENTED")
201
219
  end
202
220
 
203
221
  args = meta_args[0]
204
-
205
-
206
222
  @singular = args.first.tableize.singularize # should be in form hello_world
207
223
 
208
-
209
224
  if @singular.include?("/")
210
225
  @singular = @singular.split("/").last
211
226
  end
@@ -292,8 +307,7 @@ module HotGlue
292
307
  raise HotGlue::Error, "You specified both --smart-layout and also specified grouping mode (there is a : character in your field include list); you must remove the colon(s) from your --include tag or remove the --smart-layout option"
293
308
  end
294
309
 
295
-
296
- @container_name = @layout == "hotglue" ? "scaffold-container" : "container-fluid"
310
+ @container_name = @layout_strategy.container_name
297
311
  @downnest = options['downnest'] || false
298
312
 
299
313
  @downnest_children = [] # TODO: defactor @downnest_children in favor of downnest_object
@@ -353,7 +367,6 @@ module HotGlue
353
367
  plural: arg.pluralize,
354
368
  optional: is_optional
355
369
  }
356
-
357
370
  }
358
371
  puts "NESTING: #{@nested_set}"
359
372
  end
@@ -361,7 +374,6 @@ module HotGlue
361
374
  # OBJECT OWNERSHIP & NESTING
362
375
  @reference_name = HotGlue.derrive_reference_name(singular_class)
363
376
  if @auth && @self_auth
364
- # byebug
365
377
  @object_owner_sym = @auth.gsub("current_", "").to_sym
366
378
  @object_owner_eval = @auth
367
379
  @object_owner_optional = false
@@ -369,18 +381,15 @@ module HotGlue
369
381
 
370
382
 
371
383
  elsif @auth && ! @self_auth && @nested_set.none? && !@auth.include?(".")
372
- # byebug
373
384
  @object_owner_sym = @auth.gsub("current_", "").to_sym
374
385
  @object_owner_eval = @auth
375
386
  @object_owner_optional = false
376
387
  @object_owner_name = @auth.gsub("current_", "").to_s
377
388
 
378
389
  elsif @auth && @auth.include?(".")
379
- # byebug
380
390
  @object_owner_sym = nil
381
391
  @object_owner_eval = @auth
382
392
  else
383
- # byebug
384
393
  if @nested_set.any?
385
394
  @object_owner_sym = @nested_set.last[:singular].to_sym
386
395
  @object_owner_eval = "@#{@nested_set.last[:singular]}"
@@ -405,13 +414,11 @@ module HotGlue
405
414
 
406
415
  buttons_width = ((!@no_edit && 1) || 0) + ((!@no_delete && 1) || 0) + @magic_buttons.count
407
416
 
408
- builder = HotGlue::Layout::Builder.new({
409
- include_setting: options['include'],
417
+ builder = HotGlue::Layout::Builder.new(include_setting: options['include'],
410
418
  downnest_object: @downnest_object,
411
419
  buttons_width: buttons_width,
412
420
  columns: @columns,
413
- smart_layout: @smart_layout
414
- })
421
+ smart_layout: @smart_layout )
415
422
  @layout_object = builder.construct
416
423
 
417
424
  @menu_file_exists = true if @nested_set.none? && File.exists?("#{Rails.root}/app/views/#{namespace_with_trailing_dash}_menu.#{@markup}")
@@ -447,7 +454,6 @@ module HotGlue
447
454
  if @object_owner_sym && ! @self_auth
448
455
  auth_assoc_field = auth_assoc + "_id" unless @god
449
456
  assoc = eval("#{singular_class}.reflect_on_association(:#{@object_owner_sym})")
450
- # byebug
451
457
  if assoc
452
458
  @ownership_field = assoc.name.to_s + "_id"
453
459
  elsif ! @nested_set.any?
@@ -586,19 +592,10 @@ module HotGlue
586
592
  end
587
593
 
588
594
  def list_column_headings
589
- if @layout == "bootstrap"
590
- column_width = @layout_object[:columns][:size_each]
591
- col_identifier = "col-md-#{column_width}"
592
- elsif @layout == "hotglue"
593
- column_width = each_col * @columns.count
594
- col_identifier = "scaffold-cell"
595
- end
596
-
597
595
  @template_builder.list_column_headings(
598
596
  columns: @layout_object[:columns][:container],
599
- col_identifier: col_identifier,
600
- layout: @layout,
601
- column_width: column_width
597
+ col_identifier: @layout_strategy.column_classes_for_column_headings,
598
+ column_width: @layout_strategy.column_width
602
599
  )
603
600
  end
604
601
 
@@ -619,6 +616,11 @@ module HotGlue
619
616
  }.join(", ")
620
617
  end
621
618
 
619
+
620
+ def regenerate_me_code
621
+ "rails generate hot_glue:scaffold #{ @meta_args[0][0] } #{@meta_args[1].join(" ")}"
622
+ end
623
+
622
624
  def object_parent_mapping_as_argument_for_specs
623
625
  if @nested_set.any?
624
626
  ", " + @nested_set.last[:singular] + ": " + @nested_set.last[:singular]
@@ -899,6 +901,15 @@ module HotGlue
899
901
  )
900
902
  end
901
903
 
904
+ def nav_template
905
+ "#{namespace_with_trailing_dash}nav"
906
+ end
907
+
908
+
909
+ def include_nav_template
910
+ File.exists?("#{Rails.root}/app/views/#{namespace_with_trailing_dash}_nav.html.#{@markup}")
911
+ end
912
+
902
913
  def copy_view_files
903
914
  return if @specs_only
904
915
  all_views.each do |view|
@@ -943,9 +954,10 @@ module HotGlue
943
954
 
944
955
  def append_model_callbacks
945
956
  # somehow the generator invokes this
957
+
946
958
  if options['with_turbo_streams'] == true
947
959
  dest_filename = cc_filename_with_extensions("#{singular_class.underscore}", "rb")
948
- dest_filepath = File.join("#{'dummy/' if Rails.env.test?}app/models", dest_filename)
960
+ dest_filepath = File.join("#{'spec/dummy/' if Rails.env.test?}app/models", dest_filename)
949
961
 
950
962
 
951
963
  puts "appending turbo callbacks to #{dest_filepath}"
@@ -1026,24 +1038,19 @@ module HotGlue
1026
1038
  end
1027
1039
 
1028
1040
  def all_form_fields
1029
- col_identifier = (@layout == "hotglue") ? "scaffold-cell" : "col-md-#{@layout_object[:columns][:size_each]}"
1030
-
1031
1041
  @template_builder.all_form_fields(
1032
1042
  columns: @layout_object[:columns][:container],
1033
1043
  show_only: @show_only,
1034
1044
  singular_class: singular_class,
1035
1045
  singular: singular,
1036
1046
  hawk_keys: @hawk_keys,
1037
- col_identifier: col_identifier,
1047
+ col_identifier: @layout_strategy.column_classes_for_form_fields,
1038
1048
  ownership_field: @ownership_field,
1039
1049
  form_labels_position: @form_labels_position,
1040
1050
  form_placeholder_labels: @form_placeholder_labels
1041
1051
  )
1042
1052
  end
1043
1053
 
1044
- def column_width
1045
- @each_col ||= each_col
1046
- end
1047
1054
 
1048
1055
  def list_label
1049
1056
  if(eval("#{class_name}.class_variable_defined?(:@@table_label_plural)"))
@@ -1061,39 +1068,15 @@ module HotGlue
1061
1068
  end
1062
1069
  end
1063
1070
 
1064
- def each_col
1065
- return col_width if @columns.count == 0
1066
- (col_width/(@columns.count)).to_i
1067
- end
1068
-
1069
- def col_width
1070
- downnest_size = case (@downnest_children.count)
1071
-
1072
- when 0
1073
- downnest_size = 0
1074
- when 1
1075
- downnest_size = 40
1076
-
1077
- else
1078
- downnest_size = 60
1079
-
1080
- end
1081
- 100 - downnest_size - 5
1082
- end
1083
-
1084
1071
  def all_line_fields
1085
- col_identifier = (@layout == "hotglue") ? "scaffold-cell" : "col-md-#{@layout_object[:columns][:size_each]}"
1086
-
1087
1072
  @template_builder.all_line_fields(
1088
- perc_width: column_width,
1073
+ perc_width: @layout_strategy.each_col, #undefined method `each_col'
1089
1074
  columns: @layout_object[:columns][:container],
1090
1075
  show_only: @show_only,
1091
1076
  singular_class: singular_class,
1092
1077
  singular: singular,
1093
- layout: @layout,
1094
- col_identifier: col_identifier,
1078
+ col_identifier: @layout_strategy.column_classes_for_line_fields,
1095
1079
  inline_list_labels: @inline_list_labels
1096
-
1097
1080
  )
1098
1081
  end
1099
1082
 
@@ -1152,15 +1135,6 @@ module HotGlue
1152
1135
  @template_builder.paginate(plural: plural)
1153
1136
  end
1154
1137
 
1155
- # def delete_confirmation_syntax
1156
- # if !@stimulus_syntax
1157
- # "{confirm: 'Are you sure?'}"
1158
- # else
1159
- # "{controller: 'confirmable', 'confirm-message': \"Are you sure you want to delete \#{ #{@singular}.#{ display_class } } \", 'action': 'confirmation#confirm'}"
1160
- # end
1161
- # end
1162
-
1163
-
1164
1138
  def controller_magic_button_update_actions
1165
1139
  @magic_buttons.collect{ |magic_button|
1166
1140
  " if #{singular}_params[:#{magic_button}]
@@ -1192,7 +1166,6 @@ module HotGlue
1192
1166
  end
1193
1167
  end
1194
1168
 
1195
-
1196
1169
  def n_plus_one_includes
1197
1170
  if @associations.any?
1198
1171
  ".includes(" + @associations.map{|x| ":#{x.to_s}"}.join(", ") + ")"
@@ -1236,6 +1209,3 @@ module HotGlue
1236
1209
  end
1237
1210
  end
1238
1211
  end
1239
-
1240
-
1241
-
@@ -1,4 +1,7 @@
1
1
  class <%= controller_class_name %> < <%= controller_descends_from %>
2
+ # regenerate this controller with
3
+ # <%= regenerate_me_code %>
4
+
2
5
  helper :hot_glue
3
6
  include HotGlue::ControllerHelper
4
7
 
@@ -1,7 +1,7 @@
1
1
  <div class="row">
2
2
  <%= all_form_fields %>
3
3
 
4
- <div class="<%= @layout == "hotglue" ? 'scaffold-cell' : 'col-md-2' %>">
4
+ <div class="<%= @layout_strategy.column_classes_for_form_fields %>">
5
5
  <\%= link_to "Cancel", <%= path_helper_plural %>, {class: "btn btn-secondary"} %><% if @no_field_form %>
6
6
  <\%= f.hidden_field "_________" %><% end %>
7
7
  <\%= f.submit "Save", class: "btn btn-primary pull-right" %>
@@ -1,6 +1,6 @@
1
1
  <% if @turbo_streams %><\%= turbo_stream_from <%= singular %> %>
2
2
  <% end %><\%= turbo_frame_tag "<%= @namespace %>__#{ dom_id(<%= singular %>) }" do %>
3
- <div class='row scaffold-row' data-id='<\%= <%= singular %>.id %>' data-edit='false'>
3
+ <div class='<%= @layout_strategy.row_classes %>' data-id='<\%= <%= singular %>.id %>' data-edit='false'>
4
4
  <\%= render partial: '<%= show_path_partial %>', locals: { <%= singular %>: <%= singular %> }<% @nested_set.each do |nest_arg| %>.merge(defined?(<%= nest_arg[:singular] %>) ? {<%= nest_arg[:singular] %>: <%= nest_arg[:singular] %>, nested_for: "<%= nest_arg[:singular] %>-#{<%= nest_arg[:singular] %>.id}"} : {})<% end %> %>
5
5
 
6
6
  </div>
@@ -1,5 +1,5 @@
1
1
  <\%= turbo_frame_tag "<%= @namespace %>__<%= plural %>-list" <%= nested_for_turbo_id_list_constructor %> do %>
2
- <div class="<%= @container_name %> scaffold-list">
2
+ <div class="<%= @container_name %> <%= @layout_strategy.list_classes %>">
3
3
  <% unless @no_list || @no_list_label || (@nested_set.any? && !@nested_set.collect{|x| x[:optional]}.any?) %>
4
4
  <% unless list_label.nil? %><h4>
5
5
  <%= list_label %>
@@ -10,14 +10,12 @@
10
10
 
11
11
  <% unless @no_list %>
12
12
  <% unless @no_list_heading %>
13
- <div class="row scaffold-heading-row">
13
+ <div class="<%= @layout_strategy.row_classes %> <%= @layout_strategy.row_heading_classes %>">
14
14
  <%= list_column_headings %>
15
15
  <% if @downnest_object.any? %>
16
- <%# each_downnest_width = @downnest_object.count == 1 ? 40 : (60/@downnest_object.count).floor %>
17
- <% downnest_column_style = @layout == "hotglue" ? 'style="flex-basis: ' + each_downnest_width.to_s + '%;' : "" %>
18
-
16
+ <%= @layout_strategy.downnest_column_style %>
19
17
  <% @downnest_object.each do |downnest,i| %>
20
- <div class=" scaffold-col-heading<%= " col-sm-#{ @layout_object[:portals][downnest][:size] }" if @layout=="bootstrap" %>" <%= downnest_column_style %>>
18
+ <div class=" scaffold-col-heading <%= @layout_strategy.downnest_portal_column_width(downnest) %> <%= @layout_strategy.downnest_column_style %>">
21
19
  <strong>
22
20
  <%= downnest.titleize %>
23
21
  </strong>
@@ -25,10 +23,7 @@
25
23
  <% end %>
26
24
  <% end %>
27
25
 
28
- <% button_column_style = @layout == "hotglue" ? 'style="flex-basis: 150px' : "" %>
29
-
30
- <div class=' scaffold-col-heading scaffold-col-heading-buttons<%= " col-md-#{ @layout_object[:buttons][:size] }" if @layout=="bootstrap" %>' <%= button_column_style %>>
31
-
26
+ <div class=' scaffold-col-heading scaffold-col-heading-buttons <%= @layout_strategy.column_classes_for_column_headings %>' <%= @layout_strategy.button_column_style %>>
32
27
  </div>
33
28
  </div>
34
29
  <% end %>
@@ -9,7 +9,7 @@
9
9
  <% if downnest_object.nil?; raise "no relationship for downnested portal `#{downnest}` found on `#{singular_class}`; please check relationship for has_many :#{downnest}"; end; %>
10
10
  <% downnest_class = downnest_object.class_name %>
11
11
  <% downnest_object_name = eval("#{downnest_class}.table_name") %>
12
- <% downnest_style = @layout == "hotglue" ? 'style="flex-basis: ' + each_downnest_width.to_s + '%"' : "" %>
12
+ <% downnest_style = @layout_strategy.downnest_style %>
13
13
  <div class="<%= " col-md-#{@layout_object[:portals][downnest][:size]}" if @layout == "bootstrap" %> scaffold-downnest" <%= downnest_style %> >
14
14
  <\%= render partial: "<%= namespace_with_trailing_dash %><%= downnest_object_name %>/list", locals: {
15
15
  <%= @singular %>: <%= @singular %>,
@@ -22,8 +22,8 @@
22
22
  <% end %>
23
23
  <% end %>
24
24
 
25
- <% button_style = @layout == "hotglue" ? 'style="flex-basis: ' + (100 - (column_width * @columns.count)).floor.to_s + '%;"' : "" %>
26
- <div class="<%= @col_identifier %> scaffold-line-buttons <%= " col-md-#{ @layout_object[:buttons][:size] }" if @layout == "bootstrap" %>" <%= button_style %>>
25
+ <%= @layout_strategy.button_style %>
26
+ <div class="<%= @col_identifier %> scaffold-line-buttons <%= @layout_strategy.button_classes %>" <%= @layout_strategy.button_style %>>
27
27
  <%= magic_button_output %>
28
28
 
29
29
  <% if destroy_action %>
@@ -1,14 +1,11 @@
1
1
  <% if @menu_file_exists %><\%= render partial: "<%= namespace_with_trailing_dash %>menu", locals: {active: '<%= plural %>'} %><% end %>
2
2
 
3
3
  <div class="<%= @container_name %>">
4
- <% if @layout == "bootstrap" %><div class="row"> <div class="col-md-12">
5
- <% else %>
6
- <div class=' scaffold-index-<%= plural %>'>
7
- <% end %>
4
+ <%= @layout_strategy.page_begin %>
5
+ <% if include_nav_template %><\%= render partial: "<%= nav_template %>", locals: {nav: "<%= @plural %>"} %><% end %>
8
6
 
9
- <div class="clearfix"></div>
10
7
  <\%= render partial: '<%= list_path_partial %>',
11
8
  locals: {<%= plural %>: @<%= plural %>}<%= @nested_set.collect{|arg| ".merge(@" + arg[:singular] + " ? {nested_for: \"" + arg[:singular] + "-\#{@" + arg[:singular] + ".id}\"" + ", " + arg[:singular] + ": @" + arg[:singular] + "} : {})"}.join() %> \%>
12
9
 
13
- <% if @layout == "bootstrap" %></div></div><% else %></div><% end %>
10
+ <%= @layout_strategy.page_end %>
14
11
  </div>
data/lib/hot-glue.rb CHANGED
@@ -1,11 +1,7 @@
1
1
  require "hotglue/engine"
2
2
  require 'kaminari'
3
3
 
4
-
5
4
  module HotGlue
6
-
7
-
8
-
9
5
  module TemplateBuilders
10
6
 
11
7
  end
@@ -1,6 +1,6 @@
1
1
  module HotGlue
2
2
  class Engine < ::Rails::Engine
3
3
 
4
- config.autoload_paths << File.expand_path("lib/helpers/hot_glue_helper.rb", __dir__)
4
+
5
5
  end
6
6
  end
@@ -1,5 +1,5 @@
1
1
  module HotGlue
2
2
  class Version
3
- CURRENT = '0.5.4'
3
+ CURRENT = '0.5.5'
4
4
  end
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: hot-glue
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.5.4
4
+ version: 0.5.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jason Fleetwood-Boldt
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2022-11-27 00:00:00.000000000 Z
11
+ date: 2022-12-27 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails
@@ -75,9 +75,12 @@ files:
75
75
  - config/database.yml
76
76
  - config/hot_glue.yml
77
77
  - db/schema.rb
78
- - lib/generators/hot_glue/helpers.rb
79
78
  - lib/generators/hot_glue/install_generator.rb
80
79
  - lib/generators/hot_glue/layout/builder.rb
80
+ - lib/generators/hot_glue/layout_strategy/base.rb
81
+ - lib/generators/hot_glue/layout_strategy/bootstrap.rb
82
+ - lib/generators/hot_glue/layout_strategy/hot_glue.rb
83
+ - lib/generators/hot_glue/layout_strategy/tailwind.rb
81
84
  - lib/generators/hot_glue/markup_templates/base.rb
82
85
  - lib/generators/hot_glue/markup_templates/erb.rb
83
86
  - lib/generators/hot_glue/scaffold_generator.rb
@@ -1,13 +0,0 @@
1
- class HotGlue::Helpers
2
-
3
-
4
- def self.open_page( link)
5
- if RbConfig::CONFIG['host_os'] =~ /mswin|mingw|cygwin/
6
- system "start #{link}"
7
- elsif RbConfig::CONFIG['host_os'] =~ /darwin/
8
- system "open #{link}"
9
- elsif RbConfig::CONFIG['host_os'] =~ /linux|bsd/
10
- system "xdg-open #{link}"
11
- end
12
- end
13
- end