Class: Sass::Script::String
- Defined in:
- lib/sass/script/string.rb
Overview
A SassScript object representing a CSS string or a CSS identifier.
Instance Attribute Summary collapse
-
#type ⇒ Symbol
readonly
Whether this is a CSS string or a CSS identifier.
-
#value ⇒ String
readonly
The Ruby value of the string.
Attributes inherited from Node
Instance Method Summary collapse
-
#context=(context)
In addition to setting the Node#context of the string, this sets the string to be an identifier if the context is
:equals
. -
#initialize(value, type = :identifier) ⇒ String
constructor
Creates a new string.
- #plus(other)
- #to_s(opts = {})
- #to_sass(opts = {})
Methods inherited from Literal
#==, #_perform, #and, #assert_int!, #children, #comma, #concat, #div, #eq, #inspect, #minus, #neq, #options, #or, #single_eq, #to_bool, #to_i, #unary_div, #unary_minus, #unary_not, #unary_plus
Methods inherited from Node
#_perform, #children, #dasherize, #perform
Constructor Details
#initialize(value, type = :identifier) ⇒ String
Creates a new string.
31 32 33 34 |
# File 'lib/sass/script/string.rb', line 31
def initialize(value, type = :identifier)
super(value)
@type = type
end
|
Instance Attribute Details
#type ⇒ Symbol (readonly)
Whether this is a CSS string or a CSS identifier. The difference is that strings are written with double-quotes, while identifiers aren't.
16 17 18 |
# File 'lib/sass/script/string.rb', line 16
def type
@type
end
|
#value ⇒ String (readonly)
The Ruby value of the string.
9 10 11 |
# File 'lib/sass/script/string.rb', line 9
def value
@value
end
|
Instance Method Details
#context=(context)
In addition to setting the Node#context of the string,
this sets the string to be an identifier if the context is :equals
.
22 23 24 25 |
# File 'lib/sass/script/string.rb', line 22
def context=(context)
super
@type = :identifier if context == :equals
end
|
#plus(other)
37 38 39 40 |
# File 'lib/sass/script/string.rb', line 37
def plus(other)
other_str = other.is_a?(Sass::Script::String) ? other.value : other.to_s
Sass::Script::String.new(self.value + other_str, self.type)
end
|
#to_s(opts = {})
43 44 45 46 47 48 49 50 51 52 53 54 |
# File 'lib/sass/script/string.rb', line 43
def to_s(opts = {})
if self.type == :identifier
return %q{""} if context == :equals && self.value.size == 0
return self.value.gsub("\n", " ")
end
return "\"#{value.gsub('"', "\\\"")}\"" if opts[:quote] == %q{"}
return "'#{value.gsub("'", "\\'")}'" if opts[:quote] == %q{'}
return "\"#{value}\"" unless value.include?('"')
return "'#{value}'" unless value.include?("'")
"\"#{value.gsub('"', "\\\"")}\"" #'
end
|
#to_sass(opts = {})
57 58 59 60 61 62 63 64 65 |
# File 'lib/sass/script/string.rb', line 57
def to_sass(opts = {})
if self.type == :identifier && context == :equals &&
self.value !~ Sass::SCSS::RX::URI &&
Sass::SCSS::RX.escape_ident(self.value).include?(?\\)
return "unquote(#{Sass::Script::String.new(self.value, :string).to_sass})"
else
return to_s
end
end
|