hot-glue 0.0.8 → 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (52) hide show
  1. checksums.yaml +4 -4
  2. data/.github/FUNDING.yml +1 -1
  3. data/Gemfile.lock +21 -18
  4. data/README.md +84 -50
  5. data/app/helpers/hot_glue/controller_helper.rb +1 -1
  6. data/db/migrate/20210306223305_create_ghis.rb +9 -0
  7. data/db/schema.rb +1 -1
  8. data/lib/generators/hot_glue/install_generator.rb +0 -2
  9. data/lib/generators/hot_glue/markup_templates/base.rb +7 -0
  10. data/lib/generators/hot_glue/markup_templates/erb.rb +228 -0
  11. data/lib/generators/hot_glue/markup_templates/haml.rb +223 -0
  12. data/lib/generators/hot_glue/markup_templates/slim.rb +9 -0
  13. data/lib/generators/hot_glue/scaffold_generator.rb +172 -280
  14. data/lib/generators/hot_glue/templates/controller.rb.erb +12 -10
  15. data/lib/generators/hot_glue/templates/erb/_errors.erb +11 -0
  16. data/lib/generators/hot_glue/templates/erb/_flash_notices.erb +12 -0
  17. data/lib/generators/hot_glue/templates/erb/_form.erb +8 -0
  18. data/lib/generators/hot_glue/templates/erb/_line.erb +10 -0
  19. data/lib/generators/hot_glue/templates/erb/_list.erb +19 -0
  20. data/lib/generators/hot_glue/templates/erb/_new_button.erb +3 -0
  21. data/lib/generators/hot_glue/templates/erb/_new_form.erb +8 -0
  22. data/lib/generators/hot_glue/templates/erb/_show.erb +8 -0
  23. data/lib/generators/hot_glue/templates/erb/create.turbo_stream.erb +18 -0
  24. data/lib/generators/hot_glue/templates/erb/destroy.turbo_stream.erb +3 -0
  25. data/lib/generators/hot_glue/templates/erb/edit.erb +30 -0
  26. data/lib/generators/hot_glue/templates/erb/edit.turbo_stream.erb +3 -0
  27. data/lib/generators/hot_glue/templates/erb/index.erb +10 -0
  28. data/lib/generators/hot_glue/templates/erb/new.erb +1 -0
  29. data/lib/generators/hot_glue/templates/erb/update.turbo_stream.erb +10 -0
  30. data/lib/generators/hot_glue/templates/{_errors.haml → haml/_errors.haml} +0 -0
  31. data/lib/generators/hot_glue/templates/{_flash_notices.haml → haml/_flash_notices.haml} +0 -0
  32. data/lib/generators/hot_glue/templates/{_form.haml → haml/_form.haml} +1 -0
  33. data/lib/generators/hot_glue/templates/{_line.haml → haml/_line.haml} +0 -0
  34. data/lib/generators/hot_glue/templates/{_list.haml → haml/_list.haml} +0 -0
  35. data/lib/generators/hot_glue/templates/{_new_button.haml → haml/_new_button.haml} +0 -0
  36. data/lib/generators/hot_glue/templates/{_new_form.haml → haml/_new_form.haml} +0 -3
  37. data/lib/generators/hot_glue/templates/haml/_show.haml +7 -0
  38. data/lib/generators/hot_glue/templates/{create.turbo_stream.haml → haml/create.turbo_stream.haml} +0 -0
  39. data/lib/generators/hot_glue/templates/{destroy.turbo_stream.haml → haml/destroy.turbo_stream.haml} +0 -0
  40. data/lib/generators/hot_glue/templates/{edit.haml → haml/edit.haml} +0 -0
  41. data/lib/generators/hot_glue/templates/{edit.turbo_stream.haml → haml/edit.turbo_stream.haml} +0 -0
  42. data/lib/generators/hot_glue/templates/{index.haml → haml/index.haml} +0 -0
  43. data/lib/generators/hot_glue/templates/{new.haml → haml/new.haml} +0 -0
  44. data/lib/generators/hot_glue/templates/haml/update.turbo_stream.haml +9 -0
  45. data/lib/generators/hot_glue/templates/system_spec.rb.erb +115 -76
  46. data/lib/hot-glue.rb +6 -20
  47. data/lib/hotglue/version.rb +1 -1
  48. metadata +45 -27
  49. data/db/migrate/20210306223305_create_hgis.rb +0 -9
  50. data/lib/generators/hot_glue/templates/_show.haml +0 -7
  51. data/lib/generators/hot_glue/templates/request_spec.rb.erb +0 -110
  52. data/lib/generators/hot_glue/templates/update.turbo_stream.haml +0 -5
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: ae1088aa0a809a10fb6332fa7ca062e1af6aa39a1c8541dabdf4d8451c5ba04d
4
- data.tar.gz: a3ff6d5d8a171e1d1d361df692f6255f855720609e692c21573d6311fbeb41e2
3
+ metadata.gz: 81ca38b1bfb68e173a1665d924729b04afa26ccda900d707508a64e01977f1ad
4
+ data.tar.gz: 8d2b98c07d84ec264600d79f5073139ea717a3b66488b5b269a4466bc5eb04be
5
5
  SHA512:
6
- metadata.gz: f65f042a47123cb7a7f69222ddf6618ca085f8cb38bf372179f3bb3da6e47fb07cb383ecba4e0c22642d775db004c0ab111fc99667f575fde62869f7d4c4efba
7
- data.tar.gz: e6c36f5bb8a516ee2e74250000174eede61f39c38c46fb74ac963cfa958ac2c5ba2bd3323832b1359ef452e532b7e01b24e04ff68bb67b28df781ccf04e958a4
6
+ metadata.gz: 4525044b21596dd6dc96d7aa397402421459ec483749df04dd08ad3f20de7a6a1998e38b9436d77522c48dedabb78a3b4e9e88ce2225e2c8633b8c32a30fa8a8
7
+ data.tar.gz: 06d16a32919eb23b306add1ca5e1997694f0bbbb21d0bc045992530b2963cf65f6dbb987fb3223b50a1e543598e1f42611f17b80b206fb032d2c00d8ddb72eb9
data/.github/FUNDING.yml CHANGED
@@ -1,2 +1,2 @@
1
1
  github: [jasonfb]
2
- custom: ["https://jfb.teachable.com"]
2
+ custom: ["https://www.instagram.com/jfbcodes/"]
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- hot-glue (0.0.7)
4
+ hot-glue (0.2.0)
5
5
  ffaker (~> 2.16)
6
6
  haml-rails (~> 2.0)
7
7
  kaminari (~> 1.2)
@@ -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.8)
77
+ concurrent-ruby (1.1.9)
78
78
  crass (1.0.6)
79
- devise (4.7.3)
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.18.0)
88
- ffi (1.14.2)
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.1)
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.9)
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.9.0)
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.5)
128
- mini_mime (1.0.2)
129
- mini_portile2 (2.5.0)
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.1)
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.15.1)
171
- sexp_processor (~> 4.9)
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.2)
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.5.9)
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.3)
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.1.4
219
+ 2.2.19
data/README.md CHANGED
@@ -1,77 +1,117 @@
1
- # Hot Glue
2
1
 
3
- Hot Glue is an evolution of the best of the admin-style scaffold builders 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) being the most popular of those). It harnesses the power of Rails 6, Turbo-Rails, and Hotwire to deliver a lightning fast experience.
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
 
5
- As well, its premise is a little different than the configuration-heavy admin interface toolkits. It will read your relationships and field types to generate your code for you, leaving you with a 'sourdough starter' to work from. If you modify the generated code, you're on your own if you want to preserve your changes and also re-generate scaffold after adding fields.
4
+ Using Turbo-Rails and Hotwire you get a lightning-fast out-of-the-box CRUD building experience. Every page displays only a list view: new and edit operations happen as 'edit-in-place', so the user never leaves the page.
6
5
 
7
- It gives users full control over objects they 'own' and by default it spits out functionality giving access to all fields.
6
+ It will read your relationships and field types to generate your code for you, leaving you with a 'sourdough starter' to work from. If you modify the generated code, you're on your own if you want to preserve your changes and also re-generate scaffold after adding fields.
8
7
 
9
- Hot Glue generates functionality that's quick and dirty. It let's you be crafty. As with a real glue gun, take care not to burn yourself while using it.
8
+ By default, it generates code that gives users full control over objects they 'own' and by default it spits out functionality giving access to all fields.
10
9
 
11
- * Build plug-and-play scaffolding mixing HAML and turbo_stream responses
12
- * Automatically Reads Your Models (make them before building your scaffolding!)
13
- * CRUD, lists with pagination, (coming soon: sorting & searching)
14
- * Wonderful for prototyping.
15
- * Nest your routes model-by-model for built-in poor man's authentication.
10
+ Hot Glue generates functionality that's quick and dirty. It let's you be crafty. As with a real hot glue gun, use with caution.
11
+
12
+ * Build plug-and-play scaffolding for any CRUD on any object
13
+ * mixes HAML and turbo_stream responses
14
+ * Everything edits-in-place (unless you use --big-edit, then it won't)
15
+ * Automatically reads your ActiveRecord models and relationships (make them before building your scaffolding!)
16
+ * Create-read-update-delete (CRUD) with pagination (one day: sorting & searching)
17
+ * Excellent tool for prototyping and hackathons, but a knowledge of Rails is needed.
18
+ * Nest your routes model-by-model for built-in poor man's authentication. (Customers have_many :invoices; Invoices have_many :line_items; etc)
16
19
  * Plays nicely with Devise, but you can implement your own current_user object instead.
17
- * Requires & uses Kaminari for pagination.
18
- * Create specs automatically along with the controllers (* rspec only for now).
20
+ * Kaminari for pagination.
21
+ * Create specs automatically along with the controllers.
19
22
  * Throw the scaffolding away when your app is ready to graduate to its next phase (or don't if you like it).
20
23
 
21
- ## QUICK START (COMING SOON)
24
+ ## QUICK START
22
25
 
23
26
  It's really easy to get started by following along with this blog post that creates three simple tables (User, Event, and Format).
24
27
 
25
28
  Feel free to build your own tables when you get to the sections for building the 'Event' scaffold:
26
29
 
27
- https://blog.jasonfleetwoodboldt.com/hot-glue
30
+ https://jasonfleetwoodboldt.com/hot-glue
28
31
 
29
32
  ## HOW EASY?
30
33
 
31
-
32
34
  ```
33
35
  rails generate hot_glue:scaffold Thing
34
36
  ```
35
37
 
38
+ Generate a quick scaffold to manage a table called `pronouns`
39
+ ![hot-glue-3](https://user-images.githubusercontent.com/59002/116405509-bdee2f00-a7fd-11eb-9723-4c6e22f81bd3.gif)
40
+
41
+
42
+
43
+ Instantly get a simple CRUD interface
44
+
45
+ ![hot-glue-4](https://user-images.githubusercontent.com/59002/116405517-c2b2e300-a7fd-11eb-8423-d43e3afc9fa6.gif)
46
+
47
+
36
48
  ## TO INSTALL
37
49
 
38
- - Add Turbo-Rails to your Gemfile & bundle install
50
+ - Add `gem 'turbo-rails'` to your Gemfile & `bundle install`
39
51
 
40
52
  - Then install it with `rails turbo:install`
41
53
 
42
54
  - The Turbo install has switched your action cable settings from 'async' to Redis, so be sure to start a redis server
43
55
 
44
- - Add `hot_glue` to your Gemfile & `bundle install`
56
+ - Add `gem 'hot-glue'` to your Gemfile & `bundle install`
45
57
 
46
- - Then install it with `rails generate hot_glue:install`
58
+ - Run the hot-glue installation with `rails generate hot_glue:install`
47
59
 
48
60
  - Add to your `application.html.erb`
49
61
  ```
50
62
  <%= render partial: 'layouts/flash_notices' %>
51
63
  ```
52
64
 
65
+ - Rspec setup
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`
70
+ ```
71
+ RSpec.configure do |config|
72
+ // ... more rspec configuration (not shown)
73
+ config.include FactoryBot::Syntax::Methods
74
+ end
75
+ ```
76
+ more info:
77
+ https://github.com/thoughtbot/factory_bot/blob/master/GETTING_STARTED.md#rspec
78
+
79
+ - for a quick Capybara login, create a support helper in `spec/support/` and log-in as your user
80
+ ```
81
+ def login_as(account)
82
+ visit '/accounts/sign_in'
83
+ within("#new_account") do
84
+ fill_in 'Email', with: account.email
85
+ fill_in 'Password', with: 'password'
86
+ end
87
+ click_button 'Log in'
88
+ end
89
+ ```
90
+
53
91
  - Install Bootstrap (optional)
54
92
 
55
93
  Bootstrap with Webpack:
56
94
  - change `stylesheet_link_tag` to `stylesheet_pack_tag` in your application layout
57
- - `yarn add bootstrap`
58
- - create a new file at `app/javascript/css/site.scss` with this content
95
+ - run `yarn add bootstrap`
96
+ - create a new file at `app/javascript/require_bootstrap.scss` with this content
59
97
  ```
60
98
  @import "~bootstrap/scss/bootstrap.scss";
61
99
  ```
62
100
 
63
101
  - add to `app/javascript/packs/application.js`
64
102
  ```
65
- import 'css/site'
103
+ import 'require_bootstrap'
66
104
  ```
67
105
 
68
106
  Bootstrap with Sprockets:
69
- - use bootstrap-rails gem
70
-
107
+ - use bootstrap-rubygem gem
108
+ - see README for bootstrap-rubygem to install
109
+
71
110
 
72
111
  - Install Devise or implement your own authentication
112
+ (or only use --gd mode, see below)
73
113
 
74
- - Also recommended: font-awesome-sass
114
+ - font-awesome
75
115
 
76
116
 
77
117
  ### First Argument
@@ -277,6 +317,12 @@ end
277
317
 
278
318
  ```
279
319
 
320
+
321
+ ### `--markup` (default: 'erb')
322
+
323
+ ERB is default. For HAML, `--markup=haml`.
324
+
325
+
280
326
  ## FLAGS (Options with no values)
281
327
  These options (flags) also uses `--` syntax but do not take any values. Everything is assumed (default) to be false unless specified.
282
328
 
@@ -313,6 +359,16 @@ If you do not want inline editing of your list items but instead to fall back to
313
359
 
314
360
  # VERSION HISTORY
315
361
 
362
+ #### 2021-09-06 - v0.2.0 - SLIM and ERB ; use the option --markup=erb or --markup=haml (default is now erb)
363
+
364
+ #### 2021-06-28 - v0.1.2 - fixes problem with namespaces on path helpers
365
+
366
+ #### 2021-05-09 (yanked) - v0.1.1 - add cancellation buttons
367
+
368
+ #### 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"
369
+
370
+ #### 2021-03-24 - v0.0.9 - fixes in the automatic field label detection; cleans up junk in spec output
371
+
316
372
  #### 2021-03-21 - v0.0.8 - show only flag; more specific spec coverage in generator spec
317
373
 
318
374
  #### 2021-03-20 - v0.0.7 - adds lots of spec coverage; cleans up generated cruft code on each run; adds no-delete, no-create; a working --big-edit with basic data-turbo false to disable inline editing
@@ -332,41 +388,19 @@ If you do not want inline editing of your list items but instead to fall back to
332
388
  #### 2021-02-23 - v0.0.0 - Port of my prior work from github.com/jasonfb/common_core_js
333
389
 
334
390
 
335
- # ACKNOWLEDGEMENTS
336
-
337
- ### "POOR MAN"
338
-
339
- I hope one day I will leave this Earth a poor man (like my code) owning only the most simple structure for the simple form of my existence. Thanks for having educated me in this wisdom goes to my former mentor [@trak3r](https://github.com/trak3r)!
340
-
341
-
342
-
343
391
 
344
392
  # HOW THIS GEM IS TESTED
345
393
 
346
- The testing of functionality-within-functionality is a little tricky and requires thinking outside the box.
394
+ SETUP:
395
+ • Run bundle install
396
+ • 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
347
397
 
348
- We have two kinds of "sandboxes": a DUMMY sandbox, and also a STRAWMAN sandbox
349
398
 
350
399
  The dummy sandbox is found at `spec/dummy`
351
400
 
352
- 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)
401
+ 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)
353
402
 
354
403
  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.
355
404
 
356
-
357
405
  The DUMMY testing DOES NOT test the actual functionality of the output code (it just tests the functionality of the generation process).
358
406
 
359
- For this reason, I've also added something I call STRAWMAN testing, which is a set of steps that does these things:
360
-
361
- The Strawman isn't in the repository, but if you build it locally, it will create itself into
362
-
363
- `spec/strawman/`
364
-
365
- 1) Builds you a strawman sandbox app from scratch, using the native `rails new`
366
- 2) Makes a few small modifications to the new app to support this gem
367
- 3) Create two nonsense tables called OmnitableA and OmnitableB. Each omnitable has one of each kind of field (integer, text, string, date, time, etc)
368
- 4) In this way, it is a "Noah's Arc" testing strategy: It will build you a fully functional app using all of the feature sets of the gem.
369
- 5) The built app itself will contain its own specs
370
- 6) You will then cd into `spec/strawman` and run `rspec`. This second test suite now runs to full test all of the *generated* code.
371
-
372
-
@@ -43,7 +43,7 @@ module HotGlue
43
43
  type: 'time',
44
44
  value: date_to_current_timezone(value, timezone))
45
45
 
46
- res << timezonize(tz)
46
+ res << timezonize(timezone)
47
47
  res
48
48
  end
49
49
 
@@ -0,0 +1,9 @@
1
+ class CreateGhis < ActiveRecord::Migration[6.1]
2
+ def change
3
+ create_table :ghis do |t|
4
+ t.integer :def_id
5
+
6
+ t.timestamps
7
+ end
8
+ end
9
+ end
data/db/schema.rb CHANGED
@@ -27,7 +27,7 @@ ActiveRecord::Schema.define(version: 2021_03_06_225506) do
27
27
  t.datetime "updated_at", precision: 6, null: false
28
28
  end
29
29
 
30
- create_table "hgis", force: :cascade do |t|
30
+ create_table "ghis", force: :cascade do |t|
31
31
  t.integer "def_id"
32
32
  t.datetime "created_at", precision: 6, null: false
33
33
  t.datetime "updated_at", precision: 6, null: false
@@ -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,7 @@
1
+ module HotGlue
2
+ class TemplateBase
3
+ def initialize()
4
+ end
5
+
6
+ end
7
+ end
@@ -0,0 +1,228 @@
1
+ module HotGlue
2
+ class ErbTemplate < TemplateBase
3
+
4
+ attr_accessor :singular
5
+
6
+ def field_output(col, type = nil, width, col_identifier )
7
+ "<div class='col form-group <%='alert-danger' if @#{singular}.errors.details.keys.include?(:#{col.to_s})%>' > \n" +
8
+ " <%= f.text_field :#{col.to_s}, value: @#{@singular}.#{col.to_s}, size: #{width}, class: 'form-control', type: '#{type}' %>\n "+
9
+ " <label class='form-text' >#{col.to_s.humanize}</label>\n" +
10
+ "</div>"
11
+ end
12
+
13
+ def list_column_headings(*args)
14
+ columns = args[0][:columns]
15
+
16
+ columns.map(&:to_s).map{|col_name| "<div class='col'>#{col_name.humanize}</div>"}.join("\n")
17
+ end
18
+
19
+
20
+ def all_form_fields(*args)
21
+
22
+ columns = args[0][:columns]
23
+ show_only = args[0][:show_only]
24
+ singular_class = args[0][:singular_class]
25
+
26
+ # TODO: CLEAN ME
27
+ @singular = args[0][:singular]
28
+ singular = @singular
29
+
30
+
31
+ col_identifier = "col"
32
+ col_spaces_prepend = " "
33
+
34
+ res = columns.map { |col|
35
+
36
+ if show_only.include?(col)
37
+
38
+ "#{col_identifier}{class: \"form-group \#{'alert-danger' if #{singular}.errors.details.keys.include?(:#{col.to_s})}\"}
39
+ = @#{singular}.#{col.to_s}
40
+ %label.form-text
41
+ #{col.to_s.humanize}\n"
42
+ else
43
+
44
+
45
+ type = eval("#{singular_class}.columns_hash['#{col}']").type
46
+ limit = eval("#{singular_class}.columns_hash['#{col}']").limit
47
+ sql_type = eval("#{singular_class}.columns_hash['#{col}']").sql_type
48
+
49
+ case type
50
+ when :integer
51
+ # look for a belongs_to on this object
52
+ if col.to_s.ends_with?("_id")
53
+ assoc_name = col.to_s.gsub("_id","")
54
+ assoc = eval("#{singular_class}.reflect_on_association(:#{assoc_name})")
55
+ if assoc.nil?
56
+ exit_message= "*** Oops. on the #{singular_class} object, there doesn't seem to be an association called '#{assoc_name}'"
57
+ exit
58
+ end
59
+ display_column = derrive_reference_name(assoc.class_name)
60
+
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 = derrive_reference_name(assoc.class_name)
160
+
161
+
162
+ "<div class='#{col_identifer}'>
163
+ <%= #{singular}.#{assoc.name.to_s}.try(:#{display_column}) || '<span class=\"content alert-danger\">MISSING</span>'.html_safe %>
164
+ </div>"
165
+
166
+ else
167
+ "<div class='#{col_identifer}'>
168
+ <%= #{singular}.#{col}%></div>"
169
+ end
170
+ when :float
171
+ width = (limit && limit < 40) ? limit : (40)
172
+ "#{col_identifer}
173
+ = #{singular}.#{col}"
174
+
175
+ when :string
176
+ width = (limit && limit < 40) ? limit : (40)
177
+ "<div class='#{col_identifer}'>
178
+ <%= #{singular}.#{col} %>
179
+ </div>"
180
+ when :text
181
+ "<div class='#{col_identifer}'>
182
+ <%= #{singular}.#{col} %>
183
+ </div>"
184
+ when :datetime
185
+
186
+ "<div class='#{col_identifer}'>
187
+ <% unless #{singular}.#{col}.nil? %>
188
+ <%= #{singular}.#{col}.in_time_zone(current_timezone).strftime('%m/%d/%Y @ %l:%M %p ') + timezonize(current_timezone) %>
189
+ <% else %>
190
+ <span class='alert-danger'>MISSING</span>
191
+ <% end %>
192
+ </div>"
193
+ when :date
194
+ "<div class='#{col_identifer}'>
195
+ <% unless #{singular}.#{col}.nil? %>
196
+ <%= #{singular}.#{col} %>
197
+ <% else %>
198
+ <span class='alert-danger'>MISSING</span>
199
+ <% end %>
200
+ </div>"
201
+ when :time
202
+ "<div class='#{col_identifer}'>
203
+ <% unless #{singular}.#{col}.nil? %>
204
+ <%= #{singular}.#{col}.in_time_zone(current_timezone).strftime('%l:%M %p ') + timezonize(current_timezone) %>
205
+ <% else %>
206
+ <span class='alert-danger'>MISSING</span>
207
+ <% end %>
208
+ </div>
209
+ "
210
+ when :boolean
211
+ "<div class='#{col_identifer}'>
212
+ <% if #{singular}.#{col}.nil? %>
213
+ <span class='alert-danger'>MISSING</span>
214
+ <% elsif #{singular}.#{col} %>
215
+ YES
216
+ <% else %>
217
+ NO
218
+ <% end %>
219
+ </div>
220
+ "
221
+ end #end of switch
222
+ }.join("\n")
223
+ end
224
+ end
225
+
226
+
227
+
228
+ end