Skip to content

Add a tom_select generator and run it from core_setup - #210

Open
OutlawAndy wants to merge 6 commits into
masterfrom
tom-select-generator
Open

OutlawAndy wants to merge 6 commits into
masterfrom
tom-select-generator

Conversation

@OutlawAndy

@OutlawAndy OutlawAndy commented Sep 29, 2026 •

Copy link
Copy Markdown
Member

Why?

No generator sets up Tom Select, even though the rspec generator's SelectHelper already drives it. Apps copy the input and Stimulus controller from each other by hand. fujifilm_cimba's copy has Stimulus actions that keep Tom Select's selected values through a Turbo morph. tarsco_bolted_tank's has the better settings. Turbo morphs are now routine because turbo_form re-renders dynamic forms by morphing. This PR combines the two and makes that the default.

What Changed

  • New rolemodel:tom_select generator, modeled on rolemodel:tailored_select:
    • adds the tom-select package and imports tom-select/dist/css/tom-select.css
    • adds a tom-select Stimulus controller, bound to the <select> itself, and updates the manifest. Its settings come from tarsco_bolted_tank: create from the input's allow_create: option, delimiter: null, the search text clears after a pick, and remove_button only for multiple selects. There's no dropdown_input plugin, so the rspec SelectHelper can type into the control.
    • its morph handling comes from fujifilm_cimba. turbo:before-morph-element saves the current markup into Tom Select's revert settings and destroys the instance. turbo:morph-element rebuilds it. Both are :self actions on the select, so nothing depends on a page-wide morph handler.
    • if SimpleForm is present, adds tom_select and grouped_tom_select inputs that attach the controller and both morph actions. The grouped input gets the morph actions too.
  • The inputs call super with the Stimulus options merged into wrapper_options, instead of re-implementing SimpleForm's input. Rendered in tarsco_bolted_tank, the HTML matches tarsco's input for plain, allow_create: and custom data: cases, apart from the added morph actions.
  • rolemodel:core_setup and rolemodel:all run rolemodel:tom_select right after rolemodel:simple_form
  • The all generator spec derives the expected generators from lib/generators/rolemodel instead of a hard-coded list. It expects a directory's own all generator when it has one, and keeps a named exclusion list (core_setup, tailored_select). That showed rolemodel:all never ran rolemodel:turbo:all, so it does now, and the rolemodel:all README lists the Turbo generators in place of a dead ./modals link.
  • rolemodel:simple_form drops its Bundler.with_unbundled_env wrapper. bundle_command already runs in Bundler.with_original_env.

Pre-merge checklist

  • Update relevant READMEs (root README, generators README, core_setup README, new tom_select README/USAGE)

Notes

  • Left out tarsco's sync action, which re-syncs every tom-select 100ms after any Turbo Stream renders. It's left over from turbo_fetch. A stream that replaces the select reconnects the controller anyway.
  • No Optics-specific styling. cimba's and tarsco's overrides depend on their own SCSS. The stock Tom Select stylesheet is imported instead.
  • Full suite passes locally (110 examples).

Screenshots

N/A — no UI changes in this gem

🤖 Generated with Claude Code

OutlawAndy and others added 6 commits September 29, 2026 11:51
bundle_command already runs in Bundler.with_original_env.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
Installs tom-select, its stylesheet, and a Stimulus controller that
tears Tom Select down before a Turbo morph and rebuilds it after, so the
selected values survive. When SimpleForm is present it also installs the
tom_select and grouped_tom_select inputs, both wired to those morph
actions. core_setup runs it right after simple_form.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
The controller binds to the select itself instead of a target, takes a
create value from the input's allow_create option, keeps commas in
values, clears the search text after a pick, and drops the
dropdown_input plugin so the rspec SelectHelper can type into the
control. The per-element morph actions stay.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
The all generator spec now derives the expected generators from
lib/generators/rolemodel, delegating to a directory's all generator when
it has one, minus a named exclusion list. That surfaced rolemodel:all
never running rolemodel:turbo:all, which core_setup does, so it runs it
now and its README lists the Turbo generators in place of a dead Modals
link. The core_setup ordering spec goes away.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

1 participant