hot-glue 0.4.5 → 0.4.9
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.circleci/config.yml +71 -0
- data/.github/FUNDING.yml +2 -2
- data/.gitignore +4 -1
- data/Gemfile +5 -1
- data/Gemfile.lock +16 -16
- data/README.md +340 -251
- data/README2.md +79 -0
- data/config/database.yml +8 -83
- data/db/schema.rb +1 -0
- data/lib/generators/hot_glue/install_generator.rb +0 -1
- data/lib/generators/hot_glue/layout/builder.rb +51 -33
- data/lib/generators/hot_glue/markup_templates/erb.rb +97 -88
- data/lib/generators/hot_glue/scaffold_generator.rb +292 -91
- data/lib/generators/hot_glue/templates/controller.rb.erb +51 -47
- data/lib/generators/hot_glue/templates/erb/_form.erb +3 -2
- data/lib/generators/hot_glue/templates/erb/_line.erb +1 -1
- data/lib/generators/hot_glue/templates/erb/_list.erb +31 -21
- data/lib/generators/hot_glue/templates/erb/_new_button.erb +1 -1
- data/lib/generators/hot_glue/templates/erb/_new_form.erb +4 -3
- data/lib/generators/hot_glue/templates/erb/_show.erb +10 -6
- data/lib/generators/hot_glue/templates/erb/create.turbo_stream.erb +4 -4
- data/lib/generators/hot_glue/templates/erb/destroy.turbo_stream.erb +2 -2
- data/lib/generators/hot_glue/templates/erb/edit.erb +2 -2
- data/lib/generators/hot_glue/templates/erb/index.erb +1 -1
- data/lib/generators/hot_glue/templates/erb/new.erb +1 -1
- data/lib/generators/hot_glue/templates/erb/update.turbo_stream.erb +2 -2
- data/lib/hotglue/version.rb +3 -1
- metadata +6 -20
- data/db/schema.rb +0 -60
- data/lib/generators/hot_glue/markup_templates/haml.rb +0 -243
- data/lib/generators/hot_glue/markup_templates/slim.rb +0 -9
data/README2.md
ADDED
@@ -0,0 +1,79 @@
|
|
1
|
+
|
2
|
+
## LEGACY SETUP FOR RAILS 6
|
3
|
+
|
4
|
+
## Legacy Step #1. ADD HOTWIRE
|
5
|
+
(RAILS 6 ONLY— SKIP THIS STEP FOR RAILS 7)
|
6
|
+
```
|
7
|
+
yarn add @hotwired/turbo-rails
|
8
|
+
```
|
9
|
+
or `npm install @hotwired/turbo-rails`
|
10
|
+
|
11
|
+
|
12
|
+
## Legacy Step #2. SWITCH FROM TurblLinks to Turbo-Rails
|
13
|
+
(RAILS 6 ONLY — SKIP FOR RAILS 7)
|
14
|
+
(THIS WAS AUTOMATICALLY DONE BY THE HOT GLUE INSTALLATION -- CONFIRM CHANGES ONLY)
|
15
|
+
- Add `gem 'turbo-rails'` to your Gemfile & `bundle install`
|
16
|
+
- Then install it with `rails turbo:install`
|
17
|
+
- The Turbo install has switched your action cable settings from 'async' to Redis, so be sure to start a redis server
|
18
|
+
- in `app/javascript/packs/application.js` remove this line
|
19
|
+
```
|
20
|
+
import Turbolinks from "turbolinks"
|
21
|
+
```
|
22
|
+
and replace it with
|
23
|
+
```
|
24
|
+
import { Turbo } from "@hotwired/turbo-rails"
|
25
|
+
```
|
26
|
+
|
27
|
+
|
28
|
+
Also replace
|
29
|
+
```
|
30
|
+
Turbolinks.start()
|
31
|
+
```
|
32
|
+
with:
|
33
|
+
```
|
34
|
+
Turbo.start()
|
35
|
+
```
|
36
|
+
|
37
|
+
|
38
|
+
## Legacy Step #3. INSTALL WEBPACKER
|
39
|
+
(_SKIP FOR RAILS 7_ unless you want to use Webpacker with Rails 7)
|
40
|
+
|
41
|
+
** For webpacker, you must be using Node version ^12.13.0 || ^14.15.0 || >=16 **
|
42
|
+
|
43
|
+
I recommend Node Version Manager (NVM) to switch between nodes. You will not be able to get through the following command with a Node version that does not match above.
|
44
|
+
|
45
|
+
Check your node version with `node -v`
|
46
|
+
|
47
|
+
```
|
48
|
+
`yarn add @rails/webpacker`
|
49
|
+
```
|
50
|
+
|
51
|
+
|
52
|
+
rails webpacker:install
|
53
|
+
|
54
|
+
## Legacy Step #4: Postgresql Enum Support for Rail 6
|
55
|
+
For Enum support, I recommend activerecord-pg_enum
|
56
|
+
Instructions for Rails 6 are here:
|
57
|
+
https://jasonfleetwoodboldt.com/courses/stepping-up-rails/enumerated-types-in-rails-and-postgres/
|
58
|
+
|
59
|
+
_This functionality is now built-in to Rails 7._
|
60
|
+
|
61
|
+
|
62
|
+
## Legacy Step #5: Fix Devise if adding Turbo To Your Project
|
63
|
+
## IMPORTANT: Devise currently has serious compatibility issues with Turbo Rails. In particular, your log-in screens do not work out of the box. Follow the next step to fix them.
|
64
|
+
|
65
|
+
Manually port the Devise views into your app with
|
66
|
+
|
67
|
+
`rails generate devise:views`
|
68
|
+
|
69
|
+
Edit `devise/registrations/new`, `devise/sessions/new`, `devise/passwords/new` and `devise/confirmations/new` modifying all four templates like so:
|
70
|
+
|
71
|
+
form_for(resource, as: resource_name, url: session_path(resource_name) ) do |f|
|
72
|
+
|
73
|
+
add the data-turbo false option in the html key:
|
74
|
+
```bigquery
|
75
|
+
|
76
|
+
```
|
77
|
+
form_for(resource, as: resource_name, **html: {'data-turbo' => "false"},** url: session_path(resource_name) ) do |f|
|
78
|
+
|
79
|
+
This tells Devise to fall back to non-Turbo interaction for the log-in and registration. For the rest of the app, we will use Turbo Rails interactions.
|
data/config/database.yml
CHANGED
@@ -1,86 +1,11 @@
|
|
1
|
-
# PostgreSQL. Versions 9.3 and up are supported.
|
2
|
-
#
|
3
|
-
# Install the pg driver:
|
4
|
-
# gem install pg
|
5
|
-
# On macOS with Homebrew:
|
6
|
-
# gem install pg -- --with-pg-config=/usr/local/bin/pg_config
|
7
|
-
# On macOS with MacPorts:
|
8
|
-
# gem install pg -- --with-pg-config=/opt/local/lib/postgresql84/bin/pg_config
|
9
|
-
# On Windows:
|
10
|
-
# gem install pg
|
11
|
-
# Choose the win32 build.
|
12
|
-
# Install PostgreSQL and put its /bin directory on your path.
|
13
|
-
#
|
14
|
-
# Configure Using Gemfile
|
15
|
-
# gem 'pg'
|
16
|
-
#
|
17
|
-
default: &default
|
18
|
-
adapter: postgresql
|
19
|
-
encoding: unicode
|
20
|
-
# For details on connection pooling, see Rails configuration guide
|
21
|
-
# https://guides.rubyonrails.org/configuring.html#database-pooling
|
22
|
-
pool: <%= ENV.fetch("RAILS_MAX_THREADS") { 5 } %>
|
23
|
-
|
24
1
|
development:
|
25
|
-
|
26
|
-
database:
|
27
|
-
|
28
|
-
|
29
|
-
# To create additional roles in postgres see `$ createuser --help`.
|
30
|
-
# When left blank, postgres will use the default role. This is
|
31
|
-
# the same name as the operating system user running Rails.
|
32
|
-
#username: Dummy
|
33
|
-
|
34
|
-
# The password associated with the postgres role (username).
|
35
|
-
#password:
|
36
|
-
|
37
|
-
# Connect on a TCP socket. Omitted by default since the client uses a
|
38
|
-
# domain socket that doesn't need configuration. Windows does not have
|
39
|
-
# domain sockets, so uncomment these lines.
|
40
|
-
#host: localhost
|
2
|
+
adapter: sqlite3
|
3
|
+
database: ../spec/dummy/db/development.sqlite3
|
4
|
+
pool: 5
|
5
|
+
timeout: 5000
|
41
6
|
|
42
|
-
# The TCP port the server listens on. Defaults to 5432.
|
43
|
-
# If your server runs on a different port number, change accordingly.
|
44
|
-
#port: 5432
|
45
|
-
|
46
|
-
# Schema search path. The server defaults to $user,public
|
47
|
-
#schema_search_path: myapp,sharedapp,public
|
48
|
-
|
49
|
-
# Minimum log levels, in increasing order:
|
50
|
-
# debug5, debug4, debug3, debug2, debug1,
|
51
|
-
# log, notice, warning, error, fatal, and panic
|
52
|
-
# Defaults to warning.
|
53
|
-
#min_messages: notice
|
54
|
-
|
55
|
-
# Warning: The database defined as "test" will be erased and
|
56
|
-
# re-generated from your development database when you run "rake".
|
57
|
-
# Do not set this db to the same as development or production.
|
58
7
|
test:
|
59
|
-
|
60
|
-
database:
|
61
|
-
|
62
|
-
|
63
|
-
# like your database password, in your source code. If your source code is
|
64
|
-
# ever seen by anyone, they now have access to your database.
|
65
|
-
#
|
66
|
-
# Instead, provide the password or a full connection URL as an environment
|
67
|
-
# variable when you boot the app. For example:
|
68
|
-
#
|
69
|
-
# DATABASE_URL="postgres://myuser:mypass@localhost/somedatabase"
|
70
|
-
#
|
71
|
-
# If the connection URL is provided in the special DATABASE_URL environment
|
72
|
-
# variable, Rails will automatically merge its configuration values on top of
|
73
|
-
# the values provided in this file. Alternatively, you can specify a connection
|
74
|
-
# URL environment variable explicitly:
|
75
|
-
#
|
76
|
-
# production:
|
77
|
-
# url: <%= ENV['MY_APP_DATABASE_URL'] %>
|
78
|
-
#
|
79
|
-
# Read https://guides.rubyonrails.org/configuring.html#configuring-a-database
|
80
|
-
# for a full overview on how database connection configuration can be specified.
|
81
|
-
#
|
82
|
-
production:
|
83
|
-
<<: *default
|
84
|
-
database: Dummy_production
|
85
|
-
username: Dummy
|
86
|
-
password: <%= ENV['DUMMY_DATABASE_PASSWORD'] %>
|
8
|
+
adapter: sqlite3
|
9
|
+
database: ../spec/dummy/db/test.sqlite3
|
10
|
+
pool: 5
|
11
|
+
timeout: 5000
|
data/db/schema.rb
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
db/spec/dummy/db/schema.rb
|
@@ -17,7 +17,6 @@ module HotGlue
|
|
17
17
|
super
|
18
18
|
@layout = options['layout'] || "hotglue"
|
19
19
|
@theme = options['theme']
|
20
|
-
|
21
20
|
if @layout == "hotglue" && options['theme'].nil?
|
22
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"
|
23
22
|
return
|
@@ -3,23 +3,27 @@
|
|
3
3
|
module HotGlue
|
4
4
|
module Layout
|
5
5
|
class Builder
|
6
|
-
attr_reader :include_setting,
|
6
|
+
attr_reader :include_setting,
|
7
|
+
:downnest_object,
|
8
|
+
:buttons_width, :columns,
|
9
|
+
:smart_layout, :specified_grouping_mode
|
7
10
|
|
8
11
|
def initialize(params)
|
9
12
|
@include_setting = params[:include_setting]
|
10
|
-
@
|
13
|
+
@downnest_object = params[:downnest_object]
|
11
14
|
|
12
15
|
@buttons_width = params[:buttons_width]
|
13
16
|
|
14
17
|
@no_buttons = @buttons_width == 0
|
15
18
|
@columns = params[:columns]
|
16
19
|
@smart_layout = params[:smart_layout]
|
20
|
+
@specified_grouping_mode = include_setting.include?(":")
|
17
21
|
end
|
18
22
|
|
19
23
|
def construct
|
20
24
|
layout_object = {
|
21
25
|
columns: {
|
22
|
-
size_each: nil,
|
26
|
+
size_each: smart_layout ? 2 : (specified_grouping_mode ? nil : 1),
|
23
27
|
container: [] # array of arrays
|
24
28
|
},
|
25
29
|
portals: {
|
@@ -28,33 +32,39 @@ module HotGlue
|
|
28
32
|
buttons: { size: @buttons_width}
|
29
33
|
}
|
30
34
|
|
31
|
-
|
32
|
-
|
33
|
-
end
|
35
|
+
# downnest_object.each do |child, size|
|
36
|
+
# layout_object[:portals][child] = {size: size}
|
37
|
+
# end
|
34
38
|
|
35
39
|
# smart layout: 2 columns per field; 4 column for EACH downnested portals, 2 column for buttons
|
36
|
-
how_many_downnest =
|
40
|
+
how_many_downnest = downnest_object.size
|
41
|
+
|
42
|
+
bootstrap_columns = (12 - @buttons_width )
|
43
|
+
|
44
|
+
bootstrap_columns = bootstrap_columns - (downnest_object.collect{|k,v| v}.sum)
|
37
45
|
|
38
|
-
bootstrap_columns = (12-@buttons_width )
|
39
|
-
bootstrap_columns = bootstrap_columns - (how_many_downnest*4)
|
40
46
|
available_columns = (bootstrap_columns / 2).floor # bascially turns the 12-column grid into a 6-column grid
|
41
47
|
|
42
48
|
if available_columns < 0
|
43
49
|
raise "Cannot build layout with #{how_many_downnest} downnested portals"
|
44
50
|
end
|
45
51
|
|
46
|
-
|
47
|
-
@downnest_children.each_with_index{ |child, i| @downnest_children_width[i] = 4}
|
48
|
-
|
49
|
-
if include_setting.nil?
|
52
|
+
downnest_children_width = []
|
50
53
|
|
54
|
+
downnest_object.each do |child, size|
|
55
|
+
layout_object[:portals][child] = {size: size}
|
51
56
|
end
|
52
57
|
|
58
|
+
|
53
59
|
if smart_layout
|
54
60
|
# automatic control
|
55
61
|
#
|
56
62
|
|
57
63
|
if columns.size > available_columns
|
64
|
+
if available_columns == 0
|
65
|
+
raise "Oopps... No available columns in SMART LAYOUT"
|
66
|
+
end
|
67
|
+
|
58
68
|
each_col_can_have = (columns.size.to_f / available_columns.to_f).round
|
59
69
|
|
60
70
|
layout_object[:columns][:container] = (0..available_columns-1).collect { |x|
|
@@ -68,23 +78,29 @@ module HotGlue
|
|
68
78
|
}
|
69
79
|
layout_object[:columns][:container].reject!{|x| x == [nil]}
|
70
80
|
end
|
71
|
-
elsif !
|
81
|
+
elsif ! specified_grouping_mode
|
82
|
+
# not smart and no specified grouping
|
83
|
+
#
|
72
84
|
layout_object[:columns][:container] = columns.collect{|col| [col]}
|
73
85
|
|
74
|
-
else
|
86
|
+
else # specified grouping mode -- the builder is given control
|
75
87
|
|
76
88
|
(0..available_columns-1).each do |int|
|
77
89
|
layout_object[:columns][:container][int] = []
|
78
90
|
end
|
79
91
|
|
80
92
|
# input control
|
81
|
-
|
93
|
+
|
94
|
+
user_layout_columns = @include_setting.split(":")
|
95
|
+
size_each = (bootstrap_columns / user_layout_columns.count).floor # this is the bootstrap size
|
96
|
+
|
97
|
+
layout_object[:columns][:size_each] = size_each
|
82
98
|
|
83
99
|
if user_layout_columns.size > available_columns
|
84
|
-
raise "Your include statement #{
|
100
|
+
raise "Your include statement #{@include_setting } has #{user_layout_columns.size} columns, but I can only construct up to #{available_columns}"
|
85
101
|
end
|
86
102
|
user_layout_columns.each_with_index do |column,i|
|
87
|
-
layout_object[:columns][:container][i] = column.split(",")
|
103
|
+
layout_object[:columns][:container][i] = column.split(",").collect(&:to_sym)
|
88
104
|
end
|
89
105
|
|
90
106
|
if user_layout_columns.size < layout_object[:columns][:container].size
|
@@ -92,21 +108,23 @@ module HotGlue
|
|
92
108
|
end
|
93
109
|
end
|
94
110
|
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
end
|
111
|
+
# TODO: do I want this code that expands the downnest portal
|
112
|
+
# maybe refactor into a setting on the --downnest flag itself somehow
|
113
|
+
# if layout_object[:columns][:container].size < available_columns
|
114
|
+
# available = available_columns - layout_object[:columns][:container].size
|
115
|
+
# downnest_child_count = 0
|
116
|
+
#
|
117
|
+
# while(available > 0)
|
118
|
+
# if (downnest_child_count <= downnest_children.size-1)
|
119
|
+
# layout_object[:portals][downnest_children[downnest_child_count]][:size] = layout_object[:portals][downnest_children[downnest_child_count]][:size] + 2
|
120
|
+
# else
|
121
|
+
# # leave as-is
|
122
|
+
# end
|
123
|
+
# downnest_child_count = downnest_child_count + 1
|
124
|
+
# available = available - 1
|
125
|
+
# end
|
126
|
+
# # give some space back to the downnest
|
127
|
+
# end
|
110
128
|
|
111
129
|
puts "*** constructed layout columns #{layout_object.inspect}"
|
112
130
|
layout_object
|
@@ -1,24 +1,33 @@
|
|
1
1
|
module HotGlue
|
2
2
|
class ErbTemplate < TemplateBase
|
3
3
|
|
4
|
+
|
5
|
+
|
6
|
+
def add_spaces_each_line(text, num_spaces)
|
7
|
+
add_spaces = " " * num_spaces
|
8
|
+
text.lines.collect{|line| add_spaces + line}.join("")
|
9
|
+
end
|
10
|
+
|
11
|
+
|
4
12
|
# include GeneratorHelper
|
5
13
|
attr_accessor :singular
|
6
14
|
|
7
15
|
def field_output(col, type = nil, width, col_identifier )
|
8
|
-
" <%= f.text_field :#{col
|
9
|
-
"
|
16
|
+
" <%= f.text_field :#{col}, value: @#{@singular}.#{col}, autocomplete: 'off', size: #{width}, class: 'form-control', type: '#{type}' %>\n "+
|
17
|
+
"\n"
|
10
18
|
end
|
11
19
|
|
12
20
|
|
13
21
|
def magic_button_output(*args)
|
14
|
-
|
15
|
-
|
22
|
+
path = args[0][:path]
|
23
|
+
# path_helper_singular = args[0][:path_helper_singular]
|
24
|
+
# path_helper_args = args[0][:path_helper_args]
|
16
25
|
singular = args[0][:singular]
|
17
26
|
magic_buttons = args[0][:magic_buttons]
|
18
27
|
small_buttons = args[0][:small_buttons]
|
19
28
|
|
20
29
|
magic_buttons.collect{ |button_name|
|
21
|
-
"<%= form_with model: #{singular}, url: #{
|
30
|
+
"<%= 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| %>
|
22
31
|
<%= f.hidden_field :#{button_name}, value: \"#{button_name}\" %>
|
23
32
|
<%= f.submit '#{button_name.titleize}'.html_safe, disabled: (#{singular}.respond_to?(:#{button_name}able?) && ! #{singular}.#{button_name}able? ), class: '#{singular}-button btn btn-primary #{"btn-sm" if small_buttons}' %>
|
24
33
|
<% end %>"
|
@@ -31,8 +40,7 @@ module HotGlue
|
|
31
40
|
lines = 5
|
32
41
|
end
|
33
42
|
|
34
|
-
"<%= f.text_area :#{col
|
35
|
-
"<label class='form-text'>#{col.to_s.humanize}</label>"
|
43
|
+
"<%= f.text_area :#{col}, class: 'form-control', autocomplete: 'off', cols: 40, rows: '#{lines}' %>"
|
36
44
|
end
|
37
45
|
|
38
46
|
def list_column_headings(*args)
|
@@ -59,90 +67,92 @@ module HotGlue
|
|
59
67
|
show_only = args[0][:show_only]
|
60
68
|
singular_class = args[0][:singular_class]
|
61
69
|
col_identifier = args[0][:col_identifier]
|
70
|
+
ownership_field = args[0][:ownership_field]
|
62
71
|
|
63
|
-
|
64
|
-
# TODO: CLEAN ME
|
65
72
|
@singular = args[0][:singular]
|
66
73
|
singular = @singular
|
67
|
-
|
68
|
-
col_spaces_prepend = " "
|
69
|
-
|
70
|
-
|
71
74
|
result = layout_columns.map{ |column|
|
72
|
-
"<div class='#{col_identifier}' >" +
|
73
|
-
|
75
|
+
" <div class='#{col_identifier}' >" +
|
74
76
|
column.map { |col|
|
77
|
+
field_result =
|
78
|
+
if show_only.include?(col.to_sym)
|
79
|
+
"<%= @#{singular}.#{col} %>"
|
80
|
+
else
|
81
|
+
type = eval("#{singular_class}.columns_hash['#{col}']").type
|
82
|
+
limit = eval("#{singular_class}.columns_hash['#{col}']").limit
|
83
|
+
sql_type = eval("#{singular_class}.columns_hash['#{col}']").sql_type
|
84
|
+
|
85
|
+
case type
|
86
|
+
when :integer
|
87
|
+
# look for a belongs_to on this object
|
88
|
+
if col.to_s.ends_with?("_id")
|
89
|
+
assoc_name = col.to_s.gsub("_id","")
|
90
|
+
assoc = eval("#{singular_class}.reflect_on_association(:#{assoc_name})")
|
91
|
+
if assoc.nil?
|
92
|
+
exit_message = "*** Oops. on the #{singular_class} object, there doesn't seem to be an association called '#{assoc_name}'"
|
93
|
+
exit
|
94
|
+
end
|
95
|
+
|
96
|
+
is_owner = col == ownership_field
|
97
|
+
assoc_class_name = assoc.active_record.name
|
98
|
+
display_column = HotGlue.derrive_reference_name(assoc_class_name)
|
99
|
+
|
100
|
+
(is_owner ? "<% unless @#{assoc_name} %>\n" : "") +
|
101
|
+
" <%= f.collection_select(:#{col}, #{assoc.class_name}.all, :id, :#{display_column}, {prompt: true, selected: @#{singular}.#{col} }, class: 'form-control') %>\n" +
|
102
|
+
(is_owner ? "<% else %>\n <%= @#{assoc_name}.#{display_column} %>" : "") +
|
103
|
+
(is_owner ? "\n<% end %>" : "")
|
104
|
+
|
105
|
+
else
|
106
|
+
"<%= f.text_field :#{col}, value: #{singular}.#{col}, class: 'form-control', size: 4, type: 'number' %>"
|
75
107
|
|
76
|
-
field_result = if show_only.include?(col)
|
77
|
-
"<%= @#{singular}.#{col.to_s} %>" +
|
78
|
-
"<label class='form-text'>#{col.to_s.humanize}</label>"
|
79
|
-
else
|
80
|
-
type = eval("#{singular_class}.columns_hash['#{col}']").type
|
81
|
-
limit = eval("#{singular_class}.columns_hash['#{col}']").limit
|
82
|
-
sql_type = eval("#{singular_class}.columns_hash['#{col}']").sql_type
|
83
|
-
|
84
|
-
case type
|
85
|
-
when :integer
|
86
|
-
# look for a belongs_to on this object
|
87
|
-
if col.to_s.ends_with?("_id")
|
88
|
-
assoc_name = col.to_s.gsub("_id","")
|
89
|
-
assoc = eval("#{singular_class}.reflect_on_association(:#{assoc_name})")
|
90
|
-
if assoc.nil?
|
91
|
-
exit_message= "*** Oops. on the #{singular_class} object, there doesn't seem to be an association called '#{assoc_name}'"
|
92
|
-
exit
|
93
108
|
end
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
<label class='small form-text text-muted'>#{col.to_s.humanize}</label>"
|
109
|
+
when :string
|
110
|
+
if sql_type == "varchar" || sql_type == "character varying"
|
111
|
+
field_output(col, nil, limit || 40, col_identifier)
|
112
|
+
else
|
113
|
+
text_area_output(col, 65536, col_identifier)
|
114
|
+
end
|
101
115
|
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
|
116
|
+
when :text
|
117
|
+
if sql_type == "varchar"
|
118
|
+
field_output(col, nil, limit, col_identifier)
|
119
|
+
else
|
120
|
+
text_area_output(col, 65536, col_identifier)
|
121
|
+
end
|
122
|
+
when :float
|
123
|
+
field_output(col, nil, 5, col_identifier)
|
124
|
+
when :datetime
|
125
|
+
"<%= datetime_field_localized(f, :#{col}, #{singular}.#{col}, '#{ col.to_s.humanize }', #{@auth ? @auth+'.timezone' : 'nil'}) %>"
|
126
|
+
when :date
|
127
|
+
"<%= date_field_localized(f, :#{col}, #{singular}.#{col}, '#{ col.to_s.humanize }', #{@auth ? @auth+'.timezone' : 'nil'}) %>"
|
128
|
+
when :time
|
129
|
+
"<%= time_field_localized(f, :#{col}, #{singular}.#{col}, '#{ col.to_s.humanize }', #{@auth ? @auth+'.timezone' : 'nil'}) %>"
|
130
|
+
when :boolean
|
131
|
+
" " +
|
132
|
+
" <span>#{col.to_s.humanize}</span>" +
|
133
|
+
" <%= f.radio_button(:#{col}, '0', checked: #{singular}.#{col} ? '' : 'checked') %>\n" +
|
134
|
+
" <%= f.label(:#{col}, value: 'No', for: '#{singular}_#{col}_0') %>\n" +
|
135
|
+
" <%= f.radio_button(:#{col}, '1', checked: #{singular}.#{col} ? 'checked' : '') %>\n" +
|
136
|
+
" <%= f.label(:#{col}, value: 'Yes', for: '#{singular}_#{col}_1') %>\n" +
|
137
|
+
""
|
138
|
+
when :enum
|
139
|
+
enum_type = eval("#{singular_class}.columns.select{|x| x.name == '#{col}'}[0].sql_type")
|
140
|
+
"<%= f.collection_select(:#{col}, enum_to_collection_select( #{singular_class}.defined_enums['#{enum_type}']), :key, :value, {selected: @#{singular}.#{col} }, class: 'form-control') %>"
|
108
141
|
end
|
109
142
|
|
110
|
-
when :text
|
111
|
-
if sql_type == "varchar"
|
112
|
-
field_output(col, nil, limit, col_identifier)
|
113
|
-
else
|
114
|
-
text_area_output(col, 65536, col_identifier)
|
115
|
-
end
|
116
|
-
when :float
|
117
|
-
field_output(col, nil, 5, col_identifier)
|
118
|
-
when :datetime
|
119
|
-
"<%= datetime_field_localized(f, :#{col.to_s}, #{singular}.#{col.to_s}, '#{ col.to_s.humanize }', #{@auth ? @auth+'.timezone' : 'nil'}) %>"
|
120
|
-
when :date
|
121
|
-
"<%= date_field_localized(f, :#{col.to_s}, #{singular}.#{col.to_s}, '#{ col.to_s.humanize }', #{@auth ? @auth+'.timezone' : 'nil'}) %>"
|
122
|
-
when :time
|
123
|
-
"<%= time_field_localized(f, :#{col.to_s}, #{singular}.#{col.to_s}, '#{ col.to_s.humanize }', #{@auth ? @auth+'.timezone' : 'nil'}) %>"
|
124
|
-
when :boolean
|
125
|
-
" " +
|
126
|
-
" <span>#{col.to_s.humanize}</span>" +
|
127
|
-
" <%= f.radio_button(:#{col.to_s}, '0', checked: #{singular}.#{col.to_s} ? '' : 'checked') %>\n" +
|
128
|
-
" <%= f.label(:#{col.to_s}, value: 'No', for: '#{singular}_#{col.to_s}_0') %>\n" +
|
129
|
-
" <%= f.radio_button(:#{col.to_s}, '1', checked: #{singular}.#{col.to_s} ? 'checked' : '') %>\n" +
|
130
|
-
" <%= f.label(:#{col.to_s}, value: 'Yes', for: '#{singular}_#{col.to_s}_1') %>\n" +
|
131
|
-
""
|
132
|
-
when :enum
|
133
|
-
enum_type = eval("#{singular_class}.columns.select{|x| x.name == '#{col.to_s}'}[0].sql_type")
|
134
|
-
"<%= f.collection_select(:#{col.to_s}, enum_to_collection_select( #{singular_class}.defined_enums['#{enum_type}']), :key, :value, {selected: @#{singular}.#{col.to_s} }, class: 'form-control') %>
|
135
|
-
<label class='small form-text text-muted'>#{col.to_s.humanize}</label>"
|
136
143
|
end
|
137
|
-
|
138
|
-
|
139
|
-
|
140
|
-
|
141
|
-
|
142
|
-
|
143
|
-
|
144
|
-
|
145
|
-
|
144
|
+
|
145
|
+
if (type == :integer) && col.to_s.ends_with?("_id")
|
146
|
+
field_error_name = col.to_s.gsub("_id","")
|
147
|
+
else
|
148
|
+
field_error_name = col
|
149
|
+
end
|
150
|
+
|
151
|
+
add_spaces_each_line( "\n <span class='<%= \"alert-danger\" if #{singular}.errors.details.keys.include?(:#{field_error_name}) %>' #{ 'style="display: inherit;"'} >\n" +
|
152
|
+
add_spaces_each_line(field_result + "\n<label class='small form-text text-muted'>#{col.to_s.humanize}</label>", 4) +
|
153
|
+
"\n </span>\n <br />", 2)
|
154
|
+
|
155
|
+
}.join("") + "\n </div>"
|
146
156
|
}.join("\n")
|
147
157
|
return result
|
148
158
|
end
|
@@ -162,20 +172,20 @@ module HotGlue
|
|
162
172
|
singular = args[0][:singular]
|
163
173
|
perc_width = args[0][:perc_width]
|
164
174
|
layout = args[0][:layout]
|
175
|
+
col_identifier = args[0][:col_identifier] || (layout == "bootstrap" ? "col-md-2" : "scaffold-cell")
|
176
|
+
|
165
177
|
|
166
178
|
columns_count = layout_columns.count + 1
|
167
179
|
perc_width = (perc_width).floor
|
168
180
|
|
169
181
|
if layout == "bootstrap"
|
170
|
-
col_identifer = "col-md-2"
|
171
182
|
style_with_flex_basis = ""
|
172
183
|
else
|
173
184
|
style_with_flex_basis = " style='flex-basis: #{perc_width}%'"
|
174
|
-
col_identifer = "scaffold-cell"
|
175
185
|
end
|
176
186
|
|
177
187
|
result = layout_columns.map{ |column|
|
178
|
-
"<div class='#{
|
188
|
+
"<div class='#{col_identifier}'#{style_with_flex_basis}>" +
|
179
189
|
|
180
190
|
|
181
191
|
column.map { |col|
|
@@ -186,7 +196,7 @@ module HotGlue
|
|
186
196
|
case type
|
187
197
|
when :integer
|
188
198
|
# look for a belongs_to on this object
|
189
|
-
if col.
|
199
|
+
if col.ends_with?("_id")
|
190
200
|
|
191
201
|
assoc_name = col.to_s.gsub("_id","")
|
192
202
|
|
@@ -199,9 +209,8 @@ module HotGlue
|
|
199
209
|
exit
|
200
210
|
# raise(HotGlue::Error,exit_message)
|
201
211
|
end
|
202
|
-
|
203
|
-
display_column = HotGlue.derrive_reference_name(
|
204
|
-
|
212
|
+
assoc_class_name = assoc.active_record.name
|
213
|
+
display_column = HotGlue.derrive_reference_name(assoc_class_name)
|
205
214
|
"<%= #{singular}.#{assoc.name.to_s}.try(:#{display_column}) || '<span class=\"content alert-danger\">MISSING</span>'.html_safe %>"
|
206
215
|
|
207
216
|
else
|
@@ -244,7 +253,7 @@ module HotGlue
|
|
244
253
|
<% end %>
|
245
254
|
|
246
255
|
" when :enum
|
247
|
-
enum_type = eval("#{singular_class}.columns.select{|x| x.name == '#{col
|
256
|
+
enum_type = eval("#{singular_class}.columns.select{|x| x.name == '#{col}'}[0].sql_type")
|
248
257
|
|
249
258
|
"
|
250
259
|
<% if #{singular}.#{col}.nil? %>
|