Module: Hibiki::Rails::Generators::ScaffoldTransportStylesheet
- Included in:
- ScaffoldControllerGenerator
- Defined in:
- lib/generators/hibiki/rails/scaffold_transport_stylesheet.rb
Overview
Emitting the transport stylesheet, and getting it onto the page.
The rules key on the client's attributes and know nothing about any model, so this is ONE file per app rather than one per resource — which is also why every write here is idempotent: scaffolding a second resource finds it already present and leaves it, and the wiring line it needs is added at most once.
Getting it onto the page is the part with branches, because "the main stylesheet" is not one thing. Three app shapes cover everything the generators have been run against, and the fourth branch is a printed instruction rather than a guess.
Constant Summary collapse
- STYLESHEET =
"app/assets/stylesheets/hibiki_busy.css"- LOGICAL_NAME =
"hibiki_busy"- IMPORT_LINE =
The LEADING ./ is not decoration. Tailwind 4's CLI resolves imports the way a bundler does, so a bare "hibiki_busy.css" is looked up as a PACKAGE and the build fails with "Can't resolve" — even though the file is sitting next to the entry stylesheet.
%(@import "./hibiki_busy.css";)- ENTRIES =
The entry stylesheet a bundler compiles, in the order the two conventions are checked. cssbundling-rails keeps it beside the other stylesheets; tailwindcss-rails gives it its own directory, so the import has to climb out of it.
{ "app/assets/stylesheets/application.tailwind.css" => IMPORT_LINE, "app/assets/tailwind/application.css" => %(@import "../stylesheets/hibiki_busy.css";) }.freeze
- LAYOUT =
"app/views/layouts/application.html.erb"- BULK_LINK =
Propshaft's bulk helper: :app links every css file under app/assets, :all every one on the load path. Either way a new file in that directory is already on the page and there is nothing to wire.
/stylesheet_link_tag\s+:(?:app|all)\b/- SINGLE_LINK =
Anchor for the fallback, and deliberately narrow: it matches the line a stock layout carries so the new tag lands directly after it, in the
, where a stylesheet belongs. /^.*stylesheet_link_tag\s+["':].*$\n/- LINK_TAG =
%( <%= stylesheet_link_tag "hibiki_busy", "data-turbo-track": "reload" %>\n)- TAILWIND_IMPORT =
Where the import lands: directly below Tailwind's own. CSS wants every @import before any other statement, so appending after a
@plugin "daisyui"line emits invalid CSS — and Tailwind's entry always opens with its own import, which ours must follow anyway. An entry someone rewrote without that line just gets the import appended; assume they will place it themselves. (Order never protects the rules from the utilities — being unlayered does, see the stylesheet's own header.) %(@import "tailwindcss";\n)