Sha256: cb3927ab260c445ee7a9b8aba9aab4168bf9481d82996d73f9ee8386717a9988

Contents?: true

Size: 822 Bytes

Versions: 21

Compression:

Stored size: 822 Bytes

Contents

module JsDuck

  # 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

Version data entries

21 entries across 21 versions & 1 rubygems

Version Path
jsduck-4.0.1 lib/jsduck/io.rb
jsduck-4.0.0 lib/jsduck/io.rb
jsduck-3.11.2 lib/jsduck/io.rb
jsduck-4.0.beta2 lib/jsduck/io.rb
jsduck-3.11.1 lib/jsduck/io.rb
jsduck-4.0.beta lib/jsduck/io.rb
jsduck-3.11.0 lib/jsduck/io.rb
jsduck-3.10.5 lib/jsduck/io.rb
jsduck-3.10.4 lib/jsduck/io.rb
jsduck-3.10.3 lib/jsduck/io.rb
jsduck-3.10.2 lib/jsduck/io.rb
jsduck-3.10.1 lib/jsduck/io.rb
jsduck-3.10.0 lib/jsduck/io.rb
jsduck-3.9.1 lib/jsduck/io.rb
jsduck-3.9.0 lib/jsduck/io.rb
jsduck-3.9.0.pre lib/jsduck/io.rb
jsduck-3.8.4 lib/jsduck/io.rb
jsduck-3.8.3 lib/jsduck/io.rb
jsduck-3.8.2 lib/jsduck/io.rb
jsduck-3.8.1 lib/jsduck/io.rb