From 5e9bddbdfc4bed3ca4d105da3bb8f5bdf5f7750a Mon Sep 17 00:00:00 2001 From: Philippe Date: Mon, 15 Jun 2026 19:00:57 +0200 Subject: [PATCH 1/5] refacto: token-driven button variants, radius tokens, and DRY component rendering Make the gem expressive enough that downstream forks (DsCta/DsInfoBox) are unnecessary: customization happens through token configuration, not component rewrites. - tokens: generalize storage/emission behind a GROUPS table (adding a group is one entry), add a radius group, a button_style(variant) resolver, a bulk load(...) helper, and a single to_h snapshot reader - extract ButtonStyle (value object + .from factory) and ScssSerializer (SRP) - Cta/Button share a bulletproof_button_table scaffold in Base; Cta is token-inline-driven (now supporting outline secondary via tokens) while Button stays CSS-driven; drop the hardcoded 4px radius - InfoBox: box-scoped info_box_* tokens (fall back to page palette) + box radius - SCSS: radius always applied on .button/.cta (drop opt-in .radius), mirror secondary color/border and info-box radius from tokens - document new tokens + bulk loader in the generator initializer --- .rubocop.yml | 4 + .../stylesheets/activemail/_components.scss | 31 ++--- .../stylesheets/activemail/_settings.scss | 14 ++- lib/activemail/components/base.rb | 18 +++ lib/activemail/components/button.rb | 15 +-- lib/activemail/components/cta.rb | 36 ++++-- lib/activemail/components/info_box.rb | 9 +- lib/activemail/tokens.rb | 108 +++++++++++------- lib/activemail/tokens/button_style.rb | 31 +++++ lib/activemail/tokens/scss_serializer.rb | 23 ++++ .../activemail/templates/initializer.rb | 19 +++ lib/tasks/activemail.rake | 2 +- test/components/cta_test.rb | 25 ++++ test/components/info_box_test.rb | 39 +++++++ test/scss_framework_test.rb | 17 +++ test/tokens_test.rb | 65 ++++++++++- 16 files changed, 375 insertions(+), 81 deletions(-) create mode 100644 lib/activemail/tokens/button_style.rb create mode 100644 lib/activemail/tokens/scss_serializer.rb create mode 100644 test/components/info_box_test.rb diff --git a/.rubocop.yml b/.rubocop.yml index 2bb85c0..26a4c8a 100644 --- a/.rubocop.yml +++ b/.rubocop.yml @@ -26,6 +26,10 @@ Metrics/BlockLength: # Test files: autofix only, relaxed metrics. Metrics/ClassLength: + # Declarative data literals (token tables) are length, not complexity. + CountAsOne: + - array + - hash Exclude: - 'test/**/*' diff --git a/app/assets/stylesheets/activemail/_components.scss b/app/assets/stylesheets/activemail/_components.scss index e5877e9..d605906 100644 --- a/app/assets/stylesheets/activemail/_components.scss +++ b/app/assets/stylesheets/activemail/_components.scss @@ -1,12 +1,15 @@ // Background on both inner cell and link so the whole bulletproof button -// (table.button > td > table > td > a) is filled and clickable. -.button table td { +// (table.button > td > table > td > a) is filled and clickable. Radius is applied +// by default (progressive enhancement — clients that don't support it just ignore it), +// keeping CSS-driven