Sha256: 3c11cf1fb150c24fb6ec02b65ee81bc7bfed8019489a6a84c59de0627d82fd1a

Contents?: true

Size: 888 Bytes

Versions: 27

Compression:

Stored size: 888 Bytes

Contents

module JsDuck
  module Util

    # A helper to use instead the builtin IO class to read files in
    # correct encoding.
    #
    # By default in Ruby 1.9 the encoding is auto-detected, which can
    # have surprising results.  So in here we read in all files in UTF-8
    # (the default) or in some other encoding specified through --encoding
    # option and convert it to UTF-8 internally.
    class IO
      @@encoding = "UTF-8"

      # Sets the external encoding to be used for reading files.
      # When it's different from UTF-8, the input will be converted to UTF-8.
      def self.encoding=(e)
        if e =~ /^UTF-8$/i
          @@encoding = e
        else
          @@encoding = e+":UTF-8"
        end
      end

      # Reads given filename into string
      def self.read(filename)
        File.open(filename, "r:"+@@encoding) {|f| f.read }
      end

    end

  end
end

Version data entries

27 entries across 27 versions & 1 rubygems

Version Path
jsduck-5.0.0.beta5 lib/jsduck/util/io.rb
jsduck-5.0.0.beta4 lib/jsduck/util/io.rb
jsduck-4.10.4 lib/jsduck/util/io.rb
jsduck-5.0.0.beta3 lib/jsduck/util/io.rb
jsduck-4.10.3 lib/jsduck/util/io.rb
jsduck-4.10.2 lib/jsduck/util/io.rb
jsduck-4.10.1 lib/jsduck/util/io.rb
jsduck-4.10.0 lib/jsduck/util/io.rb
jsduck-4.9.0 lib/jsduck/util/io.rb
jsduck-4.8.0 lib/jsduck/util/io.rb
jsduck-5.0.0.beta2 lib/jsduck/util/io.rb
jsduck-4.7.1 lib/jsduck/util/io.rb
jsduck-4.7.0 lib/jsduck/util/io.rb
jsduck-5.0.0.beta01 lib/jsduck/util/io.rb
jsduck-4.6.2 lib/jsduck/util/io.rb
jsduck-4.6.1 lib/jsduck/util/io.rb
jsduck-4.6.0 lib/jsduck/util/io.rb
jsduck-4.5.1 lib/jsduck/util/io.rb
jsduck-4.5.0 lib/jsduck/util/io.rb
jsduck-4.4.1 lib/jsduck/util/io.rb