hot-glue 0.0.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (34) hide show
  1. checksums.yaml +7 -0
  2. data/.github/FUNDING.yml +2 -0
  3. data/.gitignore +16 -0
  4. data/Gemfile +15 -0
  5. data/Gemfile.lock +196 -0
  6. data/LICENCE +13 -0
  7. data/README.md +262 -0
  8. data/Rakefile +32 -0
  9. data/app/helpers/hot_glue/controller_helper.rb +105 -0
  10. data/app/helpers/hot_glue_helper.rb +4 -0
  11. data/bin/rails +14 -0
  12. data/lib/generators/hot_glue/install_generator.rb +21 -0
  13. data/lib/generators/hot_glue/scaffold_generator.rb +674 -0
  14. data/lib/generators/hot_glue/templates/_errors.haml +5 -0
  15. data/lib/generators/hot_glue/templates/_flash_notices.haml +7 -0
  16. data/lib/generators/hot_glue/templates/_form.haml +4 -0
  17. data/lib/generators/hot_glue/templates/_line.haml +6 -0
  18. data/lib/generators/hot_glue/templates/_list.haml +9 -0
  19. data/lib/generators/hot_glue/templates/_new_button.haml +2 -0
  20. data/lib/generators/hot_glue/templates/_show.haml +7 -0
  21. data/lib/generators/hot_glue/templates/base_controller.rb +3 -0
  22. data/lib/generators/hot_glue/templates/controller.rb +125 -0
  23. data/lib/generators/hot_glue/templates/controller_spec.rb +110 -0
  24. data/lib/generators/hot_glue/templates/create.turbo_stream.haml +5 -0
  25. data/lib/generators/hot_glue/templates/destroy.turbo_stream.haml +2 -0
  26. data/lib/generators/hot_glue/templates/edit.haml +19 -0
  27. data/lib/generators/hot_glue/templates/edit.turbo_stream.haml +4 -0
  28. data/lib/generators/hot_glue/templates/index.haml +9 -0
  29. data/lib/generators/hot_glue/templates/new.haml +10 -0
  30. data/lib/generators/hot_glue/templates/update.turbo_stream.haml +5 -0
  31. data/lib/hot-glue.rb +28 -0
  32. data/lib/hotglue/engine.rb +6 -0
  33. data/lib/hotglue/version.rb +3 -0
  34. metadata +178 -0
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 46cd5cd43915874022d96f3342d3cd9b28f7c926c94ea04c29eb8df63152623f
4
+ data.tar.gz: 932672afaa6e13d9a0ebebf3014a3b67e9ec506b7531a23fa9cde4032652bbb8
5
+ SHA512:
6
+ metadata.gz: 7dacdf0e6d3f91883084799025a5dd02a0d1016e55f455a9d9cbf177f1e723cadfc06bd2ddca7f1ad8ecf4e33dec8e3d851689578e123b78cf7a2d8bf2e4a349
7
+ data.tar.gz: ddc83432caf2a0ab52a952fbda552ab11ab8696efcdf967debd05988a699a8b62ceab227c0d4d00df68c204578adb5ab604683fafa4735b44140a616f375a46a
@@ -0,0 +1,2 @@
1
+ github: [jasonfb]
2
+ custom: ["https://jfb.teachable.com"]
data/.gitignore ADDED
@@ -0,0 +1,16 @@
1
+ .bundle/
2
+ log/*.log
3
+ pkg/
4
+ test/dummy/db/*.sqlite3
5
+ test/dummy/db/*.sqlite3-journal
6
+ test/dummy/db/*.sqlite3-*
7
+ test/dummy/log/*.log
8
+ test/dummy/storage/
9
+ test/dummy/tmp/
10
+ .byebug_history
11
+
12
+ .idea/
13
+ *.gem
14
+ .DS_Store
15
+
16
+ dump.rdb
data/Gemfile ADDED
@@ -0,0 +1,15 @@
1
+ source 'https://rubygems.org'
2
+ git_source(:github) { |repo| "https://github.com/#{repo}.git" }
3
+
4
+ # Declare your gem's dependencies in common_core_js.gemspec.
5
+ # Bundler will treat runtime dependencies like base dependencies, and
6
+ # development dependencies will be added by default to the :development group.
7
+ gemspec
8
+
9
+ # Declare any dependencies that are still in development here instead of in
10
+ # your gemspec. These might include edge Rails or gems from your path or
11
+ # Git. Remember to move these dependencies to your gemspec before releasing
12
+ # your gem to rubygems.org.
13
+
14
+ # To use a debugger
15
+ # gem 'byebug', group: [:development, :test]
data/Gemfile.lock ADDED
@@ -0,0 +1,196 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ hot-glue (0.0.1)
5
+ ffaker (~> 2.16)
6
+ haml-rails (~> 2.0)
7
+ kaminari (~> 1.2)
8
+ rails (~> 6.0)
9
+ sass-rails
10
+
11
+ GEM
12
+ remote: https://rubygems.org/
13
+ specs:
14
+ actioncable (6.1.0)
15
+ actionpack (= 6.1.0)
16
+ activesupport (= 6.1.0)
17
+ nio4r (~> 2.0)
18
+ websocket-driver (>= 0.6.1)
19
+ actionmailbox (6.1.0)
20
+ actionpack (= 6.1.0)
21
+ activejob (= 6.1.0)
22
+ activerecord (= 6.1.0)
23
+ activestorage (= 6.1.0)
24
+ activesupport (= 6.1.0)
25
+ mail (>= 2.7.1)
26
+ actionmailer (6.1.0)
27
+ actionpack (= 6.1.0)
28
+ actionview (= 6.1.0)
29
+ activejob (= 6.1.0)
30
+ activesupport (= 6.1.0)
31
+ mail (~> 2.5, >= 2.5.4)
32
+ rails-dom-testing (~> 2.0)
33
+ actionpack (6.1.0)
34
+ actionview (= 6.1.0)
35
+ activesupport (= 6.1.0)
36
+ rack (~> 2.0, >= 2.0.9)
37
+ rack-test (>= 0.6.3)
38
+ rails-dom-testing (~> 2.0)
39
+ rails-html-sanitizer (~> 1.0, >= 1.2.0)
40
+ actiontext (6.1.0)
41
+ actionpack (= 6.1.0)
42
+ activerecord (= 6.1.0)
43
+ activestorage (= 6.1.0)
44
+ activesupport (= 6.1.0)
45
+ nokogiri (>= 1.8.5)
46
+ actionview (6.1.0)
47
+ activesupport (= 6.1.0)
48
+ builder (~> 3.1)
49
+ erubi (~> 1.4)
50
+ rails-dom-testing (~> 2.0)
51
+ rails-html-sanitizer (~> 1.1, >= 1.2.0)
52
+ activejob (6.1.0)
53
+ activesupport (= 6.1.0)
54
+ globalid (>= 0.3.6)
55
+ activemodel (6.1.0)
56
+ activesupport (= 6.1.0)
57
+ activerecord (6.1.0)
58
+ activemodel (= 6.1.0)
59
+ activesupport (= 6.1.0)
60
+ activestorage (6.1.0)
61
+ actionpack (= 6.1.0)
62
+ activejob (= 6.1.0)
63
+ activerecord (= 6.1.0)
64
+ activesupport (= 6.1.0)
65
+ marcel (~> 0.3.1)
66
+ mimemagic (~> 0.3.2)
67
+ activesupport (6.1.0)
68
+ concurrent-ruby (~> 1.0, >= 1.0.2)
69
+ i18n (>= 1.6, < 2)
70
+ minitest (>= 5.1)
71
+ tzinfo (~> 2.0)
72
+ zeitwerk (~> 2.3)
73
+ builder (3.2.4)
74
+ concurrent-ruby (1.1.8)
75
+ crass (1.0.6)
76
+ erubi (1.10.0)
77
+ erubis (2.7.0)
78
+ ffaker (2.17.0)
79
+ ffi (1.14.2)
80
+ globalid (0.4.2)
81
+ activesupport (>= 4.2.0)
82
+ haml (5.2.1)
83
+ temple (>= 0.8.0)
84
+ tilt
85
+ haml-rails (2.0.1)
86
+ actionpack (>= 5.1)
87
+ activesupport (>= 5.1)
88
+ haml (>= 4.0.6, < 6.0)
89
+ html2haml (>= 1.0.1)
90
+ railties (>= 5.1)
91
+ html2haml (2.2.0)
92
+ erubis (~> 2.7.0)
93
+ haml (>= 4.0, < 6)
94
+ nokogiri (>= 1.6.0)
95
+ ruby_parser (~> 3.5)
96
+ i18n (1.8.9)
97
+ concurrent-ruby (~> 1.0)
98
+ kaminari (1.2.1)
99
+ activesupport (>= 4.1.0)
100
+ kaminari-actionview (= 1.2.1)
101
+ kaminari-activerecord (= 1.2.1)
102
+ kaminari-core (= 1.2.1)
103
+ kaminari-actionview (1.2.1)
104
+ actionview
105
+ kaminari-core (= 1.2.1)
106
+ kaminari-activerecord (1.2.1)
107
+ activerecord
108
+ kaminari-core (= 1.2.1)
109
+ kaminari-core (1.2.1)
110
+ loofah (2.9.0)
111
+ crass (~> 1.0.2)
112
+ nokogiri (>= 1.5.9)
113
+ mail (2.7.1)
114
+ mini_mime (>= 0.1.1)
115
+ marcel (0.3.3)
116
+ mimemagic (~> 0.3.2)
117
+ method_source (1.0.0)
118
+ mimemagic (0.3.5)
119
+ mini_mime (1.0.2)
120
+ minitest (5.14.3)
121
+ nio4r (2.5.4)
122
+ nokogiri (1.11.1-x86_64-darwin)
123
+ racc (~> 1.4)
124
+ racc (1.5.2)
125
+ rack (2.2.3)
126
+ rack-test (1.1.0)
127
+ rack (>= 1.0, < 3)
128
+ rails (6.1.0)
129
+ actioncable (= 6.1.0)
130
+ actionmailbox (= 6.1.0)
131
+ actionmailer (= 6.1.0)
132
+ actionpack (= 6.1.0)
133
+ actiontext (= 6.1.0)
134
+ actionview (= 6.1.0)
135
+ activejob (= 6.1.0)
136
+ activemodel (= 6.1.0)
137
+ activerecord (= 6.1.0)
138
+ activestorage (= 6.1.0)
139
+ activesupport (= 6.1.0)
140
+ bundler (>= 1.15.0)
141
+ railties (= 6.1.0)
142
+ sprockets-rails (>= 2.0.0)
143
+ rails-dom-testing (2.0.3)
144
+ activesupport (>= 4.2.0)
145
+ nokogiri (>= 1.6)
146
+ rails-html-sanitizer (1.3.0)
147
+ loofah (~> 2.3)
148
+ railties (6.1.0)
149
+ actionpack (= 6.1.0)
150
+ activesupport (= 6.1.0)
151
+ method_source
152
+ rake (>= 0.8.7)
153
+ thor (~> 1.0)
154
+ rake (13.0.3)
155
+ rb-fsevent (0.10.4)
156
+ rb-inotify (0.10.1)
157
+ ffi (~> 1.0)
158
+ ruby_parser (3.15.0)
159
+ sexp_processor (~> 4.9)
160
+ sass (3.7.4)
161
+ sass-listen (~> 4.0.0)
162
+ sass-listen (4.0.0)
163
+ rb-fsevent (~> 0.9, >= 0.9.4)
164
+ rb-inotify (~> 0.9, >= 0.9.7)
165
+ sass-rails (5.1.0)
166
+ railties (>= 5.2.0)
167
+ sass (~> 3.1)
168
+ sprockets (>= 2.8, < 4.0)
169
+ sprockets-rails (>= 2.0, < 4.0)
170
+ tilt (>= 1.1, < 3)
171
+ sexp_processor (4.15.1)
172
+ sprockets (3.7.2)
173
+ concurrent-ruby (~> 1.0)
174
+ rack (> 1, < 3)
175
+ sprockets-rails (3.2.2)
176
+ actionpack (>= 4.0)
177
+ activesupport (>= 4.0)
178
+ sprockets (>= 3.0.0)
179
+ temple (0.8.2)
180
+ thor (1.1.0)
181
+ tilt (2.0.10)
182
+ tzinfo (2.0.4)
183
+ concurrent-ruby (~> 1.0)
184
+ websocket-driver (0.7.3)
185
+ websocket-extensions (>= 0.1.0)
186
+ websocket-extensions (0.1.5)
187
+ zeitwerk (2.4.2)
188
+
189
+ PLATFORMS
190
+ ruby
191
+
192
+ DEPENDENCIES
193
+ hot-glue!
194
+
195
+ BUNDLED WITH
196
+ 2.1.4
data/LICENCE ADDED
@@ -0,0 +1,13 @@
1
+ Permission is hereby granted to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
2
+
3
+ Any users of this software agree to work to
4
+ 1) dismantle systemic racism;
5
+ 2) seek justice for black, brown, transgender people, women, and
6
+ 3) work towards LGBTQIAA+ representation and inclusion.
7
+
8
+ Organizations using this software agree to center the narratives of black, brown, transgender, and non-advantaged people in the world.
9
+
10
+ The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
11
+
12
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
13
+
data/README.md ADDED
@@ -0,0 +1,262 @@
1
+ # Hot Glue
2
+
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.
4
+
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.
6
+
7
+ It gives users full control over objects they 'own' and by default it spits out functionality giving access to all fields.
8
+
9
+ Hot Glue generates functionality that's quick and dirty. It let's you be crafty. Like a real glue gun with hot glue, take care not to burn yourself while using it.
10
+
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.
16
+ * 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).
19
+ * Throw the scaffolding away when your app is ready to graduate to its next phase (or don't if you like it).
20
+
21
+ ## QUICK START (COMING SOON)
22
+
23
+ It's really easy to get started by following along with this blog post that creates three simple tables (User, Event, and Format).
24
+
25
+ Feel free to build your own tables when you get to the sections for building the 'Event' scaffold:
26
+
27
+ https://blog.jasonfleetwoodboldt.com/hot-glue
28
+
29
+ ## HOW EASY?
30
+
31
+
32
+ ```
33
+ rails generate hot_glue:scaffold Thing
34
+ ```
35
+
36
+ ## TO INSTALL
37
+
38
+ - Add Turbo-Rails to your Gemfile & bundle install, then install it with `rails turbo:install`
39
+
40
+ - The Turbo install has switched your action cable settings from 'async' to Redis, so be sure to start a redis server
41
+
42
+ - Add hot_glue to your Gemfile & bundle install, then install it with `rails hot_glue:install`
43
+
44
+ - Install Bootstrap (optional)
45
+
46
+ with Webpack:
47
+ - change `stylesheet_link_tag` to `stylesheet_pack_tag` in your application layout
48
+ - `yarn add bootstrap`
49
+ - create a new file at `app/javascript/css/site.scss` with this contents
50
+ ```
51
+ @import "~bootstrap/scss/bootstrap.scss
52
+ ```
53
+
54
+ - add to `app/javascript/packs/application.js`
55
+ ```
56
+ import 'css/site'
57
+ ```
58
+
59
+
60
+
61
+ - Install Devise or implement your own authentication
62
+
63
+
64
+
65
+ ## Options
66
+
67
+ Note that the arguments are not preceded by dashes and are followed by equal sign and the input you are giving.
68
+
69
+ Flags take two dashes (--) and do not take any value. Always pass options first, followed by the flags (or else your options won't work!)
70
+
71
+ ### First Argument
72
+
73
+ TitleCase class name of the thing you want to build a scaffoling for.
74
+
75
+ ### `namespace=`
76
+
77
+ pass `namespace=` as an option to denote a namespace to apply to the Rails path helpers
78
+
79
+
80
+ `rails generate hot_glue:scaffold Thing namespace=dashboard`
81
+
82
+ This produces several views at `app/views/dashboard/things/` and a controller at`app/controllers/dashboard/things_controller.rb`
83
+
84
+ The controller looks like so:
85
+
86
+ ```
87
+ class Dashboard::ThingsController < ApplicationController
88
+ before_action :authenticate_user!
89
+ before_action :load_thing, only: [:show, :edit, :update, :destroy]
90
+ def load_thing
91
+ @thing = current_user.things.find(params[:id])
92
+ end
93
+ ...
94
+ end
95
+
96
+ ```
97
+
98
+
99
+ ### `nest=`
100
+
101
+ pass `nest=` to denote a nested resources
102
+
103
+
104
+ `rails generate hot_glue:scaffold Line nest=invoice`
105
+
106
+ In this example, it is presumed that the current user has_many :invoices, and that invoices have many :lines
107
+
108
+
109
+ For multi-level nesting use slashes to separate your levels of nesting. Remember, you should match what you have in your routes.rb file.
110
+
111
+ ```
112
+ resources :invoices do
113
+ resources :lines do
114
+ resources :charge
115
+ end
116
+ end
117
+
118
+ ```
119
+ In this example, it is presumed that the current user has_many :invoices, and that invoices have many :lines, and that lines have many :charges
120
+
121
+
122
+ To generate scaffold:
123
+ `rails generate hot_glue:scaffold Charge nest=invoice/line`
124
+
125
+ The order of the nest should match the nested resources you have in your own app. In particular, you auth root will be used as the starting point when loading the objects from the URL:
126
+
127
+ In the example above, @invoice will be loaded from
128
+
129
+ `@invoice = current_user.invoices.find(params[:invoice_id])`
130
+
131
+ Then, @line will be loaded
132
+
133
+ `@line = @invoice.lines.find(params[:line_id])`
134
+
135
+ Then, finally the @charge will be loaded
136
+
137
+ `@charge = @line.charges.find(params[:id])`
138
+
139
+ It's called "poor man's auth" because if a user attempts to hack the URL by passing ids for objects they don't own--- which Rails makes relatively easy with its default URL pattern-- they will hit ActiveRecord not found errors (the objects they don't own won't be found in the associated relationship).
140
+
141
+ It works, but it isn't granular. As well, it isn't appropriate for a large app with any level of intricacy to access control (that is, having roles).
142
+
143
+ Your customers can delete their own objects by default (may be a good idea or a bad idea for you). If you don't want that, you should strip out the delete actions off the controllers.
144
+
145
+
146
+ ### `auth=`
147
+
148
+ By default, it will be assumed you have a `current_user` for your user authentication. This will be treated as the "authentication root" for the "poor man's auth" explained above.
149
+
150
+ The poor man's auth presumes that object graphs have only one natural way to traverse them (that is, one primary way to traverse them), and that all relationships infer that a set of things or their descendants are granted access to me for reading, writing, updating, and deleting.
151
+
152
+ Of course this is a sloppy way to do authentication, and can easily leave open endpoints your real users shouldn't have access to.
153
+
154
+ When you display anything built with the scaffolding, we assume the `current_user` will have `has_many` association that matches the pluralized name of the scaffold. In the case of nesting, we will automatically find the nested objects first, then continue down the nest chain to find the target object. In this way, we know that all object are 'anchored' to the logged-in user.
155
+
156
+ If you use Devise, you probably already have a `current_user` method available in your controllers. If you don't use Devise, you can implement it in your ApplicationController.
157
+
158
+ If you use a different object other than "User" for authentication, override using the `auth` option.
159
+
160
+ `rails generate hot_glue:scaffold Thing auth=current_account`
161
+
162
+ You will note that in this example it is presumed that the Account object will have an association for `things`
163
+
164
+ It is also presumed that when viewing their own dashboard of things, the user will want to see ALL of their associated things.
165
+
166
+ If you supply nesting (see below), your nest chain will automatically begin with your auth root object (see nesting)
167
+
168
+
169
+
170
+
171
+ ### `auth_identifier=`
172
+
173
+ Your controller will call a method authenticate_ (AUTH IDENTIFIER) bang, like:
174
+
175
+ `authenticate_user!`
176
+
177
+ Before all of the controller actions. If you leave this blank, it will default to using the variable name supplied by auth with "current_" stripped away.
178
+ (This is setup for devise.)
179
+
180
+ Be sure to implement the following method in your ApplicationController or some other method. Here's a quick example using Devise. You will note in the code below, user_signed_in? is implemented when you add Devise methods to your User table.
181
+
182
+ As well, the `after_sign_in_path_for(user)` here is a hook for Devise also that provides you with after login redirect to the page where the user first intended to go.
183
+
184
+ ```
185
+ def authenticate_user!
186
+ if ! user_signed_in?
187
+ session['user_return_to'] = request.path
188
+ redirect_to new_user_registration_path
189
+ end
190
+ end
191
+
192
+ def after_sign_in_path_for(user)
193
+ session['user_return_to'] || account_url(user)
194
+ end
195
+ ```
196
+
197
+
198
+ The default (do not pass `auth_identifier=`) will match the `auth` (So if you use 'account' as the auth, `authenticate_account!` will get invoked from your generated controller; the default is always 'user', so you can leave both auth and auth_identifier off if you want 'user')
199
+
200
+
201
+ `rails generate hot_glue:scaffold Thing auth=current_account auth_identifier=login`
202
+ In this example, the controller produced with:
203
+ ```
204
+ before_action :authenticate_login!
205
+ ```
206
+ However, the object graph anchors would continue to start from current_account. That is,
207
+ ```
208
+ @thing = current_account.things.find(params[:id])
209
+ ```
210
+
211
+ Use empty string to **turn this method off**:
212
+ `rails generate hot_glue:scaffold Thing auth=current_account auth_identifier=''`
213
+
214
+ In this case a controller would be generated that would have NO before_action to authenticate the account, but it would still treat the current_account as the auth root for the purpose of loading the objects.
215
+
216
+ Please note that this example would product non-functional code, so you would need to manually fix your controllers to make sure `current_account` is available to the controller.
217
+
218
+
219
+ ### `plural=`
220
+
221
+ You don't need this if the pluralized version is just + "s" of the singular version. Only use for non-standard plurlizations, and be sure to pass it as TitleCase (as if you pluralized the model name)
222
+
223
+
224
+ ### `--god`
225
+
226
+ Use this flag to create controllers with no root authentication. You can still use an auth_identifier, which can be useful for a meta-leval authentication to the controoler.
227
+
228
+ For example, FOR ADMIN CONTROLLERS ONLY, supply a auth_identifier and use `--god` flag
229
+
230
+ In God mode, the objects are loaded directly from the base class (these controllers have full access)
231
+ ```
232
+ def load_thing
233
+ @thing = Thing.find(params[:id])
234
+ end
235
+
236
+ ```
237
+
238
+
239
+
240
+ ### `--specs-only`
241
+
242
+ Produces ONLY the controller spec file, nothing else.
243
+
244
+
245
+ ### `--no-specs`
246
+
247
+ Produces all the files except the spec file.
248
+
249
+
250
+ # VERSION HISTORY
251
+ #### 2021-02-24 - v0.0.1 - first proof of concept release -- basic CRUD works
252
+
253
+ #### 2021-02-23 - v0.0.0 - Port of my prior work from github.com/jasonfb/common_core_js
254
+
255
+
256
+ # ACKNOWLEDGEMENTS
257
+
258
+ ### "POOR MAN"
259
+
260
+ 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)!
261
+
262
+
data/Rakefile ADDED
@@ -0,0 +1,32 @@
1
+ begin
2
+ require 'bundler/setup'
3
+ rescue LoadError
4
+ puts 'You must `gem install bundler` and `bundle install` to run rake tasks'
5
+ end
6
+
7
+ require 'rdoc/task'
8
+
9
+ RDoc::Task.new(:rdoc) do |rdoc|
10
+ rdoc.rdoc_dir = 'rdoc'
11
+ rdoc.title = 'HotGlue'
12
+ rdoc.options << '--line-numbers'
13
+ rdoc.rdoc_files.include('README.md')
14
+ rdoc.rdoc_files.include('lib/**/*.rb')
15
+ end
16
+
17
+ APP_RAKEFILE = File.expand_path("test/dummy/Rakefile", __dir__)
18
+ load 'rails/tasks/engine.rake'
19
+
20
+ load 'rails/tasks/statistics.rake'
21
+
22
+ require 'bundler/gem_tasks'
23
+
24
+ require 'rake/testtask'
25
+
26
+ Rake::TestTask.new(:test) do |t|
27
+ t.libs << 'test'
28
+ t.pattern = 'test/**/*_test.rb'
29
+ t.verbose = false
30
+ end
31
+
32
+ task default: :test
@@ -0,0 +1,105 @@
1
+ module HotGlue
2
+ module ControllerHelper
3
+
4
+ def timezonize(tz)
5
+ tz = tz.to_i
6
+ (tz >= 0 ? "+" : "-") + sprintf('%02d',tz.abs) + ":00"
7
+ end
8
+
9
+
10
+ def datetime_field_localized(form_object, field_name, value, label, timezone = nil )
11
+ res = form_object.label(label,
12
+ field_name,
13
+ class: 'small form-text text-muted')
14
+
15
+ res << form_object.text_field(field_name, class: 'form-control',
16
+ type: 'datetime-local',
17
+ value: date_to_current_timezone(value, timezone))
18
+
19
+ res << timezonize(timezone)
20
+ res
21
+ end
22
+
23
+
24
+ def date_field_localized(form_object, field_name, value, label, timezone = nil )
25
+
26
+ res = form_object.label(label,
27
+ field_name,
28
+ class: 'small form-text text-muted')
29
+
30
+ res << form_object.text_field(field_name, class: 'form-control',
31
+ type: 'date',
32
+ value: value )
33
+
34
+ res
35
+ end
36
+
37
+ def time_field_localized(form_object, field_name, value, label, timezone = nil )
38
+ res = form_object.label(label,
39
+ field_name,
40
+ class: 'small form-text text-muted')
41
+
42
+ res << form_object.text_field(field_name, class: 'form-control',
43
+ type: 'time',
44
+ value: date_to_current_timezone(value, timezone))
45
+
46
+ res << timezonize(tz)
47
+ res
48
+ end
49
+
50
+ def current_timezone
51
+ if defined?(current_user)
52
+ if current_user.try(:timezone)
53
+ Time.now.in_time_zone(current_user.timezone.to_i).strftime("%z").to_i/100
54
+ else
55
+ server_timezone
56
+ end
57
+ elsif defined?(controller) == "method"
58
+ # controller.try(:current_timezone)
59
+ elsif self.class.ancestors.include?(ApplicationController)
60
+ self.try(:current_timezone)
61
+ else
62
+ raise "no method current_user is available; please implement/override the method current_timezone IN YOUR CONTROLLER"
63
+ end
64
+ end
65
+
66
+ def server_timezone
67
+ Time.now.strftime("%z").to_i/100
68
+ end
69
+
70
+ def date_to_current_timezone(date, timezone = nil)
71
+ # if the timezone is nil, use the server date'
72
+ if timezone.nil?
73
+ timezone = Time.now.strftime("%z").to_i/100
74
+ end
75
+
76
+ return nil if date.nil?
77
+
78
+ begin
79
+ return date.in_time_zone(timezone).strftime("%Y-%m-%dT%H:%M")
80
+ rescue
81
+ return nil
82
+ end
83
+ end
84
+
85
+
86
+
87
+ def modify_date_inputs_on_params(modified_params, current_user_object = nil)
88
+ use_timezone = (current_user_object.try(:timezone)) || Time.now.strftime("%z")
89
+
90
+ modified_params = modified_params.tap do |params|
91
+ params.keys.each{|k|
92
+ if k.ends_with?("_at") || k.ends_with?("_date")
93
+
94
+ begin
95
+ params[k] = DateTime.strptime("#{params[k]} #{use_timezone}", '%Y-%m-%dT%H:%M %z')
96
+ rescue StandardError
97
+
98
+ end
99
+ end
100
+ }
101
+ end
102
+ modified_params
103
+ end
104
+ end
105
+ end
@@ -0,0 +1,4 @@
1
+ module HotGlueHelper
2
+
3
+
4
+ end
data/bin/rails ADDED
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+ # This command will automatically be run when you run "rails" with Rails gems
3
+ # installed from the root of your application.
4
+
5
+ ENGINE_ROOT = File.expand_path('..', __dir__)
6
+ ENGINE_PATH = File.expand_path('../lib/common_core_js/engine', __dir__)
7
+ APP_PATH = File.expand_path('../test/dummy/config/application', __dir__)
8
+
9
+ # Set up gems listed in the Gemfile.
10
+ ENV['BUNDLE_GEMFILE'] ||= File.expand_path('../Gemfile', __dir__)
11
+ require 'bundler/setup' if File.exist?(ENV['BUNDLE_GEMFILE'])
12
+
13
+ require 'rails/all'
14
+ require 'rails/engine/commands'