rs-activeadmin-searchable_select 4.0.5

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.
Files changed (145) hide show
  1. checksums.yaml +7 -0
  2. data/.actrc +20 -0
  3. data/.claude/commands/fix-tests.md +203 -0
  4. data/.github/workflows/ci.yml +170 -0
  5. data/.github/workflows/npm-publish.yml +47 -0
  6. data/.gitignore +27 -0
  7. data/.npmignore +58 -0
  8. data/.rspec +2 -0
  9. data/.rubocop.yml +67 -0
  10. data/.yardopts +2 -0
  11. data/AGENTS.md +39 -0
  12. data/Appraisals +15 -0
  13. data/CHANGELOG.md +24 -0
  14. data/CLAUDE.md +104 -0
  15. data/Gemfile +11 -0
  16. data/Gemfile.lock +366 -0
  17. data/LICENSE.txt +25 -0
  18. data/README.md +439 -0
  19. data/Rakefile +4 -0
  20. data/bin/rspec +17 -0
  21. data/config/database.yml +16 -0
  22. data/config.ru +28 -0
  23. data/docs/activeadmin-4-detailed-reference.md +932 -0
  24. data/docs/activeadmin-4-gem-migration-guide.md +313 -0
  25. data/docs/combustion.md +213 -0
  26. data/docs/for-next-session.md +199 -0
  27. data/docs/guide-update-your-app.md +213 -0
  28. data/docs/propshaft-readme.md +121 -0
  29. data/docs/propshaft-upgrade.md +267 -0
  30. data/docs/rails-7-asset-pipeline.md +279 -0
  31. data/docs/setup-activeadmin-app.md +552 -0
  32. data/docs/setup-activeadmin-gem.md +535 -0
  33. data/docs/upload-system.md +225 -0
  34. data/gemfiles/rails_7.x_active_admin_4.x.gemfile +11 -0
  35. data/gemfiles/rails_7.x_active_admin_4.x.gemfile.lock +371 -0
  36. data/gemfiles/rails_8.x_active_admin_4.x.gemfile +11 -0
  37. data/gemfiles/rails_8.x_active_admin_4.x.gemfile.lock +366 -0
  38. data/lefthook.yml +17 -0
  39. data/lib/activeadmin/inputs/filters/searchable_select_input.rb +13 -0
  40. data/lib/activeadmin/inputs/searchable_select_input.rb +11 -0
  41. data/lib/activeadmin/searchable_select/engine.rb +17 -0
  42. data/lib/activeadmin/searchable_select/option_collection.rb +119 -0
  43. data/lib/activeadmin/searchable_select/resource_dsl_extension.rb +56 -0
  44. data/lib/activeadmin/searchable_select/resource_extension.rb +10 -0
  45. data/lib/activeadmin/searchable_select/select_input_extension.rb +159 -0
  46. data/lib/activeadmin/searchable_select/version.rb +5 -0
  47. data/lib/activeadmin/searchable_select.rb +20 -0
  48. data/lib/activeadmin-searchable_select.rb +4 -0
  49. data/lib/generators/active_admin/searchable_select/install/install_generator.rb +217 -0
  50. data/package-lock.json +18 -0
  51. data/package.json +45 -0
  52. data/rs-activeadmin-searchable_select.gemspec +38 -0
  53. data/sonar-project.properties +25 -0
  54. data/spec/features/ajax_params_spec.rb +31 -0
  55. data/spec/features/end_to_end_spec.rb +227 -0
  56. data/spec/features/filter_input_spec.rb +137 -0
  57. data/spec/features/form_input_spec.rb +122 -0
  58. data/spec/features/inline_ajax_setting_spec.rb +26 -0
  59. data/spec/features/input_errors_spec.rb +76 -0
  60. data/spec/features/input_html_options_spec.rb +30 -0
  61. data/spec/features/options_dsl_spec.rb +220 -0
  62. data/spec/features/production_build_spec.rb +108 -0
  63. data/spec/internal/app/admin/categories.rb +26 -0
  64. data/spec/internal/app/admin/dashboard.rb +29 -0
  65. data/spec/internal/app/admin/option_types.rb +19 -0
  66. data/spec/internal/app/admin/option_values.rb +30 -0
  67. data/spec/internal/app/admin/posts.rb +27 -0
  68. data/spec/internal/app/admin/products.rb +22 -0
  69. data/spec/internal/app/admin/rgb_colors.rb +25 -0
  70. data/spec/internal/app/admin/tag_names.rb +21 -0
  71. data/spec/internal/app/admin/test_ajax_params_category.rb +10 -0
  72. data/spec/internal/app/admin/test_ajax_params_post.rb +20 -0
  73. data/spec/internal/app/admin/test_form_post_class.rb +7 -0
  74. data/spec/internal/app/admin/test_form_post_custom.rb +11 -0
  75. data/spec/internal/app/admin/test_form_post_resource.rb +11 -0
  76. data/spec/internal/app/admin/test_form_post_resource_custom.rb +12 -0
  77. data/spec/internal/app/admin/test_inline_ajax_post.rb +9 -0
  78. data/spec/internal/app/admin/test_input_html_post.rb +11 -0
  79. data/spec/internal/app/admin/test_posts_display_text.rb +9 -0
  80. data/spec/internal/app/admin/test_posts_filter.rb +9 -0
  81. data/spec/internal/app/admin/test_posts_named.rb +9 -0
  82. data/spec/internal/app/admin/test_posts_pagination.rb +9 -0
  83. data/spec/internal/app/admin/test_posts_payload_lambda.rb +11 -0
  84. data/spec/internal/app/admin/test_posts_payload_proc.rb +9 -0
  85. data/spec/internal/app/admin/test_posts_scope_lambda.rb +8 -0
  86. data/spec/internal/app/admin/test_posts_scope_params.rb +8 -0
  87. data/spec/internal/app/admin/test_posts_scope_user.rb +8 -0
  88. data/spec/internal/app/admin/test_posts_text_attr.rb +5 -0
  89. data/spec/internal/app/admin/users.rb +23 -0
  90. data/spec/internal/app/admin/variants.rb +31 -0
  91. data/spec/internal/app/assets/config/manifest.js +1 -0
  92. data/spec/internal/app/assets/javascripts/active_admin.js +2 -0
  93. data/spec/internal/app/assets/javascripts/searchable_select_test.js +2 -0
  94. data/spec/internal/app/controllers/application_controller.rb +5 -0
  95. data/spec/internal/app/css/active_admin_source.css +81 -0
  96. data/spec/internal/app/js/active_admin.js +17 -0
  97. data/spec/internal/app/models/article.rb +12 -0
  98. data/spec/internal/app/models/category.rb +12 -0
  99. data/spec/internal/app/models/internal/tag_name.rb +14 -0
  100. data/spec/internal/app/models/internal_tag_name.rb +11 -0
  101. data/spec/internal/app/models/option_type.rb +12 -0
  102. data/spec/internal/app/models/option_value.rb +4 -0
  103. data/spec/internal/app/models/post.rb +15 -0
  104. data/spec/internal/app/models/product.rb +12 -0
  105. data/spec/internal/app/models/rgb_color.rb +16 -0
  106. data/spec/internal/app/models/user.rb +12 -0
  107. data/spec/internal/app/models/variant.rb +12 -0
  108. data/spec/internal/build_activeadmin_css.js +115 -0
  109. data/spec/internal/config/database.yml +7 -0
  110. data/spec/internal/config/environment.rb +48 -0
  111. data/spec/internal/config/initializers/active_admin.rb +53 -0
  112. data/spec/internal/config/initializers/assets.rb +9 -0
  113. data/spec/internal/config/initializers/searchable_select.rb +6 -0
  114. data/spec/internal/config/routes.rb +4 -0
  115. data/spec/internal/config.ru +4 -0
  116. data/spec/internal/db/schema.rb +63 -0
  117. data/spec/internal/db/seeds.rb +88 -0
  118. data/spec/internal/esbuild.config.js +30 -0
  119. data/spec/internal/inject-jquery.js +4 -0
  120. data/spec/internal/log/.gitignore +1 -0
  121. data/spec/internal/package/LICENSE.txt +25 -0
  122. data/spec/internal/package/README.md +439 -0
  123. data/spec/internal/package/package.json +45 -0
  124. data/spec/internal/package/src/index.js +1 -0
  125. data/spec/internal/package/src/searchable_select/init.js +1 -0
  126. data/spec/internal/package/src/searchable_select.css +1 -0
  127. data/spec/internal/package/src/searchable_select.scss +1 -0
  128. data/spec/internal/package-lock.json +1385 -0
  129. data/spec/internal/package.json +26 -0
  130. data/spec/internal/public/favicon.ico +0 -0
  131. data/spec/internal/spec/internal/app/css/active_admin_source.css +38 -0
  132. data/spec/internal/spec/internal/log/test.log +0 -0
  133. data/spec/internal/tailwind-active_admin.config.js +53 -0
  134. data/spec/rails_helper.rb +86 -0
  135. data/spec/spec_helper.rb +137 -0
  136. data/spec/support/active_admin_helpers.rb +17 -0
  137. data/spec/support/capybara.rb +8 -0
  138. data/spec/support/models.rb +88 -0
  139. data/spec/support/pluck_polyfill.rb +12 -0
  140. data/spec/support/reset_settings.rb +5 -0
  141. data/src/index.js +77 -0
  142. data/src/searchable_select/init.js +58 -0
  143. data/src/searchable_select.css +5 -0
  144. data/src/searchable_select.css.map +1 -0
  145. metadata +405 -0
@@ -0,0 +1,552 @@
1
+ # Setting Up Standalone ActiveAdmin 4 Application
2
+
3
+ This guide shows how to create a new standalone ActiveAdmin 4 application with proper asset pipeline configuration.
4
+
5
+ ## Quick Start: ActiveAdmin Trumbowyg Installation
6
+
7
+ ### For esbuild/webpack users (Modern Setup)
8
+ ```bash
9
+ # Install via NPM
10
+ npm install @rocket-sensei/activeadmin_trumbowyg
11
+
12
+ # Import in your JavaScript
13
+ # app/javascript/application.js or app/javascript/active_admin.js
14
+ import '@rocket-sensei/activeadmin_trumbowyg'
15
+
16
+ # No generator needed! The package auto-initializes
17
+ ```
18
+
19
+ ### For Importmap/Propshaft users (Rails Default)
20
+ ```bash
21
+ # Add gem to Gemfile
22
+ gem 'activeadmin_trumbowyg'
23
+
24
+ # Run generator
25
+ rails generate activeadmin_trumbowyg:install
26
+ ```
27
+
28
+ ## 1. Create Rails Application
29
+
30
+ ```bash
31
+ # For Rails 8 (Propshaft included by default):
32
+ rails new my_admin_app --css=tailwind --javascript=esbuild
33
+ cd my_admin_app
34
+
35
+ # For Rails 7, we'll add Propshaft in the next step
36
+ ```
37
+
38
+ ## 2. Add ActiveAdmin to Gemfile
39
+
40
+ ```ruby
41
+ # Gemfile
42
+ gem 'activeadmin', '~> 4.0.0.beta16'
43
+ gem 'importmap-rails', '~> 2.0' # Required for ActiveAdmin 4
44
+
45
+ # For Rails 7, add Propshaft (Rails 8 includes it by default):
46
+ gem 'propshaft' # Required - Sprockets is not supported
47
+
48
+ # Optional: Add your vendor packages
49
+ # gem 'activeadmin_trumbowyg' # Or other AA extensions
50
+ ```
51
+
52
+ ```bash
53
+ bundle install
54
+ ```
55
+
56
+ ## 3. Install ActiveAdmin
57
+
58
+ ```bash
59
+ rails generate active_admin:install
60
+
61
+ # This creates:
62
+ # - config/initializers/active_admin.rb
63
+ # - app/admin/ directory
64
+ # - db/migrate/xxx_create_active_admin_comments.rb
65
+ ```
66
+
67
+ ## 4. Run Migrations
68
+
69
+ ```bash
70
+ rails db:create
71
+ rails db:migrate
72
+ rails db:seed # Creates default admin user if using Devise
73
+ ```
74
+
75
+ ## 5. Install NPM Dependencies
76
+
77
+ ```bash
78
+ # Install ActiveAdmin Tailwind plugin and other dependencies
79
+ npm install --save-dev @activeadmin/activeadmin@^3.3.0
80
+
81
+ # If you need jQuery plugins
82
+ npm install jquery
83
+
84
+ # Install vendor packages via NPM
85
+ # For activeadmin_trumbowyg gem users with esbuild/webpack:
86
+ npm install @rocket-sensei/activeadmin_trumbowyg
87
+
88
+ # Or install Trumbowyg directly:
89
+ # npm install trumbowyg
90
+ ```
91
+
92
+ ## 6. Configure Tailwind (CRITICAL!)
93
+
94
+ ```javascript
95
+ // tailwind.config.js - Convert to ESM format
96
+ // Rename to tailwind.config.mjs
97
+
98
+ import activeAdminPlugin from '@activeadmin/activeadmin/plugin'
99
+ import { execSync } from 'node:child_process'
100
+
101
+ let activeAdminPath = null
102
+ try {
103
+ activeAdminPath = execSync('bundle show activeadmin', { encoding: 'utf8' }).trim()
104
+ } catch (e) {
105
+ console.warn('Could not find activeadmin gem path')
106
+ }
107
+
108
+ export default {
109
+ content: [
110
+ './public/*.html',
111
+ './app/helpers/**/*.rb',
112
+ './app/javascript/**/*.js',
113
+ './app/views/**/*.{erb,haml,html,slim}',
114
+ './app/admin/**/*.rb',
115
+ // Include ActiveAdmin gem views
116
+ ...(activeAdminPath ? [
117
+ `${activeAdminPath}/app/views/**/*.{arb,erb,html,rb}`,
118
+ `${activeAdminPath}/vendor/javascript/flowbite.js`,
119
+ `${activeAdminPath}/plugin.js`,
120
+ ] : [])
121
+ ],
122
+ darkMode: 'selector',
123
+ theme: {
124
+ extend: {
125
+ fontFamily: {
126
+ sans: ['Inter var', 'sans-serif'],
127
+ },
128
+ },
129
+ },
130
+ plugins: [
131
+ activeAdminPlugin,
132
+ // Other plugins like forms, typography
133
+ ],
134
+ // CRITICAL: Add safelist for ActiveAdmin dynamic classes
135
+ safelist: [
136
+ // Grid and layout
137
+ 'grid', 'gap-4', 'gap-6', 'lg:grid-cols-3', 'md:grid-cols-2',
138
+ 'col-span-2', 'col-span-3', 'lg:col-span-2', 'lg:col-span-1',
139
+ // Flexbox
140
+ 'flex', 'flex-col', 'flex-row', 'flex-wrap', 'items-center',
141
+ 'justify-between', 'justify-center', 'items-start', 'items-end',
142
+ // Spacing
143
+ 'p-4', 'p-6', 'px-4', 'px-6', 'py-2', 'py-4', 'm-0', 'mx-auto',
144
+ 'mt-4', 'mb-4', 'ml-auto', 'mr-auto', 'space-y-4', 'space-x-4',
145
+ // Display
146
+ 'block', 'inline-block', 'hidden', 'lg:hidden', 'lg:block', 'lg:flex',
147
+ // Width/Height
148
+ 'w-full', 'w-auto', 'w-64', 'h-full', 'min-h-screen', 'max-w-7xl',
149
+ // Typography
150
+ 'text-sm', 'text-base', 'text-lg', 'text-xl', 'font-medium', 'font-semibold',
151
+ // Colors
152
+ 'bg-white', 'bg-gray-50', 'bg-gray-100', 'text-gray-900', 'text-gray-600',
153
+ 'dark:bg-gray-800', 'dark:bg-gray-900', 'dark:text-white', 'dark:text-gray-300',
154
+ // Borders
155
+ 'border', 'border-gray-200', 'dark:border-gray-700', 'rounded-lg', 'rounded-md',
156
+ // Forms
157
+ 'form-input', 'form-select', 'form-checkbox',
158
+ // Position & Z-index
159
+ 'relative', 'absolute', 'fixed', 'sticky', 'top-0', 'left-0', 'right-0',
160
+ 'z-10', 'z-20', 'z-30', 'z-40', 'z-50',
161
+ // Shadows
162
+ 'shadow', 'shadow-md', 'shadow-lg',
163
+ // Tables
164
+ 'table-auto', 'border-collapse',
165
+ // Buttons
166
+ 'inline-flex', 'cursor-pointer'
167
+ ]
168
+ }
169
+ ```
170
+
171
+ ## 7. Update Package.json Scripts
172
+
173
+ ```json
174
+ {
175
+ "name": "my-admin-app",
176
+ "scripts": {
177
+ "build:css": "tailwindcss -c tailwind.config.mjs -i ./app/assets/stylesheets/application.tailwind.css -o ./app/assets/builds/application.css --minify",
178
+ "build:js": "esbuild app/javascript/*.* --bundle --sourcemap --format=esm --outdir=app/assets/builds --public-path=/assets --inject:./inject-jquery.js",
179
+ "build": "npm run build:css && npm run build:js",
180
+ "watch:css": "npm run build:css -- --watch",
181
+ "watch:js": "npm run build:js -- --watch"
182
+ }
183
+ }
184
+ ```
185
+
186
+ ## 8. Create jQuery Injection (if using jQuery plugins)
187
+
188
+ ```javascript
189
+ // inject-jquery.js (in project root)
190
+ export { default as $ } from 'jquery/dist/jquery.js'
191
+ export { default as jQuery } from 'jquery/dist/jquery.js'
192
+ ```
193
+
194
+ ## 9. Set Up Application CSS
195
+
196
+ ```css
197
+ /* app/assets/stylesheets/application.tailwind.css */
198
+ @tailwind base;
199
+ @tailwind components;
200
+ @tailwind utilities;
201
+
202
+ /* ActiveAdmin custom styles */
203
+ @layer components {
204
+ /* Custom component styles */
205
+ .admin-button {
206
+ @apply px-4 py-2 bg-blue-600 text-white rounded-md hover:bg-blue-700;
207
+ }
208
+ }
209
+
210
+ /* Import vendor CSS if needed */
211
+ /* Note: @rocket-sensei/activeadmin_trumbowyg NPM package includes CSS automatically */
212
+ /* For manual Trumbowyg setup: @import 'trumbowyg/dist/ui/trumbowyg.css'; */
213
+ ```
214
+
215
+ ## 10. Set Up Application JavaScript
216
+
217
+ ```javascript
218
+ // app/javascript/application.js
219
+ import "@hotwired/turbo-rails"
220
+ import "./controllers"
221
+
222
+ // If using jQuery and plugins
223
+ import $ from 'jquery'
224
+ window.$ = window.jQuery = $
225
+
226
+ // Import vendor libraries via NPM packages
227
+ // For activeadmin_trumbowyg gem users with esbuild/webpack:
228
+ // import '@rocket-sensei/activeadmin_trumbowyg'
229
+
230
+ // Or import Trumbowyg directly:
231
+ // import 'trumbowyg'
232
+
233
+ // Note: No generator needed when using esbuild/webpack with NPM packages
234
+ // The NPM package automatically handles initialization
235
+
236
+ // For manual plugin initialization if needed:
237
+ document.addEventListener('DOMContentLoaded', () => {
238
+ initializePlugins()
239
+ })
240
+
241
+ document.addEventListener('turbo:load', () => {
242
+ initializePlugins()
243
+ })
244
+
245
+ function initializePlugins() {
246
+ // Initialize your jQuery plugins if not auto-initialized
247
+ // $('.select2').select2()
248
+ // $('[data-trumbowyg]').trumbowyg() // Only if not using NPM package auto-init
249
+ }
250
+ ```
251
+
252
+ ## 11. Configure ActiveAdmin
253
+
254
+ ```ruby
255
+ # config/initializers/active_admin.rb
256
+ ActiveAdmin.setup do |config|
257
+ config.site_title = "My Admin App"
258
+
259
+ # Authentication (if using Devise)
260
+ config.authentication_method = :authenticate_admin_user!
261
+ config.current_user_method = :current_admin_user
262
+ config.logout_link_path = :destroy_admin_user_session_path
263
+
264
+ # Or disable authentication for development
265
+ # config.authentication_method = false
266
+ # config.current_user_method = false
267
+
268
+ config.batch_actions = true
269
+ config.filter_attributes = [:encrypted_password, :password, :password_confirmation]
270
+ config.localize_format = :long
271
+ end
272
+ ```
273
+
274
+ ## 12. Create Sample Model and Admin Resource
275
+
276
+ ```bash
277
+ # Generate a model
278
+ rails generate model Product name:string description:text price:decimal active:boolean
279
+ rails db:migrate
280
+ ```
281
+
282
+ ```ruby
283
+ # app/admin/products.rb
284
+ ActiveAdmin.register Product do
285
+ permit_params :name, :description, :price, :active
286
+
287
+ index do
288
+ selectable_column
289
+ id_column
290
+ column :name
291
+ column :price do |product|
292
+ number_to_currency product.price
293
+ end
294
+ column :active
295
+ column :created_at
296
+ actions
297
+ end
298
+
299
+ filter :name
300
+ filter :price
301
+ filter :active
302
+ filter :created_at
303
+
304
+ form do |f|
305
+ f.semantic_errors
306
+ f.inputs do
307
+ f.input :name
308
+ f.input :description
309
+ f.input :price
310
+ f.input :active
311
+ end
312
+ f.actions
313
+ end
314
+
315
+ show do
316
+ attributes_table do
317
+ row :name
318
+ row :description
319
+ row :price do |product|
320
+ number_to_currency product.price
321
+ end
322
+ row :active
323
+ row :created_at
324
+ row :updated_at
325
+ end
326
+ end
327
+ end
328
+ ```
329
+
330
+ ## 13. Build Assets
331
+
332
+ ```bash
333
+ npm run build
334
+ ```
335
+
336
+ ## 14. Start Rails Server
337
+
338
+ ```bash
339
+ rails server
340
+ ```
341
+
342
+ Visit http://localhost:3000/admin
343
+
344
+ Default credentials (if using Devise):
345
+ - Email: admin@example.com
346
+ - Password: password
347
+
348
+ ## 15. Production Deployment
349
+
350
+ ### Asset Precompilation
351
+
352
+ ```ruby
353
+ # config/environments/production.rb
354
+ config.assets.compile = false
355
+ config.assets.precompile += %w[ application.js application.css ]
356
+ ```
357
+
358
+ ### Build Command for Production
359
+
360
+ ```bash
361
+ RAILS_ENV=production bundle exec rails assets:precompile
362
+ ```
363
+
364
+ ### Heroku Deployment
365
+
366
+ ```json
367
+ // package.json
368
+ {
369
+ "scripts": {
370
+ "build": "npm run build:css && npm run build:js",
371
+ "build:css": "tailwindcss -c tailwind.config.mjs -i ./app/assets/stylesheets/application.tailwind.css -o ./app/assets/builds/application.css --minify",
372
+ "build:js": "esbuild app/javascript/*.* --bundle --sourcemap --format=esm --outdir=app/assets/builds --public-path=/assets --minify"
373
+ }
374
+ }
375
+ ```
376
+
377
+ Add buildpacks:
378
+ ```bash
379
+ heroku buildpacks:add heroku/nodejs
380
+ heroku buildpacks:add heroku/ruby
381
+ ```
382
+
383
+ ## 16. Adding Vendor Packages (Example: Trumbowyg)
384
+
385
+ ### Method 1: Using the NPM Package (Recommended for esbuild/webpack)
386
+
387
+ ```bash
388
+ # Install the official NPM package
389
+ npm install @rocket-sensei/activeadmin_trumbowyg
390
+ ```
391
+
392
+ ```javascript
393
+ // app/javascript/application.js or app/javascript/active_admin.js
394
+ import '@rocket-sensei/activeadmin_trumbowyg'
395
+
396
+ // That's it! The package auto-initializes Trumbowyg on elements with data-provider="trumbowyg"
397
+ // No generator needed for esbuild/webpack setups
398
+ ```
399
+
400
+ ```ruby
401
+ # app/admin/posts.rb
402
+ ActiveAdmin.register Post do
403
+ form do |f|
404
+ f.inputs do
405
+ f.input :title
406
+ f.input :body, as: :text, input_html: {
407
+ 'data-provider': 'trumbowyg',
408
+ class: 'trumbowyg-editor'
409
+ }
410
+ end
411
+ f.actions
412
+ end
413
+ end
414
+ ```
415
+
416
+ ### Method 2: Using Trumbowyg Directly (Manual Setup)
417
+
418
+ ```bash
419
+ npm install trumbowyg jquery
420
+ ```
421
+
422
+ ```javascript
423
+ // app/javascript/admin.js
424
+ import $ from 'jquery'
425
+ import 'trumbowyg'
426
+
427
+ window.$ = window.jQuery = $
428
+
429
+ function initTrumbowyg() {
430
+ $('[data-trumbowyg]').each(function() {
431
+ if (!$(this).hasClass('trumbowyg-active')) {
432
+ $(this).trumbowyg({
433
+ svgPath: '/assets/trumbowyg/icons.svg'
434
+ })
435
+ $(this).addClass('trumbowyg-active')
436
+ }
437
+ })
438
+ }
439
+
440
+ document.addEventListener('DOMContentLoaded', initTrumbowyg)
441
+ document.addEventListener('turbo:load', initTrumbowyg)
442
+ ```
443
+
444
+ Copy icons (only needed for manual setup):
445
+ ```bash
446
+ cp node_modules/trumbowyg/dist/ui/icons.svg public/assets/trumbowyg/
447
+ ```
448
+
449
+ ## Common Issues & Solutions
450
+
451
+ ### Issue: Unstyled Admin Interface
452
+ **Solution**:
453
+ 1. Ensure Tailwind safelist is configured
454
+ 2. Check that CSS file is > 100KB
455
+ 3. Rebuild assets with `npm run build`
456
+
457
+ ### Issue: JavaScript Not Loading
458
+ **Solution**:
459
+ 1. Check esbuild configuration
460
+ 2. Ensure importmap or esbuild is properly configured
461
+ 3. Check browser console for errors
462
+
463
+ ### Issue: Dark Mode Not Working
464
+ **Solution**:
465
+ 1. Ensure `darkMode: 'selector'` in Tailwind config
466
+ 2. ActiveAdmin plugin handles dark mode toggle
467
+
468
+ ### Issue: Forms Not Styled
469
+ **Solution**:
470
+ 1. Add form-related classes to safelist
471
+ 2. Ensure ActiveAdmin plugin is loaded
472
+
473
+ ## Testing Setup
474
+
475
+ ```ruby
476
+ # Gemfile - test group
477
+ group :test do
478
+ gem 'rspec-rails'
479
+ gem 'capybara'
480
+ gem 'factory_bot_rails'
481
+ end
482
+ ```
483
+
484
+ ```ruby
485
+ # spec/features/admin_spec.rb
486
+ require 'rails_helper'
487
+
488
+ RSpec.describe 'Admin Interface', type: :feature do
489
+ it 'loads the dashboard' do
490
+ visit '/admin'
491
+ expect(page).to have_content('Dashboard')
492
+ end
493
+ end
494
+ ```
495
+
496
+ ## Folder Structure Summary
497
+
498
+ ```
499
+ my_admin_app/
500
+ ├── app/
501
+ │ ├── admin/ # ActiveAdmin resources
502
+ │ ├── assets/
503
+ │ │ ├── builds/ # Compiled assets
504
+ │ │ ├── config/
505
+ │ │ │ └── manifest.js
506
+ │ │ └── stylesheets/
507
+ │ │ └── application.tailwind.css
508
+ │ └── javascript/
509
+ │ ├── application.js
510
+ │ └── active_admin.js # Optional: ActiveAdmin-specific JS
511
+ ├── config/
512
+ │ └── initializers/
513
+ │ └── active_admin.rb
514
+ ├── node_modules/
515
+ │ └── @rocket-sensei/
516
+ │ └── activeadmin_trumbowyg/ # NPM package location
517
+ ├── public/
518
+ │ └── assets/ # Static vendor assets
519
+ ├── package.json
520
+ ├── tailwind.config.mjs # ESM format!
521
+ └── inject-jquery.js # If using jQuery
522
+ ```
523
+
524
+ ## Key Installation Differences
525
+
526
+ ### NPM Package (@rocket-sensei/activeadmin_trumbowyg)
527
+ - **For**: esbuild/webpack users
528
+ - **Installation**: `npm install @rocket-sensei/activeadmin_trumbowyg`
529
+ - **Import**: `import '@rocket-sensei/activeadmin_trumbowyg'`
530
+ - **Generator**: Not needed
531
+ - **JavaScript paths**: Uses `active_admin/` prefix
532
+ - **Auto-initialization**: Yes, handles Turbo events automatically
533
+
534
+ ### Ruby Gem (activeadmin_trumbowyg)
535
+ - **For**: Importmap/Propshaft users
536
+ - **Installation**: Add to Gemfile
537
+ - **Generator**: Required (`rails g activeadmin_trumbowyg:install`)
538
+ - **JavaScript paths**: Uses `active_admin/` prefix
539
+ - **Asset handling**: Via Rails asset pipeline
540
+
541
+ ## Success Checklist
542
+
543
+ ✅ Rails app created with esbuild and Tailwind
544
+ ✅ ActiveAdmin installed and configured
545
+ ✅ Tailwind config with ActiveAdmin plugin and safelist
546
+ ✅ Assets building correctly (CSS > 100KB)
547
+ ✅ Admin interface fully styled
548
+ ✅ Dark mode toggle working
549
+ ✅ Forms properly styled
550
+ ✅ No JavaScript console errors
551
+ ✅ Vendor packages integrated (if using NPM: @rocket-sensei/activeadmin_trumbowyg)
552
+ ✅ Trumbowyg editor rendering on forms with `data-provider="trumbowyg"`