Module: Clsx
- Extended by:
- Helper
- Defined in:
- lib/clsx.rb,
lib/clsx/helper.rb,
lib/clsx/version.rb,
lib/clsx/tailwind_merge.rb
Overview
Opt-in Tailwind merging. Requiring this file (once, at boot) pulls in the
tailwind_merge gem and adds a
merged variant of clsx — Helper#twm, the Helper#twm mixin method, and the
Twm[] shortcut — that resolves conflicting Tailwind utilities
(e.g. "px-2 px-4" becomes "px-4").
+clsx+/+cn+ are left untouched and stay pure; only +twm+/+Twm+ merge. Without requiring this file the core gem carries no dependency.
Defined Under Namespace
Constant Summary collapse
- VERSION =
'1.2.0'
Constants included from Helper
Class Attribute Summary collapse
-
.merger ⇒ #merge
Process-wide merger, built once.
Class Method Summary collapse
-
.[] ⇒ String?
Build a CSS class string from an arbitrary mix of arguments.
Methods included from Helper
Class Attribute Details
.merger ⇒ #merge
Process-wide merger, built once. Building a TailwindMerge::Merger is expensive, so double-checked locking constructs it exactly once even under concurrent first use; after that the lock is never taken again.
34 35 36 |
# File 'lib/clsx/tailwind_merge.rb', line 34 def merger @merger || @merger_mutex.synchronize { @merger ||= TailwindMerge::Merger.new } end |
Class Method Details
.[] ⇒ String?
Build a CSS class string from an arbitrary mix of arguments.
Falsy values (+nil+, false) and standalone true are discarded.
Duplicates are eliminated. Returns nil (not "") when no classes apply.
17 18 19 |
# File 'lib/clsx.rb', line 17 def self.[](*) clsx(*) end |