Class: TailwindMerge::Merger

Inherits:
Object
  • Object
show all
Includes:
Config, ModifierUtils
Defined in:
lib/tailwind_merge.rb

Constant Summary collapse

SPLIT_CLASSES_REGEX =
/\s+/

Constants included from ModifierUtils

TailwindMerge::ModifierUtils::IMPORTANT_MODIFIER

Constants included from Config

Config::ALIGN, Config::BLEND_MODES, Config::BLUR, Config::BORDER_COLOR, Config::BORDER_RADIUS, Config::BORDER_SPACING, Config::BORDER_WIDTH, Config::BREAKS, Config::BRIGHTNESS, Config::COLORS, Config::CONTRAST, Config::DEFAULTS, Config::FROM_THEME, Config::GAP, Config::GRADIENT_COLOR_STOPS, Config::GRADIENT_COLOR_STOP_POSITIONS, Config::GRAYSCALE, Config::HUE_ROTATE, Config::INSET, Config::INVERT, Config::LENGTH_WITH_EMPTY_AND_ARBITRARY, Config::LINE_STYLES, Config::MARGIN, Config::NUMBER_AND_ARBITRARY, Config::NUMBER_WITH_AUTO_AND_ARBITRARY, Config::OPACITY, Config::OVERFLOW, Config::OVERSCROLL, Config::PADDING, Config::POSITIONS, Config::SATURATE, Config::SCALE, Config::SEPIA, Config::SKEW, Config::SPACE, Config::SPACING, Config::SPACING_WITH_ARBITRARY, Config::SPACING_WITH_AUTO_AND_ARBITRARY, Config::TRANSLATE, Config::VALID_THEME_IDS, Config::ZERO_AND_EMPTY

Constants included from Validators

Validators::ARBITRARY_VALUE_REGEX, Validators::COLOR_FUNCTION_REGEX, Validators::FRACTION_REGEX, Validators::IMAGE_LABELS, Validators::IMAGE_REGEX, Validators::IS_ANY, Validators::IS_ARBITRARY_IMAGE, Validators::IS_ARBITRARY_LENGTH, Validators::IS_ARBITRARY_NUMBER, Validators::IS_ARBITRARY_POSITION, Validators::IS_ARBITRARY_SHADOW, Validators::IS_ARBITRARY_SIZE, Validators::IS_ARBITRARY_VALUE, Validators::IS_INTEGER, Validators::IS_LENGTH, Validators::IS_NUMBER, Validators::IS_PERCENT, Validators::IS_TSHIRT_SIZE, Validators::LENGTH_UNIT_REGEX, Validators::SHADOW_REGEX, Validators::SIZE_LABELS, Validators::STRING_LENGTHS, Validators::TSHIRT_UNIT_REGEX

Instance Method Summary collapse

Methods included from ModifierUtils

#sort_modifiers, #split_modifiers

Methods included from Config

#merge_configs

Methods included from Validators

arbitrary_value?, integer?, numeric?

Constructor Details

#initialize(config: {}) ⇒ Merger

Returns a new instance of Merger.



21
22
23
24
25
26
27
28
29
30
# File 'lib/tailwind_merge.rb', line 21

def initialize(config: {})
  @config = if config.fetch(:theme, nil)
    merge_configs(config)
  else
    TailwindMerge::Config::DEFAULTS.merge(config)
  end

  @class_utils = TailwindMerge::ClassUtils.new(@config)
  @cache = LruRedux::Cache.new(@config[:cache_size])
end

Instance Method Details

#merge(classes) ⇒ Object



32
33
34
35
36
37
38
39
40
# File 'lib/tailwind_merge.rb', line 32

def merge(classes)
  if classes.is_a?(Array)
    classes = classes.compact.join(" ")
  end

  @cache.getset(classes) do
    merge_class_list(classes)
  end
end