hot-glue 0.1.0 → 0.2.2
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/Gemfile.lock +22 -19
- data/README.md +36 -19
- data/app/helpers/hot_glue/controller_helper.rb +1 -1
- data/lib/generators/hot_glue/install_generator.rb +0 -2
- data/lib/generators/hot_glue/markup_templates/base.rb +7 -0
- data/lib/generators/hot_glue/markup_templates/erb.rb +227 -0
- data/lib/generators/hot_glue/markup_templates/haml.rb +236 -0
- data/lib/generators/hot_glue/markup_templates/slim.rb +9 -0
- data/lib/generators/hot_glue/scaffold_generator.rb +127 -264
- data/lib/generators/hot_glue/templates/controller.rb.erb +14 -2
- data/lib/generators/hot_glue/templates/erb/_errors.erb +11 -0
- data/lib/generators/hot_glue/templates/erb/_flash_notices.erb +12 -0
- data/lib/generators/hot_glue/templates/erb/_form.erb +8 -0
- data/lib/generators/hot_glue/templates/erb/_line.erb +10 -0
- data/lib/generators/hot_glue/templates/erb/_list.erb +19 -0
- data/lib/generators/hot_glue/templates/erb/_new_button.erb +3 -0
- data/lib/generators/hot_glue/templates/erb/_new_form.erb +8 -0
- data/lib/generators/hot_glue/templates/erb/_show.erb +8 -0
- data/lib/generators/hot_glue/templates/erb/create.turbo_stream.erb +18 -0
- data/lib/generators/hot_glue/templates/erb/destroy.turbo_stream.erb +3 -0
- data/lib/generators/hot_glue/templates/erb/edit.erb +30 -0
- data/lib/generators/hot_glue/templates/erb/edit.turbo_stream.erb +3 -0
- data/lib/generators/hot_glue/templates/erb/index.erb +10 -0
- data/lib/generators/hot_glue/templates/erb/new.erb +1 -0
- data/lib/generators/hot_glue/templates/erb/update.turbo_stream.erb +10 -0
- data/lib/generators/hot_glue/templates/{_errors.haml → haml/_errors.haml} +0 -0
- data/lib/generators/hot_glue/templates/{_flash_notices.haml → haml/_flash_notices.haml} +0 -0
- data/lib/generators/hot_glue/templates/{_form.haml → haml/_form.haml} +1 -0
- data/lib/generators/hot_glue/templates/{_line.haml → haml/_line.haml} +0 -0
- data/lib/generators/hot_glue/templates/{_list.haml → haml/_list.haml} +0 -0
- data/lib/generators/hot_glue/templates/{_new_button.haml → haml/_new_button.haml} +0 -0
- data/lib/generators/hot_glue/templates/{_new_form.haml → haml/_new_form.haml} +0 -0
- data/lib/generators/hot_glue/templates/{_show.haml → haml/_show.haml} +0 -0
- data/lib/generators/hot_glue/templates/{create.turbo_stream.haml → haml/create.turbo_stream.haml} +0 -0
- data/lib/generators/hot_glue/templates/{destroy.turbo_stream.haml → haml/destroy.turbo_stream.haml} +0 -0
- data/lib/generators/hot_glue/templates/{edit.haml → haml/edit.haml} +0 -0
- data/lib/generators/hot_glue/templates/{edit.turbo_stream.haml → haml/edit.turbo_stream.haml} +0 -0
- data/lib/generators/hot_glue/templates/{index.haml → haml/index.haml} +0 -0
- data/lib/generators/hot_glue/templates/{new.haml → haml/new.haml} +0 -0
- data/lib/generators/hot_glue/templates/{update.turbo_stream.haml → haml/update.turbo_stream.haml} +0 -0
- data/lib/generators/hot_glue/templates/system_spec.rb.erb +1 -1
- data/lib/hot-glue.rb +6 -20
- data/lib/hotglue/version.rb +1 -1
- metadata +49 -24
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 4ea47eaaf1c1a9a92b6382e2dc41a5e9f119600cfd0f58bc8b8091c33e3ac48a
|
|
4
|
+
data.tar.gz: c9ebd867495aff539bbb53c7d1ecb09c5fd83cb00121a129eadfc96533647efc
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 2022393514c059339cc9e4c163962501a48609f317ab7d3f4be3a00e467637d6dbb14757dadf9312569dedc6372a43f427e28b6c3b2638067bdc25ca4d23fe3d
|
|
7
|
+
data.tar.gz: 7a19916224effd9ad2726baf944b110083978ee8328588301f89c4c2ae4791bfad8fcbf5f37b9dc5844153cfe39432933a47e1f890b121b78372e5cdedbc5afc
|
data/Gemfile.lock
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
PATH
|
|
2
2
|
remote: .
|
|
3
3
|
specs:
|
|
4
|
-
hot-glue (0.
|
|
4
|
+
hot-glue (0.2.2)
|
|
5
5
|
ffaker (~> 2.16)
|
|
6
6
|
haml-rails (~> 2.0)
|
|
7
7
|
kaminari (~> 1.2)
|
|
8
|
-
rails (
|
|
8
|
+
rails (> 5.1, <= 7.0.0)
|
|
9
9
|
sass-rails
|
|
10
10
|
turbo-rails (~> 0.5)
|
|
11
11
|
|
|
@@ -74,9 +74,9 @@ GEM
|
|
|
74
74
|
bcrypt (3.1.16)
|
|
75
75
|
builder (3.2.4)
|
|
76
76
|
byebug (11.1.3)
|
|
77
|
-
concurrent-ruby (1.1.
|
|
77
|
+
concurrent-ruby (1.1.9)
|
|
78
78
|
crass (1.0.6)
|
|
79
|
-
devise (4.
|
|
79
|
+
devise (4.8.0)
|
|
80
80
|
bcrypt (~> 3.0)
|
|
81
81
|
orm_adapter (~> 0.1)
|
|
82
82
|
railties (>= 4.1.0)
|
|
@@ -84,11 +84,11 @@ GEM
|
|
|
84
84
|
warden (~> 1.2.3)
|
|
85
85
|
erubi (1.10.0)
|
|
86
86
|
erubis (2.7.0)
|
|
87
|
-
ffaker (2.
|
|
88
|
-
ffi (1.15.
|
|
87
|
+
ffaker (2.19.0)
|
|
88
|
+
ffi (1.15.4)
|
|
89
89
|
globalid (0.4.2)
|
|
90
90
|
activesupport (>= 4.2.0)
|
|
91
|
-
haml (5.2.
|
|
91
|
+
haml (5.2.2)
|
|
92
92
|
temple (>= 0.8.0)
|
|
93
93
|
tilt
|
|
94
94
|
haml-rails (2.0.1)
|
|
@@ -102,7 +102,7 @@ GEM
|
|
|
102
102
|
haml (>= 4.0, < 6)
|
|
103
103
|
nokogiri (>= 1.6.0)
|
|
104
104
|
ruby_parser (~> 3.5)
|
|
105
|
-
i18n (1.8.
|
|
105
|
+
i18n (1.8.10)
|
|
106
106
|
concurrent-ruby (~> 1.0)
|
|
107
107
|
kaminari (1.2.1)
|
|
108
108
|
activesupport (>= 4.1.0)
|
|
@@ -116,7 +116,7 @@ GEM
|
|
|
116
116
|
activerecord
|
|
117
117
|
kaminari-core (= 1.2.1)
|
|
118
118
|
kaminari-core (1.2.1)
|
|
119
|
-
loofah (2.
|
|
119
|
+
loofah (2.10.0)
|
|
120
120
|
crass (~> 1.0.2)
|
|
121
121
|
nokogiri (>= 1.5.9)
|
|
122
122
|
mail (2.7.1)
|
|
@@ -124,12 +124,14 @@ GEM
|
|
|
124
124
|
marcel (0.3.3)
|
|
125
125
|
mimemagic (~> 0.3.2)
|
|
126
126
|
method_source (1.0.0)
|
|
127
|
-
mimemagic (0.3.
|
|
128
|
-
|
|
129
|
-
|
|
127
|
+
mimemagic (0.3.10)
|
|
128
|
+
nokogiri (~> 1)
|
|
129
|
+
rake
|
|
130
|
+
mini_mime (1.1.0)
|
|
131
|
+
mini_portile2 (2.5.3)
|
|
130
132
|
minitest (5.14.4)
|
|
131
133
|
nio4r (2.5.7)
|
|
132
|
-
nokogiri (1.11.
|
|
134
|
+
nokogiri (1.11.7)
|
|
133
135
|
mini_portile2 (~> 2.5.0)
|
|
134
136
|
racc (~> 1.4)
|
|
135
137
|
orm_adapter (0.5.0)
|
|
@@ -167,8 +169,8 @@ GEM
|
|
|
167
169
|
responders (3.0.1)
|
|
168
170
|
actionpack (>= 5.0)
|
|
169
171
|
railties (>= 5.0)
|
|
170
|
-
ruby_parser (3.
|
|
171
|
-
sexp_processor (~> 4.
|
|
172
|
+
ruby_parser (3.17.0)
|
|
173
|
+
sexp_processor (~> 4.15, >= 4.15.1)
|
|
172
174
|
sass-rails (6.0.0)
|
|
173
175
|
sassc-rails (~> 2.1, >= 2.1.1)
|
|
174
176
|
sassc (2.4.0)
|
|
@@ -179,7 +181,7 @@ GEM
|
|
|
179
181
|
sprockets (> 3.0)
|
|
180
182
|
sprockets-rails
|
|
181
183
|
tilt
|
|
182
|
-
sexp_processor (4.15.
|
|
184
|
+
sexp_processor (4.15.3)
|
|
183
185
|
sprockets (4.0.2)
|
|
184
186
|
concurrent-ruby (~> 1.0)
|
|
185
187
|
rack (> 1, < 3)
|
|
@@ -191,18 +193,19 @@ GEM
|
|
|
191
193
|
temple (0.8.2)
|
|
192
194
|
thor (1.1.0)
|
|
193
195
|
tilt (2.0.10)
|
|
194
|
-
turbo-rails (0.
|
|
196
|
+
turbo-rails (0.7.11)
|
|
195
197
|
rails (>= 6.0.0)
|
|
196
198
|
tzinfo (2.0.4)
|
|
197
199
|
concurrent-ruby (~> 1.0)
|
|
198
200
|
warden (1.2.9)
|
|
199
201
|
rack (>= 2.0.9)
|
|
200
|
-
websocket-driver (0.7.
|
|
202
|
+
websocket-driver (0.7.5)
|
|
201
203
|
websocket-extensions (>= 0.1.0)
|
|
202
204
|
websocket-extensions (0.1.5)
|
|
203
205
|
zeitwerk (2.4.2)
|
|
204
206
|
|
|
205
207
|
PLATFORMS
|
|
208
|
+
-darwin-20
|
|
206
209
|
ruby
|
|
207
210
|
|
|
208
211
|
DEPENDENCIES
|
|
@@ -213,4 +216,4 @@ DEPENDENCIES
|
|
|
213
216
|
sqlite3
|
|
214
217
|
|
|
215
218
|
BUNDLED WITH
|
|
216
|
-
2.
|
|
219
|
+
2.2.19
|
data/README.md
CHANGED
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
# Hot Glue
|
|
2
1
|
|
|
3
2
|
Hot Glue is a Rails scaffold builder for the Turbo era. It is an evolution of the admin-interface style scaffolding systems of the 2010s ([activeadmin](https://github.com/activeadmin/activeadmin), [rails_admin](https://github.com/sferik/rails_admin), and [active_scaffold](https://github.com/activescaffold/active_scaffold)).
|
|
4
3
|
|
|
@@ -64,17 +63,17 @@ Instantly get a simple CRUD interface
|
|
|
64
63
|
```
|
|
65
64
|
|
|
66
65
|
- Rspec setup
|
|
67
|
-
add `gem 'rspec-rails'` to your gemfile inside :development and :test
|
|
68
|
-
add `gem 'factory_bot_rails'` to your gemfile inside :development and :test
|
|
69
|
-
run `rails generate rspec:install`
|
|
70
|
-
configure Rspec to work with Factory Bot inside of `rails_helper.rb`
|
|
66
|
+
- add `gem 'rspec-rails'` to your gemfile inside :development and :test
|
|
67
|
+
- add `gem 'factory_bot_rails'` to your gemfile inside :development and :test
|
|
68
|
+
- run `rails generate rspec:install`
|
|
69
|
+
- configure Rspec to work with Factory Bot inside of `rails_helper.rb`
|
|
71
70
|
```
|
|
72
71
|
RSpec.configure do |config|
|
|
73
72
|
// ... more rspec configuration (not shown)
|
|
74
73
|
config.include FactoryBot::Syntax::Methods
|
|
75
74
|
end
|
|
76
75
|
```
|
|
77
|
-
|
|
76
|
+
more info:
|
|
78
77
|
https://github.com/thoughtbot/factory_bot/blob/master/GETTING_STARTED.md#rspec
|
|
79
78
|
|
|
80
79
|
- for a quick Capybara login, create a support helper in `spec/support/` and log-in as your user
|
|
@@ -89,10 +88,13 @@ Instantly get a simple CRUD interface
|
|
|
89
88
|
end
|
|
90
89
|
```
|
|
91
90
|
|
|
92
|
-
- Install Bootstrap
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
91
|
+
- Install Bootstrap
|
|
92
|
+
- Bootstrap with Sprockets (Rails 5 or 7 default — Rails 6 custom)
|
|
93
|
+
- use twbs/bootstrap-rubygem gem
|
|
94
|
+
- see README for bootstrap-rubygem to install
|
|
95
|
+
|
|
96
|
+
Bootstrap with Webpack RAILS 6 ONLY:
|
|
97
|
+
- change `stylesheet_link_tag` to `stylesheet_pack_tag` in your application layout
|
|
96
98
|
- run `yarn add bootstrap`
|
|
97
99
|
- create a new file at `app/javascript/require_bootstrap.scss` with this content
|
|
98
100
|
```
|
|
@@ -103,11 +105,12 @@ Bootstrap with Webpack:
|
|
|
103
105
|
```
|
|
104
106
|
import 'require_bootstrap'
|
|
105
107
|
```
|
|
106
|
-
|
|
107
|
-
Bootstrap with Sprockets:
|
|
108
|
-
- use bootstrap-rubygem gem
|
|
109
|
-
- see README for bootstrap-rubygem to install
|
|
110
108
|
|
|
109
|
+
Bootstrap with Webpack for FOR RAILS 7 :
|
|
110
|
+
-- See this BLOG POST
|
|
111
|
+
https://jasonfleetwoodboldt.com/stepping-up-rails/rails-7-with-webpacker-and-bootstrap/
|
|
112
|
+
|
|
113
|
+
|
|
111
114
|
|
|
112
115
|
- Install Devise or implement your own authentication
|
|
113
116
|
(or only use --gd mode, see below)
|
|
@@ -318,6 +321,12 @@ end
|
|
|
318
321
|
|
|
319
322
|
```
|
|
320
323
|
|
|
324
|
+
|
|
325
|
+
### `--markup` (default: 'erb')
|
|
326
|
+
|
|
327
|
+
ERB is default. For HAML, `--markup=haml`.
|
|
328
|
+
|
|
329
|
+
|
|
321
330
|
## FLAGS (Options with no values)
|
|
322
331
|
These options (flags) also uses `--` syntax but do not take any values. Everything is assumed (default) to be false unless specified.
|
|
323
332
|
|
|
@@ -353,8 +362,15 @@ If you do not want inline editing of your list items but instead to fall back to
|
|
|
353
362
|
|
|
354
363
|
|
|
355
364
|
# VERSION HISTORY
|
|
365
|
+
#### 2021-09-20 - v0.2.1 - Fixes nesting behavior when using gd option
|
|
366
|
+
|
|
367
|
+
#### 2021-09-06 - v0.2.0 - ERB or HAML; use the option --markup=erb or --markup=haml (default is now erb)
|
|
368
|
+
|
|
369
|
+
#### 2021-06-28 - v0.1.2 - fixes problem with namespaces on path helpers
|
|
370
|
+
|
|
371
|
+
#### 2021-05-09 (yanked) - v0.1.1 - add cancellation buttons
|
|
356
372
|
|
|
357
|
-
#### 2021-04-28 - v0.1.0 - Very
|
|
373
|
+
#### 2021-04-28 - v0.1.0 - Very pleased to introduce full behavior specs, found in specs/system/, generated by default on all build code; also many fixes involving nesting and authentication"
|
|
358
374
|
|
|
359
375
|
#### 2021-03-24 - v0.0.9 - fixes in the automatic field label detection; cleans up junk in spec output
|
|
360
376
|
|
|
@@ -378,15 +394,16 @@ If you do not want inline editing of your list items but instead to fall back to
|
|
|
378
394
|
|
|
379
395
|
|
|
380
396
|
|
|
381
|
-
|
|
382
|
-
|
|
383
397
|
# HOW THIS GEM IS TESTED
|
|
384
398
|
|
|
385
|
-
|
|
399
|
+
SETUP:
|
|
400
|
+
• Run bundle install
|
|
401
|
+
• if you can't get through see https://stackoverflow.com/questions/68050807/gem-install-mimemagic-v-0-3-10-fails-to-install-on-big-sur/68170982#68170982
|
|
402
|
+
|
|
386
403
|
|
|
387
404
|
The dummy sandbox is found at `spec/dummy`
|
|
388
405
|
|
|
389
|
-
The dummy lives as mostly checked- into the repository, except the folders where the generated code goes (`spec/dummy/app/views/`, `spec/dummy/app/controllers/`, `spec/dummy/specs/` are excluded from Git)
|
|
406
|
+
The dummy sandbox lives as mostly checked- into the repository, **except** the folders where the generated code goes (`spec/dummy/app/views/`, `spec/dummy/app/controllers/`, `spec/dummy/specs/` are excluded from Git)
|
|
390
407
|
|
|
391
408
|
When you run the **internal specs**, which you can do **at the root of this repo** using the command `rspec`, a set of specs will run to assert the generators are erroring when they are supposed to and producing code when they are supposed to.
|
|
392
409
|
|
|
@@ -10,8 +10,6 @@ module HotGlue
|
|
|
10
10
|
|
|
11
11
|
def initialize(*args) #:nodoc:
|
|
12
12
|
super
|
|
13
|
-
# copy_file "hot_glue.js", "#{'spec/dummy/' if Rails.env.test?}app/javascript/hot_glue.js"
|
|
14
|
-
# copy_file "hot_glue.scss", "#{'spec/dummy/' if Rails.env.test?}app/assets/stylesheets/hot_glue.scss"
|
|
15
13
|
copy_file "_flash_notices.haml", "#{'spec/dummy/' if Rails.env.test?}app/views/layouts/_flash_notices.haml"
|
|
16
14
|
end
|
|
17
15
|
end
|
|
@@ -0,0 +1,227 @@
|
|
|
1
|
+
module HotGlue
|
|
2
|
+
class ErbTemplate < TemplateBase
|
|
3
|
+
|
|
4
|
+
# include GeneratorHelper
|
|
5
|
+
attr_accessor :singular
|
|
6
|
+
|
|
7
|
+
def field_output(col, type = nil, width, col_identifier )
|
|
8
|
+
"<div class='col form-group <%='alert-danger' if @#{singular}.errors.details.keys.include?(:#{col.to_s})%>' > \n" +
|
|
9
|
+
" <%= f.text_field :#{col.to_s}, value: @#{@singular}.#{col.to_s}, size: #{width}, class: 'form-control', type: '#{type}' %>\n "+
|
|
10
|
+
" <label class='form-text' >#{col.to_s.humanize}</label>\n" +
|
|
11
|
+
"</div>"
|
|
12
|
+
end
|
|
13
|
+
|
|
14
|
+
def list_column_headings(*args)
|
|
15
|
+
columns = args[0][:columns]
|
|
16
|
+
|
|
17
|
+
columns.map(&:to_s).map{|col_name| "<div class='col'>#{col_name.humanize}</div>"}.join("\n")
|
|
18
|
+
end
|
|
19
|
+
|
|
20
|
+
|
|
21
|
+
def all_form_fields(*args)
|
|
22
|
+
|
|
23
|
+
columns = args[0][:columns]
|
|
24
|
+
show_only = args[0][:show_only]
|
|
25
|
+
singular_class = args[0][:singular_class]
|
|
26
|
+
|
|
27
|
+
# TODO: CLEAN ME
|
|
28
|
+
@singular = args[0][:singular]
|
|
29
|
+
singular = @singular
|
|
30
|
+
|
|
31
|
+
|
|
32
|
+
col_identifier = "col"
|
|
33
|
+
col_spaces_prepend = " "
|
|
34
|
+
|
|
35
|
+
res = columns.map { |col|
|
|
36
|
+
|
|
37
|
+
if show_only.include?(col)
|
|
38
|
+
|
|
39
|
+
"#{col_identifier}{class: \"form-group <%= 'alert-danger' if #{singular}.errors.details.keys.include?(:#{col.to_s}) %> \"}
|
|
40
|
+
= @#{singular}.#{col.to_s}
|
|
41
|
+
%label.form-text
|
|
42
|
+
#{col.to_s.humanize}\n"
|
|
43
|
+
else
|
|
44
|
+
|
|
45
|
+
|
|
46
|
+
type = eval("#{singular_class}.columns_hash['#{col}']").type
|
|
47
|
+
limit = eval("#{singular_class}.columns_hash['#{col}']").limit
|
|
48
|
+
sql_type = eval("#{singular_class}.columns_hash['#{col}']").sql_type
|
|
49
|
+
|
|
50
|
+
case type
|
|
51
|
+
when :integer
|
|
52
|
+
# look for a belongs_to on this object
|
|
53
|
+
if col.to_s.ends_with?("_id")
|
|
54
|
+
assoc_name = col.to_s.gsub("_id","")
|
|
55
|
+
assoc = eval("#{singular_class}.reflect_on_association(:#{assoc_name})")
|
|
56
|
+
if assoc.nil?
|
|
57
|
+
exit_message= "*** Oops. on the #{singular_class} object, there doesn't seem to be an association called '#{assoc_name}'"
|
|
58
|
+
exit
|
|
59
|
+
end
|
|
60
|
+
display_column = HotGlue.derrive_reference_name(assoc.class_name)
|
|
61
|
+
|
|
62
|
+
"<div class='#{col_identifier} form-group <%= 'alert-danger' if #{singular}.errors.details.keys.include?(:#{assoc_name.to_s}) %>' >
|
|
63
|
+
<%= f.collection_select(:#{col.to_s}, #{assoc.class_name}.all, :id, :#{display_column}, {prompt: true, selected: @#{singular}.#{col.to_s} }, class: 'form-control') %>
|
|
64
|
+
<label class='small form-text text-muted'>#{col.to_s.humanize}</label></div>"
|
|
65
|
+
|
|
66
|
+
else
|
|
67
|
+
"<div class=\"#{col_identifier} form-group <%= 'alert-danger' if #{singular}.errors.details.keys.include?(:#{col}) %> \" >
|
|
68
|
+
<%= f.text_field :#{col.to_s}, value: #{singular}.#{col.to_s}, class: 'form-control', size: 4, type: 'number' %>
|
|
69
|
+
<label class='small form-text text-muted'>#{col.to_s.humanize}</label></div>"
|
|
70
|
+
|
|
71
|
+
end
|
|
72
|
+
when :string
|
|
73
|
+
limit ||= 256
|
|
74
|
+
if limit <= 256
|
|
75
|
+
field_output(col, nil, limit, col_identifier)
|
|
76
|
+
else
|
|
77
|
+
text_area_output(col, limit, col_identifier)
|
|
78
|
+
end
|
|
79
|
+
|
|
80
|
+
when :text
|
|
81
|
+
limit ||= 256
|
|
82
|
+
if limit <= 256
|
|
83
|
+
field_output(col, nil, limit, col_identifier)
|
|
84
|
+
else
|
|
85
|
+
text_area_output(col, limit, col_identifier)
|
|
86
|
+
end
|
|
87
|
+
when :float
|
|
88
|
+
limit ||= 256
|
|
89
|
+
field_output(col, nil, limit, col_identifier)
|
|
90
|
+
|
|
91
|
+
|
|
92
|
+
when :datetime
|
|
93
|
+
|
|
94
|
+
|
|
95
|
+
"<div class='col form-group <%='alert-danger' if @#{singular}.errors.details.keys.include?(:#{col.to_s})%>' > \n" +
|
|
96
|
+
"<%= datetime_field_localized(f, :#{col.to_s}, #{singular}.#{col.to_s}, '#{ col.to_s.humanize }', #{@auth ? @auth+'.timezone' : 'nil'}) %>" +
|
|
97
|
+
"</div>"
|
|
98
|
+
when :date
|
|
99
|
+
"<div class='col form-group <%='alert-danger' if @#{singular}.errors.details.keys.include?(:#{col.to_s})%>' > \n" +
|
|
100
|
+
"<%= date_field_localized(f, :#{col.to_s}, #{singular}.#{col.to_s}, '#{ col.to_s.humanize }', #{@auth ? @auth+'.timezone' : 'nil'}) %>" +
|
|
101
|
+
"</div>"
|
|
102
|
+
when :time
|
|
103
|
+
"<div class='col form-group <%='alert-danger' if @#{singular}.errors.details.keys.include?(:#{col.to_s})%>' > \n" +
|
|
104
|
+
"<%= time_field_localized(f, :#{col.to_s}, #{singular}.#{col.to_s}, '#{ col.to_s.humanize }', #{@auth ? @auth+'.timezone' : 'nil'}) %>" +
|
|
105
|
+
"</div>"
|
|
106
|
+
|
|
107
|
+
when :boolean
|
|
108
|
+
"<div class='col form-group <%='alert-danger' if @#{singular}.errors.details.keys.include?(:#{col.to_s})%>' > \n" +
|
|
109
|
+
" <span>#{col.to_s.humanize}</span>" +
|
|
110
|
+
" <%= f.radio_button(:#{col.to_s}, '0', checked: #{singular}.#{col.to_s} ? '' : 'checked') %>\n" +
|
|
111
|
+
" <%= f.label(:#{col.to_s}, value: 'No', for: '#{singular}_#{col.to_s}_0') %>\n" +
|
|
112
|
+
" <%= f.radio_button(:#{col.to_s}, '1', checked: #{singular}.#{col.to_s} ? 'checked' : '') %>\n" +
|
|
113
|
+
" <%= f.label(:#{col.to_s}, value: 'Yes', for: '#{singular}_#{col.to_s}_1') %>\n" +
|
|
114
|
+
"</div>"
|
|
115
|
+
end
|
|
116
|
+
end
|
|
117
|
+
}.join("\n")
|
|
118
|
+
return res
|
|
119
|
+
end
|
|
120
|
+
|
|
121
|
+
|
|
122
|
+
|
|
123
|
+
def paginate(*args)
|
|
124
|
+
plural = args[0][:plural]
|
|
125
|
+
|
|
126
|
+
"<% if #{plural}.respond_to?(:total_pages) %><%= paginate(#{plural}) %> <% end %>"
|
|
127
|
+
end
|
|
128
|
+
|
|
129
|
+
def all_line_fields(*args)
|
|
130
|
+
columns = args[0][:columns]
|
|
131
|
+
show_only = args[0][:show_only]
|
|
132
|
+
singular_class = args[0][:singular_class]
|
|
133
|
+
singular = args[0][:singular]
|
|
134
|
+
|
|
135
|
+
columns_count = columns.count + 1
|
|
136
|
+
perc_width = (100/columns_count).floor
|
|
137
|
+
|
|
138
|
+
col_identifer = "col"
|
|
139
|
+
columns.map { |col|
|
|
140
|
+
type = eval("#{singular_class}.columns_hash['#{col}']").type
|
|
141
|
+
limit = eval("#{singular_class}.columns_hash['#{col}']").limit
|
|
142
|
+
sql_type = eval("#{singular_class}.columns_hash['#{col}']").sql_type
|
|
143
|
+
|
|
144
|
+
case type
|
|
145
|
+
when :integer
|
|
146
|
+
# look for a belongs_to on this object
|
|
147
|
+
if col.to_s.ends_with?("_id")
|
|
148
|
+
|
|
149
|
+
assoc_name = col.to_s.gsub("_id","")
|
|
150
|
+
|
|
151
|
+
|
|
152
|
+
assoc = eval("#{singular_class}.reflect_on_association(:#{assoc_name})")
|
|
153
|
+
|
|
154
|
+
if assoc.nil?
|
|
155
|
+
exit_message = "*** Oops. on the #{singular_class} object, there doesn't seem to be an association called '#{assoc_name}'"
|
|
156
|
+
raise(HotGlue::Error,exit_message)
|
|
157
|
+
end
|
|
158
|
+
|
|
159
|
+
display_column = HotGlue.derrive_reference_name(assoc.class_name)
|
|
160
|
+
|
|
161
|
+
"<div class='#{col_identifer}'>
|
|
162
|
+
<%= #{singular}.#{assoc.name.to_s}.try(:#{display_column}) || '<span class=\"content alert-danger\">MISSING</span>'.html_safe %>
|
|
163
|
+
</div>"
|
|
164
|
+
|
|
165
|
+
else
|
|
166
|
+
"<div class='#{col_identifer}'>
|
|
167
|
+
<%= #{singular}.#{col}%></div>"
|
|
168
|
+
end
|
|
169
|
+
when :float
|
|
170
|
+
width = (limit && limit < 40) ? limit : (40)
|
|
171
|
+
"#{col_identifer}
|
|
172
|
+
= #{singular}.#{col}"
|
|
173
|
+
|
|
174
|
+
when :string
|
|
175
|
+
width = (limit && limit < 40) ? limit : (40)
|
|
176
|
+
"<div class='#{col_identifer}'>
|
|
177
|
+
<%= #{singular}.#{col} %>
|
|
178
|
+
</div>"
|
|
179
|
+
when :text
|
|
180
|
+
"<div class='#{col_identifer}'>
|
|
181
|
+
<%= #{singular}.#{col} %>
|
|
182
|
+
</div>"
|
|
183
|
+
when :datetime
|
|
184
|
+
|
|
185
|
+
"<div class='#{col_identifer}'>
|
|
186
|
+
<% unless #{singular}.#{col}.nil? %>
|
|
187
|
+
<%= #{singular}.#{col}.in_time_zone(current_timezone).strftime('%m/%d/%Y @ %l:%M %p ') + timezonize(current_timezone) %>
|
|
188
|
+
<% else %>
|
|
189
|
+
<span class='alert-danger'>MISSING</span>
|
|
190
|
+
<% end %>
|
|
191
|
+
</div>"
|
|
192
|
+
when :date
|
|
193
|
+
"<div class='#{col_identifer}'>
|
|
194
|
+
<% unless #{singular}.#{col}.nil? %>
|
|
195
|
+
<%= #{singular}.#{col} %>
|
|
196
|
+
<% else %>
|
|
197
|
+
<span class='alert-danger'>MISSING</span>
|
|
198
|
+
<% end %>
|
|
199
|
+
</div>"
|
|
200
|
+
when :time
|
|
201
|
+
"<div class='#{col_identifer}'>
|
|
202
|
+
<% unless #{singular}.#{col}.nil? %>
|
|
203
|
+
<%= #{singular}.#{col}.in_time_zone(current_timezone).strftime('%l:%M %p ') + timezonize(current_timezone) %>
|
|
204
|
+
<% else %>
|
|
205
|
+
<span class='alert-danger'>MISSING</span>
|
|
206
|
+
<% end %>
|
|
207
|
+
</div>
|
|
208
|
+
"
|
|
209
|
+
when :boolean
|
|
210
|
+
"<div class='#{col_identifer}'>
|
|
211
|
+
<% if #{singular}.#{col}.nil? %>
|
|
212
|
+
<span class='alert-danger'>MISSING</span>
|
|
213
|
+
<% elsif #{singular}.#{col} %>
|
|
214
|
+
YES
|
|
215
|
+
<% else %>
|
|
216
|
+
NO
|
|
217
|
+
<% end %>
|
|
218
|
+
</div>
|
|
219
|
+
"
|
|
220
|
+
end #end of switch
|
|
221
|
+
}.join("\n")
|
|
222
|
+
end
|
|
223
|
+
end
|
|
224
|
+
|
|
225
|
+
|
|
226
|
+
|
|
227
|
+
end
|