Module: ShadcnViewComponent

Defined in:
lib/shadcn_view_component/icons.rb,
lib/shadcn_view_component.rb,
lib/shadcn_view_component/engine.rb,
lib/shadcn_view_component/themes.rb,
lib/shadcn_view_component/version.rb,
lib/shadcn_view_component/form_builder.rb,
lib/shadcn_view_component/icon_registry.rb,
app/helpers/shadcn_view_component/form_helper.rb,
app/helpers/shadcn_view_component/theme_helper.rb,
lib/generators/shadcn_view_component/install/install_generator.rb

Overview

Generated from the vendored lucide SVGs (vendor/lucide/icons, taken from lucide-static at the version in vendor/lucide/REVISION) — do not edit by hand, run rake icons:build.

Defined Under Namespace

Modules: FormHelper, Generators, IconRegistry, Icons, ThemeHelper, Themes Classes: Engine, FormBuilder

Constant Summary collapse

DEFAULT_CACHE_SIZE =

tailwind_merge defaults to a 500-entry LRU. That is small for a page built from these components: the library's own default variants already occupy around a hundred entries, and a caller-computed class (w-[#{percent}%] in a long table, say) adds one per distinct value. Once the working set of a page exceeds the cache, a Rails render is the LRU's worst case — it cycles the same keys every request, so the hit rate collapses and stays collapsed.

The measured difference is roughly 0.6µs per merge on a hit against ~100µs on a miss, and nothing in a stack trace would point here. So: a bigger default, and a knob for apps that need more.

10_000
VERSION =
"0.3.3"

Class Attribute Summary collapse

Class Method Summary collapse

Class Attribute Details

.cache_sizeObject



28
29
30
# File 'lib/shadcn_view_component.rb', line 28

def cache_size
  @cache_size ||= DEFAULT_CACHE_SIZE
end

Class Method Details

.build_mergerObject



43
44
45
# File 'lib/shadcn_view_component.rb', line 43

def build_merger
  @merger = TailwindMerge::Merger.new(config: { cache_size: cache_size })
end

.class_cacheObject

Compiled class strings for components rendered without caller classes, which is the overwhelming majority of call sites. The result is a pure function of the component class and its variants, and the style blocks are static once loaded — so this both saves the merge and, more importantly, keeps the library's own strings out of the LRU, leaving the whole budget to what callers actually vary.



66
67
68
# File 'lib/shadcn_view_component.rb', line 66

def class_cache
  @class_cache ||= Concurrent::Map.new
end

.cn(*args) ⇒ Object

cn(...) — flattens, compacts and merges Tailwind classes.



48
49
50
# File 'lib/shadcn_view_component.rb', line 48

def cn(*args)
  merger.merge(flatten_classes(args))
end

.mergerObject

Shared TailwindMerge instance used by ApplicationViewComponent#cn. This is the Ruby equivalent of shadcn's cn() helper (clsx + tailwind-merge): later classes win over conflicting earlier ones.

Built eagerly by the engine, because constructing it costs a few milliseconds and two Puma threads racing on ||= would each build one and throw a warm cache away.



39
40
41
# File 'lib/shadcn_view_component.rb', line 39

def merger
  @merger ||= build_merger
end

.reset!Object

Resets both the merger and the memoised component classes. For tests and for config.to_prepare in development, where the style blocks are redefined on every reload.



55
56
57
58
# File 'lib/shadcn_view_component.rb', line 55

def reset!
  @merger = nil
  class_cache.clear
end