Sha256: 88cb850ea812410713f251715e8420a6fd0a462d2e7e4228700d98e90853322d

Contents?: true

Size: 1.35 KB

Versions: 35

Compression:

Stored size: 1.35 KB

Contents

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

Version data entries

35 entries across 34 versions & 9 rubygems

Version Path
ish_lib_manager-0.0.1 test/dummy/vendor/bundle/ruby/2.3.0/gems/sass-3.2.19/lib/sass/script/string.rb
solidus_backend-1.0.0.pre vendor/bundle/gems/sass-3.2.19/lib/sass/script/string.rb
xass-0.1.0 lib/sass/script/string.rb
oreorenasass-3.4.14 lib/sass/script/string.rb
oreorenasass-3.4.13 lib/sass/script/string.rb
oreorenasass-3.4.12 lib/sass/script/string.rb
oreorenasass-3.4.11 lib/sass/script/string.rb
oreorenasass-3.4.9 lib/sass/script/string.rb
oreorenasass-3.4.7 lib/sass/script/string.rb
oreorenasass-3.4.5 lib/sass/script/string.rb
sadui-0.0.4 vendor/bundle/ruby/2.1.0/gems/sass-3.2.14/lib/sass/script/string.rb
sadui-0.0.4 vendor/bundle/ruby/2.0.0/gems/sass-3.2.14/lib/sass/script/string.rb
sass-3.2.19 lib/sass/script/string.rb
sass-3.2.18 lib/sass/script/string.rb
sass-3.2.17 lib/sass/script/string.rb
sass-3.2.16 lib/sass/script/string.rb
sass-3.2.15 lib/sass/script/string.rb
sass-3.2.14 lib/sass/script/string.rb
mango-0.8.0 vendor/bundler/ruby/2.1.0/gems/sass-3.2.13/lib/sass/script/string.rb
mango-0.7.1 vendor/bundler/ruby/2.0.0/gems/sass-3.2.12/lib/sass/script/string.rb