rails-contact 0.1.3 → 0.1.4

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 96bbf7fb23c7f016bf4ca07ef9713a0f2412f1236efeb11b20d978f3e8c809cc
4
- data.tar.gz: c16b7c6f1258b827468f1f816b67bfe6bb77ad7e7fc2ceafb36a5197b5923bfe
3
+ metadata.gz: b40ac2006fcc2931b47cbc8b339770f3c148bca499cae741ee87c2e756a1a290
4
+ data.tar.gz: 6be3bc28491e1f20cd6c61409f8d6454db921bf1907b1834e801760d5abb304a
5
5
  SHA512:
6
- metadata.gz: c97455fedc7043f89e3a3ffcb5ebcc38a80d68ef597df76b2c4a25fb506c76d2c6e1dd577ffb071b4c4cd6df5de3f5c773b7ce5fad8bdcb51b9b72468293c4de
7
- data.tar.gz: a16a9da2acbccebe3aaeac7371c5023f511278b6c8f88a2f5b629b8d2aada0336b5e68b2f327bd53c0f8844d99b5a22fb05f6cb754e46d9fe8fc1f188df17db0
6
+ metadata.gz: 32f9fc983a9c6eea9e37ceb4d3e220ad4f0f14e4ba54d195e5ef1278f3674e598492b242cddde852efc7f51b797280758cf0f4b95ac8e905beb1dd69a2c5f65b
7
+ data.tar.gz: ca941d755aa4db4679f79a8a7122f3bfa36db04b0ba32f9623d522cdf2afc2df93091dd2f4bc3b7e415f7ef167e563808ffee61ecca190e8fc8f3291f89eeac1
data/CHANGELOG.md CHANGED
@@ -1,5 +1,11 @@
1
1
  # Changelog
2
2
 
3
+ ## 0.1.4
4
+
5
+ - Default to the host `application` layout when the engine is mounted, with `inherit_host_layout` (default `true`) to opt back into the engine-only layout.
6
+ - Ensure nested field add/remove and bulk checkbox scripts run when the host uses importmap (inline scripts + idempotent global guards; same guard in `nested_fields.js` for the Sprockets bundle).
7
+ - Pull engine stylesheet into each main contact view so styling works without the engine layout’s asset tags.
8
+
3
9
  ## 0.1.3
4
10
 
5
11
  - Flatten view partial paths under `app/views/rails/contact` and remove legacy `contacts/` partial nesting.
data/README.md CHANGED
@@ -20,7 +20,7 @@ It provides:
20
20
  ### 1) Add gem
21
21
 
22
22
  ```ruby
23
- gem "rails-contact", "~> 0.1.3"
23
+ gem "rails-contact", "~> 0.1.4"
24
24
  ```
25
25
 
26
26
  ```bash
@@ -55,6 +55,18 @@ mount Rails::Contact::Engine => "/contacts", as: "rails_contact"
55
55
  - `/contacts/new`
56
56
  - `/contacts/:id`
57
57
 
58
+ ### Host layout and importmap
59
+
60
+ By default the engine uses your host app layout named `application` so contacts pages match the rest of your UI (including Turbo and importmap). Styles for engine markup are included per page via `stylesheet_link_tag`, and nested “add row” / bulk-selection behavior uses small inline scripts so you do **not** need to pin gem JavaScript in the host importmap.
61
+
62
+ To use the engine’s standalone layout and bundled `javascript_include_tag "rails/contact/application"` instead:
63
+
64
+ ```ruby
65
+ Rails::Contact.configure do |config|
66
+ config.inherit_host_layout = false
67
+ end
68
+ ```
69
+
58
70
  ---
59
71
 
60
72
  ## Generators
@@ -1,4 +1,7 @@
1
1
  (() => {
2
+ if (window.__railsContactNestedFieldsBound) return;
3
+ window.__railsContactNestedFieldsBound = true;
4
+
2
5
  function addRow(event) {
3
6
  const button = event.target.closest("[data-add-nested]");
4
7
  if (!button) return;
@@ -1,15 +1,187 @@
1
1
  /*
2
- * This is a manifest file that'll be compiled into application.css, which will include all the files
3
- * listed below.
4
- *
5
- * Any CSS and SCSS file within this directory, lib/assets/stylesheets, vendor/assets/stylesheets,
6
- * or any plugin's vendor/assets/stylesheets directory can be referenced here using a relative path.
7
- *
8
- * You're free to add application-wide styles to this file and they'll appear at the bottom of the
9
- * compiled file so the styles you add here take precedence over styles defined in any other CSS/SCSS
10
- * files in this directory. Styles in this file should be added after the last require_* statement.
11
- * It is generally better to create a new file per style scope.
12
- *
13
- *= require_tree .
14
2
  *= require_self
15
3
  */
4
+
5
+ /* Basic reset-ish defaults scoped to engine layout usage */
6
+ html,
7
+ body {
8
+ margin: 0;
9
+ padding: 0;
10
+ background: #f8fafc;
11
+ color: #111827;
12
+ font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
13
+ }
14
+
15
+ body {
16
+ line-height: 1.4;
17
+ }
18
+
19
+ a {
20
+ color: #2563eb;
21
+ text-decoration: none;
22
+ }
23
+
24
+ a:hover {
25
+ text-decoration: underline;
26
+ }
27
+
28
+ /* Utility classes used in engine views */
29
+ .space-y-6 > * + * {
30
+ margin-top: 1.5rem;
31
+ }
32
+
33
+ .space-y-4 > * + * {
34
+ margin-top: 1rem;
35
+ }
36
+
37
+ .space-y-3 > * + * {
38
+ margin-top: 0.75rem;
39
+ }
40
+
41
+ .mt-1 { margin-top: 0.25rem; }
42
+ .mt-2 { margin-top: 0.5rem; }
43
+ .mt-3 { margin-top: 0.75rem; }
44
+ .mt-4 { margin-top: 1rem; }
45
+ .mb-1 { margin-bottom: 0.25rem; }
46
+ .mb-3 { margin-bottom: 0.75rem; }
47
+ .ml-4 { margin-left: 1rem; }
48
+ .pt-2 { padding-top: 0.5rem; }
49
+
50
+ .flex { display: flex; }
51
+ .inline-flex { display: inline-flex; }
52
+ .items-center { align-items: center; }
53
+ .items-end { align-items: flex-end; }
54
+ .items-start { align-items: flex-start; }
55
+ .justify-between { justify-content: space-between; }
56
+ .justify-center { justify-content: center; }
57
+ .gap-2 { gap: 0.5rem; }
58
+ .gap-6 { gap: 1.5rem; }
59
+
60
+ .grid { display: grid; }
61
+ .grid-cols-1 { grid-template-columns: repeat(1, minmax(0, 1fr)); }
62
+ .md\:grid-cols-2 { grid-template-columns: repeat(1, minmax(0, 1fr)); }
63
+ .md\:grid-cols-3 { grid-template-columns: repeat(1, minmax(0, 1fr)); }
64
+ .md\:grid-cols-4 { grid-template-columns: repeat(1, minmax(0, 1fr)); }
65
+ .md\:grid-cols-5 { grid-template-columns: repeat(1, minmax(0, 1fr)); }
66
+
67
+ .w-full { width: 100%; }
68
+ .w-24 { width: 6rem; }
69
+ .w-28 { width: 7rem; }
70
+ .h-4 { height: 1rem; }
71
+ .w-4 { width: 1rem; }
72
+ .h-24 { height: 6rem; }
73
+ .min-w-full { min-width: 100%; }
74
+
75
+ .rounded-md { border-radius: 0.375rem; }
76
+ .rounded-lg { border-radius: 0.5rem; }
77
+ .rounded-xl { border-radius: 0.75rem; }
78
+ .rounded-full { border-radius: 9999px; }
79
+
80
+ .border { border: 1px solid #d1d5db; }
81
+ .border-gray-200 { border-color: #e5e7eb; }
82
+ .border-gray-300 { border-color: #d1d5db; }
83
+ .border-red-200 { border-color: #fecaca; }
84
+
85
+ .bg-white { background: #fff; }
86
+ .bg-gray-50 { background: #f9fafb; }
87
+ .bg-gray-100 { background: #f3f4f6; }
88
+ .bg-gray-900 { background: #111827; }
89
+ .bg-blue-600 { background: #2563eb; }
90
+ .bg-red-50 { background: #fef2f2; }
91
+ .bg-red-600 { background: #dc2626; }
92
+
93
+ .text-white { color: #fff; }
94
+ .text-gray-900 { color: #111827; }
95
+ .text-gray-700 { color: #374151; }
96
+ .text-gray-600 { color: #4b5563; }
97
+ .text-gray-500 { color: #6b7280; }
98
+ .text-red-700 { color: #b91c1c; }
99
+ .text-blue-600 { color: #2563eb; }
100
+
101
+ .text-xs { font-size: 0.75rem; }
102
+ .text-sm { font-size: 0.875rem; }
103
+ .text-2xl { font-size: 1.5rem; }
104
+ .font-medium { font-weight: 500; }
105
+ .font-semibold { font-weight: 600; }
106
+ .font-bold { font-weight: 700; }
107
+ .uppercase { text-transform: uppercase; }
108
+ .tracking-wide { letter-spacing: 0.03em; }
109
+ .text-left { text-align: left; }
110
+ .text-right { text-align: right; }
111
+ .text-center { text-align: center; }
112
+
113
+ .p-4 { padding: 1rem; }
114
+ .px-2 { padding-left: 0.5rem; padding-right: 0.5rem; }
115
+ .px-3 { padding-left: 0.75rem; padding-right: 0.75rem; }
116
+ .px-4 { padding-left: 1rem; padding-right: 1rem; }
117
+ .py-1 { padding-top: 0.25rem; padding-bottom: 0.25rem; }
118
+ .py-2 { padding-top: 0.5rem; padding-bottom: 0.5rem; }
119
+ .py-3 { padding-top: 0.75rem; padding-bottom: 0.75rem; }
120
+ .py-8 { padding-top: 2rem; padding-bottom: 2rem; }
121
+ .pl-5 { padding-left: 1.25rem; }
122
+
123
+ .shadow-sm { box-shadow: 0 1px 2px rgba(0, 0, 0, 0.06); }
124
+ .overflow-hidden { overflow: hidden; }
125
+ .object-cover { object-fit: cover; }
126
+ .whitespace-pre-line { white-space: pre-line; }
127
+ .list-disc { list-style: disc; }
128
+
129
+ .divide-y > * + * {
130
+ border-top: 1px solid #e5e7eb;
131
+ }
132
+
133
+ .divide-gray-100 > * + * {
134
+ border-top-color: #f3f4f6;
135
+ }
136
+
137
+ .divide-gray-200 > * + * {
138
+ border-top-color: #e5e7eb;
139
+ }
140
+
141
+ .hover\:bg-gray-50:hover { background: #f9fafb; }
142
+ .hover\:bg-blue-700:hover { background: #1d4ed8; }
143
+ .hover\:bg-red-700:hover { background: #b91c1c; }
144
+ .hover\:bg-gray-700:hover { background: #374151; }
145
+ .hover\:text-blue-700:hover { color: #1d4ed8; }
146
+
147
+ input,
148
+ textarea,
149
+ select,
150
+ button {
151
+ font: inherit;
152
+ }
153
+
154
+ input[type="text"],
155
+ input[type="email"],
156
+ input[type="url"],
157
+ input[type="number"],
158
+ input[type="date"],
159
+ textarea {
160
+ box-sizing: border-box;
161
+ }
162
+
163
+ button,
164
+ input[type="submit"] {
165
+ cursor: pointer;
166
+ }
167
+
168
+ table {
169
+ border-collapse: collapse;
170
+ }
171
+
172
+ /* Layout breathing room */
173
+ body > * {
174
+ max-width: 1100px;
175
+ margin: 1.5rem auto;
176
+ padding: 0 1rem;
177
+ }
178
+
179
+ @media (min-width: 768px) {
180
+ .md\:grid-cols-2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
181
+ .md\:grid-cols-3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
182
+ .md\:grid-cols-4 { grid-template-columns: repeat(4, minmax(0, 1fr)); }
183
+ .md\:grid-cols-5 { grid-template-columns: repeat(5, minmax(0, 1fr)); }
184
+ .md\:items-end { align-items: end; }
185
+ .md\:col-span-2 { grid-column: span 2 / span 2; }
186
+ .md\:col-span-3 { grid-column: span 3 / span 3; }
187
+ }
@@ -3,8 +3,14 @@ module Rails
3
3
  class ApplicationController < ActionController::Base
4
4
  protect_from_forgery with: :exception
5
5
 
6
+ layout :rails_contact_layout
7
+
6
8
  private
7
9
 
10
+ def rails_contact_layout
11
+ Rails::Contact.configuration.inherit_host_layout ? "application" : "rails/contact/application"
12
+ end
13
+
8
14
  def t_flash(key, default:)
9
15
  I18n.t("rails_contact.flash.#{key}", default: default)
10
16
  end
@@ -0,0 +1,13 @@
1
+ <script>
2
+ (() => {
3
+ if (window.__railsContactBulkSelectionBound) return;
4
+ window.__railsContactBulkSelectionBound = true;
5
+
6
+ document.addEventListener("change", function(event) {
7
+ if (!event.target.classList.contains("bulk-id-checkbox")) return;
8
+ const values = Array.from(document.querySelectorAll(".bulk-id-checkbox:checked")).map((node) => node.value);
9
+ const field = document.getElementById("bulk-ids-field");
10
+ if (field) field.value = values.join(",");
11
+ });
12
+ })();
13
+ </script>
@@ -184,3 +184,4 @@
184
184
  <%= link_to "Back", contacts_path, class: "inline-flex rounded-md border border-gray-300 px-4 py-2 text-sm font-medium text-gray-700 hover:bg-gray-50" %>
185
185
  </div>
186
186
  <% end %>
187
+ <%= render "rails/contact/nested_fields_script" %>
@@ -0,0 +1,51 @@
1
+ <script>
2
+ (() => {
3
+ if (window.__railsContactNestedFieldsBound) return;
4
+ window.__railsContactNestedFieldsBound = true;
5
+
6
+ function addRow(event) {
7
+ const button = event.target.closest("[data-add-nested]");
8
+ if (!button) return;
9
+
10
+ const wrapper = button.closest("[data-nested-wrapper]");
11
+ const targetSelector = button.dataset.target;
12
+ const templateSelector = button.dataset.template;
13
+ if (!wrapper || !targetSelector || !templateSelector) return;
14
+
15
+ const container = wrapper.querySelector(targetSelector);
16
+ const template = wrapper.querySelector(templateSelector);
17
+ if (!container || !template) return;
18
+
19
+ const uniqueId = String(Date.now() + Math.floor(Math.random() * 1000));
20
+ const html = template.innerHTML.replace(/NEW_RECORD/g, uniqueId);
21
+ container.insertAdjacentHTML("beforeend", html);
22
+ }
23
+
24
+ function removeRow(event) {
25
+ const button = event.target.closest("[data-action='nested-fields#remove']");
26
+ if (!button) return;
27
+ const row = button.closest("[data-nested-fields-target='row']");
28
+ if (!row) return;
29
+
30
+ const destroyField = row.querySelector("[data-nested-fields-target='destroyField']");
31
+ if (destroyField) {
32
+ destroyField.value = "1";
33
+ row.style.display = "none";
34
+ } else {
35
+ row.remove();
36
+ }
37
+ }
38
+
39
+ document.addEventListener("click", (event) => {
40
+ if (event.target.closest("[data-add-nested]")) {
41
+ event.preventDefault();
42
+ addRow(event);
43
+ return;
44
+ }
45
+ if (event.target.closest("[data-action='nested-fields#remove']")) {
46
+ event.preventDefault();
47
+ removeRow(event);
48
+ }
49
+ });
50
+ })();
51
+ </script>
@@ -0,0 +1 @@
1
+ <%= stylesheet_link_tag "rails/contact/application", "data-turbo-track": "reload" %>
@@ -1,3 +1,4 @@
1
+ <%= render "rails/contact/stylesheet" %>
1
2
  <h1>Edit Contact</h1>
2
3
  <%= render "rails/contact/form", contact: @contact %>
3
4
  <%= link_to "Back", contacts_path %>
@@ -1,3 +1,4 @@
1
+ <%= render "rails/contact/stylesheet" %>
1
2
  <div class="space-y-6">
2
3
  <div class="flex items-center justify-between">
3
4
  <h1 class="text-2xl font-bold text-gray-900">Contacts</h1>
@@ -78,11 +79,4 @@
78
79
  </div>
79
80
  </div>
80
81
 
81
- <script>
82
- document.addEventListener("change", function(event) {
83
- if (!event.target.classList.contains("bulk-id-checkbox")) return;
84
- const values = Array.from(document.querySelectorAll(".bulk-id-checkbox:checked")).map((node) => node.value);
85
- const field = document.getElementById("bulk-ids-field");
86
- if (field) field.value = values.join(",");
87
- });
88
- </script>
82
+ <%= render "rails/contact/bulk_selection_script" %>
@@ -1,3 +1,4 @@
1
+ <%= render "rails/contact/stylesheet" %>
1
2
  <h1>New Contact</h1>
2
3
  <%= render "rails/contact/form", contact: @contact %>
3
4
  <%= link_to "Back", contacts_path %>
@@ -1,3 +1,4 @@
1
+ <%= render "rails/contact/stylesheet" %>
1
2
  <div class="space-y-6">
2
3
  <div class="flex items-start justify-between">
3
4
  <div>
@@ -1,8 +1,6 @@
1
1
  module Rails
2
2
  module Contact
3
3
  class ContactsController < Rails::Contact::ContactsController
4
- layout "application"
5
-
6
4
  # Override actions here when needed.
7
5
  end
8
6
  end
@@ -4,7 +4,8 @@ module Rails
4
4
  attr_accessor :contact_class_name, :elasticsearch_url, :search_backend,
5
5
  :google_sync_enabled, :google_max_contacts, :rolling_window_sort,
6
6
  :google_client_id, :google_client_secret, :google_redirect_uri,
7
- :google_token_path, :reset_index_on_boot, :default_per_page
7
+ :google_token_path, :reset_index_on_boot, :default_per_page,
8
+ :inherit_host_layout
8
9
 
9
10
  def initialize
10
11
  @contact_class_name = "Rails::Contact::Contact"
@@ -19,6 +20,10 @@ module Rails
19
20
  @google_token_path = ENV.fetch("RAILS_CONTACT_GOOGLE_TOKEN_PATH", "tmp/rails_contact_google_token.json")
20
21
  @reset_index_on_boot = false
21
22
  @default_per_page = 25
23
+ # When true (default), engine pages use the host app +layout+ named +application+ so
24
+ # importmap/Turbo match the rest of the app. Engine CSS and nested-field JS are still
25
+ # injected from gem templates so behavior does not depend on the engine layout asset tags.
26
+ @inherit_host_layout = true
22
27
  end
23
28
  end
24
29
  end
@@ -1,5 +1,5 @@
1
1
  module Rails
2
2
  module Contact
3
- VERSION = "0.1.3"
3
+ VERSION = "0.1.4"
4
4
  end
5
5
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rails-contact
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.3
4
+ version: 0.1.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Kshitiz Sinha
@@ -133,10 +133,13 @@ files:
133
133
  - app/models/rails/contact/label.rb
134
134
  - app/views/layouts/rails/contact/application.html.erb
135
135
  - app/views/rails/contact/_address_fields.html.erb
136
+ - app/views/rails/contact/_bulk_selection_script.html.erb
136
137
  - app/views/rails/contact/_email_fields.html.erb
137
138
  - app/views/rails/contact/_event_fields.html.erb
138
139
  - app/views/rails/contact/_form.html.erb
140
+ - app/views/rails/contact/_nested_fields_script.html.erb
139
141
  - app/views/rails/contact/_phone_fields.html.erb
142
+ - app/views/rails/contact/_stylesheet.html.erb
140
143
  - app/views/rails/contact/_website_fields.html.erb
141
144
  - app/views/rails/contact/edit.html.erb
142
145
  - app/views/rails/contact/index.html.erb