Class: Sass::Script::String
Overview
A SassScript object representing a CSS string or a CSS identifier.
Instance Attribute Summary
- - (Symbol) type readonly Whether this is a CSS string or a CSS identifier.
- - (String) value readonly The Ruby value of the string.
Instance Method Summary
- - (String) initialize(value, type = :identifier) constructor Creates a new string.
- - plus(other)
- - to_s(opts = {})
- - to_sass(opts = {})
Methods inherited from Literal
#==, #_perform, #assert_int!, #children, #deep_copy, #div, #eq, #inspect, #minus, #neq, #null?, #options, #single_eq, #to_a, #to_bool, #to_i, #unary_div, #unary_minus, #unary_not, #unary_plus
Methods inherited from Node
#_perform, #children, #dasherize, #deep_copy, #opts, #perform
Constructor Details
- (String) initialize(value, type = :identifier)
Creates a new string.
22 23 24 25 |
# File '/var/www/sass-pages/.sass/lib/sass/script/string.rb', line 22
def initialize(value, type = :identifier)
super(value)
@type = type
end
|
Instance Attribute Details
- (Symbol) type (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 '/var/www/sass-pages/.sass/lib/sass/script/string.rb', line 16
def type
@type
end
|
- (String) value (readonly)
The Ruby value of the string.
9 10 11 |
# File '/var/www/sass-pages/.sass/lib/sass/script/string.rb', line 9
def value
@value
end
|
Instance Method Details
- plus(other)
28 29 30 31 |
# File '/var/www/sass-pages/.sass/lib/sass/script/string.rb', line 28
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 = {})
34 35 36 37 38 39 40 41 42 43 44 |
# File '/var/www/sass-pages/.sass/lib/sass/script/string.rb', line 34
def to_s(opts = {})
if @type == :identifier
return @value.gsub(/\n\s*/, " ")
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 = {})
47 48 49 |
# File '/var/www/sass-pages/.sass/lib/sass/script/string.rb', line 47
def to_sass(opts = {})
to_s
end
|