gems.sass-3.2.9.lib.sass.script.string.rb Maven / Gradle / Ivy
Go to download
Sass makes CSS fun again. Sass is an extension of CSS3, adding nested rules, variables, mixins, selector
inheritance, and more. It's translated to well-formatted, standard CSS using the command line tool or a
web-framework plugin.
This is a repackaged GEM in a JAR format of the sass-lang.gem package. The sass-gems package version
follows the sass-lang.gem versions located http://rubyforge.org/frs/?group_id=9702. Simply change
the version of this package to download and repackage the same GEM version.
The newest version!
require 'sass/script/literal'
module Sass::Script
# A SassScript object representing a CSS string *or* a CSS identifier.
class String < Literal
# The Ruby value of the string.
#
# @return [String]
attr_reader :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 Literal#plus
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
# @see Node#to_s
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
# @see Node#to_sass
def to_sass(opts = {})
to_s
end
end
end