class Docks::NamingConventions::BEM

Constants

STATEFUL_WORDS

Public Instance Methods

base_component(component_name) click to toggle source
# File lib/docks/naming_conventions/bem_naming_convention.rb, line 8
def base_component(component_name)
  component_name.split("--").first.split("__").first
end
base_component?(component_name) click to toggle source
# File lib/docks/naming_conventions/bem_naming_convention.rb, line 12
def base_component?(component_name)
  component_name == base_component(component_name)
end
clean_variation_name(variation_name, component_name) click to toggle source
# File lib/docks/naming_conventions/bem_naming_convention.rb, line 25
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
component(component_name) click to toggle source
# File lib/docks/naming_conventions/bem_naming_convention.rb, line 16
def component(component_name)
  component_name.gsub(/--[^_]*/, "")
end
disconnected_state?(state_name) click to toggle source
# File lib/docks/naming_conventions/bem_naming_convention.rb, line 40
def disconnected_state?(state_name)
  state?(state_name) && !state_name.include?("--")
end
parent_component(component_name) click to toggle source
# File lib/docks/naming_conventions/bem_naming_convention.rb, line 20
def parent_component(component_name)
  component_name = component(component_name)
  component_name.sub(/__[^_]*$/, "")
end
state?(state_name) click to toggle source
# File lib/docks/naming_conventions/bem_naming_convention.rb, line 31
def state?(state_name)
  state_name = state_name.split("--").last
  STATEFUL_WORDS.any? { |word| state_name.start_with?(word) }
end
variant?(variant_name) click to toggle source
# File lib/docks/naming_conventions/bem_naming_convention.rb, line 36
def variant?(variant_name)
  variant_name.split("--").length > 1 && !state?(variant_name)
end