Sha256: 28bba172098de39421db0fb40a930212ff25bc0a683acc878d6f3010ddc3b902

Contents?: true

Size: 1.02 KB

Versions: 19

Compression:

Stored size: 1.02 KB

Contents

module CSL
  module_function

  def silence_warnings
    original_verbosity, $VERBOSE = $VERBOSE, nil
    yield
  ensure
    $VERBOSE = original_verbosity
  end
end

class Module
  if RUBY_VERSION < '1.9'
    alias const? const_defined?
  else
    def const?(name)
      const_defined?(name, false)
    end
  end
end

class Struct
  alias_method :__class__, :class
end unless Struct.instance_methods.include?(:__class__)

module CSL
  module_function

  if RUBY_VERSION < '1.9'

    XML_ENTITY_SUBSTITUTION = Hash[*%w{
     & &amp; < &lt; > &gt; ' &apos; " &quot;
    }].freeze

    def encode_xml_text(string)
      string.gsub(/[&<>]/) { |match|
        XML_ENTITY_SUBSTITUTION[match]
      }
    end

    def encode_xml_attr(string)
      string.gsub(/[&<>'"]/) { |match|
        XML_ENTITY_SUBSTITUTION[match]
      }.inspect
    end
  else
    def encode_xml_text(string)
      string.encode(string.encoding, :xml => :text)
    end

    def encode_xml_attr(string)
      string.encode(string.encoding, :xml => :attr)
    end
  end
end

Version data entries

19 entries across 19 versions & 1 rubygems

Version Path
csl-2.0.0 lib/csl/compatibility.rb
csl-1.6.0 lib/csl/compatibility.rb
csl-1.5.2 lib/csl/compatibility.rb
csl-1.5.1 lib/csl/compatibility.rb
csl-1.5.0 lib/csl/compatibility.rb
csl-1.4.5 lib/csl/compatibility.rb
csl-1.4.4 lib/csl/compatibility.rb
csl-1.4.3 lib/csl/compatibility.rb
csl-1.4.2 lib/csl/compatibility.rb
csl-1.4.1 lib/csl/compatibility.rb
csl-1.4.0 lib/csl/compatibility.rb
csl-1.3.2 lib/csl/compatibility.rb
csl-1.3.1 lib/csl/compatibility.rb
csl-1.3.0 lib/csl/compatibility.rb
csl-1.2.3 lib/csl/compatibility.rb
csl-1.2.2 lib/csl/compatibility.rb
csl-1.2.1 lib/csl/compatibility.rb
csl-1.2.0 lib/csl/compatibility.rb
csl-1.1.0 lib/csl/compatibility.rb