class Sass::Script::Value::String
def self.quote(contents, opts = {})
@options opts :sass [String]
always emitted unquoted. If `nil`, quoting is determined automatically.
The preferred quote style for quoted strings. If `:none`, strings are
@options opts :quote [String]
Returns the quoted string representation of `contents`.
def self.quote(contents, opts = {}) quote = opts[:quote] # Short-circuit if there are no characters that need quoting. unless contents =~ /[\n\\"']|\#\{/ quote ||= '"' return "#{quote}#{contents}#{quote}" end if quote.nil? if contents.include?('"') if contents.include?("'") quote = '"' else quote = "'" end else quote = '"' end end # Replace single backslashes with multiples. contents = contents.gsub("\\", "\\\\\\\\") # Escape interpolation. contents = contents.gsub('#{', "\\\#{") if opts[:sass] if quote == '"' contents = contents.gsub('"', "\\\"") else contents = contents.gsub("'", "\\'") end contents = contents.gsub(/\n(?![a-fA-F0-9\s])/, "\\a").gsub("\n", "\\a ") "#{quote}#{contents}#{quote}" end