Sha256: 35b05e631f814bb31e11b3181b2017519d2b15d81f293af2c9b889fc87c27b79
Contents?: true
Size: 1.25 KB
Versions: 3
Compression:
Stored size: 1.25 KB
Contents
require_relative "base_naming_convention.rb" module Docks module NamingConventions class BEM < Base STATEFUL_WORDS = %w(is) def base_component(component_name) component_name.split("--").first.split("__").first end def base_component?(component_name) component_name == base_component(component_name) end def component(component_name) component_name.gsub(/--[^_]*/, "") end def parent_component(component_name) component_name = component(component_name) component_name.sub(/__[^_]*$/, "") end def clean_variation_name(variation_name, component_name) return variation_name if disconnected_state?(variation_name) variation_name = variation_name.sub(Regexp.new("^(?:#{component_name})?(?:--)?"), "") "#{component_name}--#{variation_name}" end def state?(state_name) state_name = state_name.split("--").last STATEFUL_WORDS.any? { |word| state_name.start_with?(word) } end def variant?(variant_name) variant_name.split("--").length > 1 && !state?(variant_name) end def disconnected_state?(state_name) state?(state_name) && !state_name.include?("--") end end end end
Version data entries
3 entries across 3 versions & 1 rubygems