mirror of
https://github.com/haml/haml.git
synced 2022-11-09 12:33:31 -05:00
[Sass] Have Sass::Script::String distinguish between strings and identifiers.
This commit is contained in:
parent
6ab26875b8
commit
e814ff6608
4 changed files with 23 additions and 3 deletions
|
@ -170,6 +170,8 @@ module Sass::Script
|
|||
# assert_type value, :Number
|
||||
#
|
||||
# Valid types are `:Bool`, `:Color`, `:Number`, and `:String`.
|
||||
# Note that `:String` will match both double-quoted strings
|
||||
# and unquoted identifiers.
|
||||
#
|
||||
# @param value [Sass::Script::Literal] A SassScript value
|
||||
# @param type [Symbol] The name of the type the value is expected to be
|
||||
|
|
|
@ -199,7 +199,7 @@ module Sass
|
|||
def string(re, open)
|
||||
return unless scan(STRING_REGULAR_EXPRESSIONS[[re, open]])
|
||||
@interpolation_stack << re if @scanner[2].empty? # Started an interpolated section
|
||||
[:string, Script::String.new(@scanner[1].gsub(/\\([^0-9a-f])/, '\1').gsub(/\\([0-9a-f]{1,4})/, "\\\\\\1"))]
|
||||
[:string, Script::String.new(@scanner[1].gsub(/\\([^0-9a-f])/, '\1').gsub(/\\([0-9a-f]{1,4})/, "\\\\\\1"), :string)]
|
||||
end
|
||||
|
||||
def number
|
||||
|
|
|
@ -221,7 +221,7 @@ On line #{name.line}, character #{name.offset}#{" of '#{filename}'" if filename}
|
|||
Implicit strings have been deprecated and will be removed in version 3.0.
|
||||
'#{name.value}' was not quoted. Please add double quotes (e.g. "#{name.value}").
|
||||
END
|
||||
node(Script::String.new(name.value))
|
||||
node(Script::String.new(name.value, :identifier))
|
||||
else
|
||||
args = arglist || []
|
||||
assert_tok(:rparen)
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
require 'sass/script/literal'
|
||||
|
||||
module Sass::Script
|
||||
# A SassScript object representing a string of text.
|
||||
# A SassScript object representing a CSS string *or* a CSS identifier.
|
||||
class String < Literal
|
||||
# The Ruby value of the string.
|
||||
#
|
||||
|
@ -9,8 +9,26 @@ module Sass::Script
|
|||
attr_reader :value
|
||||
alias_method :to_s, :value
|
||||
|
||||
# Whether this is a CSS string or a CSS identifier.
|
||||
# The difference is that strings are written with double-quotes,
|
||||
# while identifiers aren't.
|
||||
#
|
||||
# @return [Symbol] `:string` or `:identifier`
|
||||
attr_reader :type
|
||||
|
||||
# Creates a new string.
|
||||
#
|
||||
# @param value [String] See \{#value}
|
||||
# @param type [Symbol] See \{#type}
|
||||
def initialize(value, type = :identifier)
|
||||
super(value)
|
||||
@type = type
|
||||
end
|
||||
|
||||
# @see Node#to_sass
|
||||
def to_sass
|
||||
return self.value if type == :identifier
|
||||
|
||||
# Replace single backslashes with double. Really.
|
||||
value = self.value.gsub("\\", "\\\\\\\\")
|
||||
return "\"#{value}\"" unless value.include?('"')
|
||||
|
|
Loading…
Reference in a new issue