hot-glue 0.6.0 → 0.6.0.1
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 +2 -2
- data/README.md +27 -18
- data/lib/generators/hot_glue/field_factory.rb +0 -1
- data/lib/generators/hot_glue/fields/association_field.rb +14 -14
- data/lib/generators/hot_glue/fields/field.rb +1 -1
- data/lib/generators/hot_glue/templates/typeahead_controller.rb.erb +1 -1
- data/lib/generators/hot_glue/templates/typeahead_views/index.html.erb +1 -1
- data/lib/generators/hot_glue/templates/typeahead_views/typeahead_controller.js +7 -1
- data/lib/generators/hot_glue/templates/typeahead_views/typeahead_results_controller.js +0 -2
- data/lib/hotglue/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 8ffc84538112521ab7f15e7c0d234de7ffc5e5231e49a6ffb3cb3fd77c4f0545
|
4
|
+
data.tar.gz: f9e7c8e6b171aace305d5fae08ee24d08f6304c0127e5044579e8d3c30cc6ca6
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 53da97a3e0c570c41594ae47ed50149a5519e512d1677c38dc70fb118e69893d67165b7f7de89e0e8f56325f766934225f810c52fba501c9b9a1a71943cdc365
|
7
|
+
data.tar.gz: f6fd036dd5abeb33724927a6a25e2fab560f553f4df23cf186438f09036e68f147aef50ce356b7c9c3858cd3fbe81c02bc9649b46076562da3a3cf43f0cf0530
|
data/Gemfile.lock
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
hot-glue (0.
|
4
|
+
hot-glue (0.6.0)
|
5
5
|
ffaker (~> 2.16)
|
6
6
|
kaminari (~> 1.2)
|
7
7
|
rails (> 5.1)
|
@@ -139,7 +139,7 @@ GEM
|
|
139
139
|
mini_mime (1.1.2)
|
140
140
|
mini_portile2 (2.8.4)
|
141
141
|
minitest (5.16.3)
|
142
|
-
net-imap (0.4.
|
142
|
+
net-imap (0.4.4)
|
143
143
|
date
|
144
144
|
net-protocol
|
145
145
|
net-pop (0.1.2)
|
data/README.md
CHANGED
@@ -64,25 +64,23 @@ _If you are on Rails 6, see [LEGACY SETUP FOR RAILS 6](https://github.com/jasonf
|
|
64
64
|
|
65
65
|
## The Super-Quick Setup
|
66
66
|
|
67
|
-
https://jasonfleetwoodboldt.com/courses/stepping-up-rails/rails-
|
67
|
+
https://jasonfleetwoodboldt.com/courses/stepping-up-rails/jason-fleetwood-boldts-rails-cookbook/
|
68
68
|
|
69
|
-
Copy & paste the whole code block from each section into your terminal.
|
69
|
+
Copy & paste the whole code block from each section into your terminal. Remember, there is a small "Copy" button at the top-right of each code block to help you copy & paste the script into your terminal.
|
70
70
|
|
71
|
+
These are the sections you need, you can ignore any others:
|
71
72
|
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
Sectoin #6 is for Hot Glue itself, and Section #7 is for Kaminari
|
83
|
-
|
84
|
-
You will also need section #8 to setup Devise if you want authentication.
|
73
|
+
* Section 1A for a new JS Bundling app, then skip down to
|
74
|
+
* Section 2B: Rspec + Friends
|
75
|
+
* Section 2B-Capy: Capybara for Rspec, then skip down to
|
76
|
+
* Section 3 for a welcome controller
|
77
|
+
( you can skip everything in Section 4 )
|
78
|
+
* Section 5 for debugging tools
|
79
|
+
* _Section 6 is the Hot Glue installer itself_ (this gem) - for Bootstrap, choose section 6A
|
80
|
+
* Section 7A to install Bootstrap along with CSSBundling
|
81
|
+
* Section 8 to set up Devise if you want authentication. (See how Hot Glue interacts with Devise below.)
|
85
82
|
|
83
|
+
If you do this through the quick setup above, you can then skip down past the next section to the "HOT GLUE DOCS" below.
|
86
84
|
|
87
85
|
## Step-By-Step Setup
|
88
86
|
|
@@ -294,10 +292,21 @@ Alternatively, you can define your own driver like so:
|
|
294
292
|
|
295
293
|
# HOT GLUE DOCS
|
296
294
|
|
295
|
+
Remember: Use `bin/rails generate model Thing` to generate models. Then add `has_many`, `belongs_to`, and _migrate your database_ before building the scaffold with Hot Glue.
|
296
|
+
|
297
|
+
You will also need every Rails model to contain _either_ a database column _or_ an object-level method named one of these five things:
|
298
|
+
`name`
|
299
|
+
`to_label`
|
300
|
+
`full_name`
|
301
|
+
`display_name`
|
302
|
+
`email`
|
303
|
+
|
304
|
+
If your database doesn't contain one of these five, add a method to your model using `def to_label`. This will be used as the default label for the object throughout the Hot Glue build system.
|
305
|
+
|
297
306
|
## First Argument
|
298
307
|
(no double slash)
|
299
308
|
|
300
|
-
TitleCase class name of the thing you want to build a
|
309
|
+
TitleCase class name of the thing you want to build a scaffolding for.
|
301
310
|
|
302
311
|
```
|
303
312
|
./bin/rails generate hot_glue:scaffold Thing
|
@@ -1393,7 +1402,7 @@ You can now use a typeahead when editing the book. Instead of displaying the aut
|
|
1393
1402
|
You will do these three things:
|
1394
1403
|
|
1395
1404
|
1. As a one-time setup step for your app, run
|
1396
|
-
`bin/rails generate hot_glue:
|
1405
|
+
`bin/rails generate hot_glue:typeahead_install`
|
1397
1406
|
2. When generating a scaffold you want to make a typeahead association, use `--modify='parent_id{typeahead}'` where `parent_id` is the foreign key
|
1398
1407
|
`bin/rails generate hot_glue:scaffold Book --include=title,author_id --modify='author_id{typeahead}'`
|
1399
1408
|
3. Within each namespace, you will generate a special typeahead controller (it exists for the associated object to be searched on
|
@@ -1476,7 +1485,7 @@ from a searchable typehead input.
|
|
1476
1485
|
The typeahead is implemented with a native Stimulus JS pair of controllers and is a modern & clean replacement to the old typeahead options.
|
1477
1486
|
|
1478
1487
|
1. As a one-time setup step for your app, run
|
1479
|
-
`bin/rails generate hot_glue:
|
1488
|
+
`bin/rails generate hot_glue:typeahead_install`
|
1480
1489
|
2. When generating a scaffold you want to make a typeahead association, use `--modify='parent_id{typeahead}'` where `parent_id` is the foreign key
|
1481
1490
|
`bin/rails generate hot_glue:scaffold Book --include=title,author_id --modify='author_id{typeahead}'`
|
1482
1491
|
3. Within each namespace, you will generate a special typeahead controller (it exists for the associated object to be searched on
|
@@ -80,20 +80,20 @@ class AssociationField < Field
|
|
80
80
|
assoc = eval("#{class_name}.reflect_on_association(:#{assoc_name})")
|
81
81
|
|
82
82
|
if modify_as && modify_as[:typeahead]
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
83
|
+
search_url = "#{namespace ? namespace + "_" : ""}#{assoc.plural_name}_typeahead_index_url"
|
84
|
+
"<div class='typeahead typeahead--#{assoc.name}_id'
|
85
|
+
data-controller='typeahead'
|
86
|
+
data-typeahead-url-value='<%= #{search_url} %>'
|
87
|
+
data-typeahead-typeahead-results-outlet='#search-results'>
|
88
|
+
<%= text_field_tag :#{assoc.plural_name}_query, '', placeholder: 'Search #{assoc.plural_name}', class: 'search__input',
|
89
|
+
data: { action: 'keyup->typeahead#fetchResults keydown->typeahead#navigateResults', typeahead_target: 'query' },
|
90
|
+
autofocus: true,
|
91
|
+
autocomplete: 'off',
|
92
|
+
value: #{singular}.try(:#{assoc.name}).try(:name) %>
|
93
|
+
<%= f.hidden_field :#{assoc.name}_id, value: #{singular}.try(:#{assoc.name}).try(:id), 'data-typeahead-target': 'hiddenFormValue' %>
|
94
|
+
<div data-typeahead-target='results'></div>
|
95
|
+
<div data-typeahead-target='classIdentifier' data-id=\"typeahead--#{assoc_name}_id\"></div>
|
96
|
+
</div>"
|
97
97
|
else
|
98
98
|
if assoc.nil?
|
99
99
|
exit_message = "*** Oops. on the #{class_name} object, there doesn't seem to be an association called '#{assoc_name}'"
|
@@ -6,7 +6,7 @@ class <%= ((@namespace.titleize.gsub(" ", "") + "::" if @namespace) || "") + @pl
|
|
6
6
|
|
7
7
|
def index
|
8
8
|
query = params[:query]
|
9
|
-
|
9
|
+
@typeahead_identifier = params[:typeahead_identifier]
|
10
10
|
@<%= @plural %> = <%= @singular.titleize.gsub(" ", "") %>.where("<%= @search_by.collect{|search| "LOWER(#{search}) LIKE ?" }.join(" OR ") %>", <%= @search_by.collect{|search| "\"%\#{query.downcase}%\"" }.join(", ") %>).limit(10)
|
11
11
|
|
12
12
|
render layout: false
|
@@ -1,7 +1,7 @@
|
|
1
1
|
|
2
2
|
<div class="typeahead-results__<%= @plural %>"
|
3
3
|
data-controller="typeahead-results"
|
4
|
-
data-typeahead-results-typeahead-outlet="
|
4
|
+
data-typeahead-results-typeahead-outlet=".<\%= @typeahead_identifier %>"
|
5
5
|
data-typeahead-results-current-class="search__result--current" >
|
6
6
|
<ul class="search__results" data-typeahead-results-target="result">
|
7
7
|
<\% if @<%= @plural %>.any? %>
|
@@ -1,7 +1,8 @@
|
|
1
1
|
import { Controller } from "@hotwired/stimulus"
|
2
2
|
|
3
3
|
export default class extends Controller {
|
4
|
-
static targets = [ "query", "results", "hiddenFormValue"
|
4
|
+
static targets = [ "query", "results", "hiddenFormValue",
|
5
|
+
"classIdentifier"]
|
5
6
|
static values = { url: String }
|
6
7
|
static outlets = [ "typeahead-results" ]
|
7
8
|
|
@@ -10,6 +11,10 @@ export default class extends Controller {
|
|
10
11
|
}
|
11
12
|
|
12
13
|
fetchResults() {
|
14
|
+
|
15
|
+
|
16
|
+
var typeaheadIdentifier = this.classIdentifierTarget.dataset.id
|
17
|
+
|
13
18
|
if(this.query == "") {
|
14
19
|
this.reset()
|
15
20
|
return
|
@@ -22,6 +27,7 @@ export default class extends Controller {
|
|
22
27
|
|
23
28
|
const url = new URL(this.urlValue)
|
24
29
|
url.searchParams.append("query", this.query)
|
30
|
+
url.searchParams.append("typeahead_identifier", typeaheadIdentifier)
|
25
31
|
|
26
32
|
this.abortPreviousFetchRequest()
|
27
33
|
|
@@ -12,7 +12,6 @@ export default class extends Controller {
|
|
12
12
|
|
13
13
|
connect() {
|
14
14
|
this.currentResultIndex = 0
|
15
|
-
|
16
15
|
const allElements = this.resultTarget.querySelectorAll(".search-result-item");
|
17
16
|
|
18
17
|
allElements.forEach((element, index) => {
|
@@ -29,7 +28,6 @@ export default class extends Controller {
|
|
29
28
|
const result_id = element.dataset.id;
|
30
29
|
|
31
30
|
// how to pass this to the search controller, set the field value and clear out the search
|
32
|
-
console.log("search item clicked...", result_value, result_id)
|
33
31
|
|
34
32
|
this.typeaheadOutlets.forEach(outlet => {
|
35
33
|
outlet.hiddenFormValueTarget.value = result_id;
|
data/lib/hotglue/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: hot-glue
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.6.0
|
4
|
+
version: 0.6.0.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Jason Fleetwood-Boldt
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2023-11-
|
11
|
+
date: 2023-11-11 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rails
|