class SCSSBeautifier::Formatters::StringQuotes

Constants

STRING_WITHOUT_QUOTES_REGEX

Public Instance Methods

check_quotes(node) click to toggle source
# File lib/scss_beautifier/formatters/string_quotes.rb, line 6
def check_quotes(node)
  return unless node.value.is_a?(Sass::Script::Tree::Literal)

  # TODO Check for single or double quote preference
  str_without_quotes = extract_string_without_quotes(node.value.value.to_s)
  change_to_single_quotes(node) if str_without_quotes && !str_without_quotes.match(/'/)
end
visit_prop(node) click to toggle source
# File lib/scss_beautifier/formatters/string_quotes.rb, line 2
def visit_prop(node)
  check_quotes(node)
  visit_children(node)
end

Private Instance Methods

change_to_single_quotes(node) click to toggle source
# File lib/scss_beautifier/formatters/string_quotes.rb, line 24
def change_to_single_quotes(node)
  new_val = node.value.value.to_s.gsub('"', '\'')
  node.instance_variable_set(:@value, Sass::Script::Value::String.new(new_val))
end
extract_string_without_quotes(source) click to toggle source
# File lib/scss_beautifier/formatters/string_quotes.rb, line 29
def extract_string_without_quotes(source)
  return unless match = STRING_WITHOUT_QUOTES_REGEX.match(source)
  match[1]
end