Module: Hibiki::Rails::Generators::ScaffoldPhlexHelpers

Included in:
ScaffoldControllerGenerator
Defined in:
lib/generators/hibiki/rails/scaffold_phlex_helpers.rb

Overview

What differs between the two view layers OUTSIDE the view templates.

The channels and the controller are one template set, not two: they differ by about eight lines across 470, and forking them to change eight would pay the phase's stated maintenance cost — every future change made twice — on the files that have the least to gain from it. So each divergent line is emitted from here instead, and under ERB every method returns exactly the text those templates carried before --phlex existed.

The view templates themselves genuinely are two trees (§19.4): a class token map can restyle markup, but nothing short of an HTML-AST DSL can turn <div id="x"> into div(id: "x").

Constant Summary collapse

PHLEX_BASE =

What bin/rails g phlex:install leaves behind, and what generated components need from it: a base class to inherit, and an autoloader that maps app/views onto the Views namespace.

"app/views/base.rb"
PHLEX_INITIALIZER =
"config/initializers/phlex.rb"
PHLEX_NAMESPACE =
/namespace:\s*Views\b/
HELPER_MODULES =

Rails helper -> the phlex-rails module that adapts it. Mostly camelize, with the two exceptions that gem's own REDIRECTS table names: check_box_tag lives under CheckboxTag and text_area_tag under TextAreaTag. Both spellings resolve — REDIRECTS installs a const_missing — but the alias is the one phlex-rails calls legacy, so generated code should not be written in it.

{
  check_box_tag: "CheckboxTag",
  text_area_tag: "TextAreaTag"
}.freeze
PLAIN_TYPES =

What Phlex's #plain renders without help. It handles String, Symbol, Integer and Float and RAISES on anything else — deliberately, so a stray object cannot land on the page as "#Foo:0x…". ERB's <%= %> simply called to_s, so this is the one place the port cannot be a transliteration: a date, a time or a decimal column needs an explicit to_s or the page raises the first time it renders.

%i[string text integer float].freeze