diff options
| author | Dan Allen <dan.j.allen@gmail.com> | 2019-01-23 23:39:06 -0700 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2019-01-23 23:39:06 -0700 |
| commit | e6ff47641a0e4bcc5d9e5271eaaf5b6389f5cacc (patch) | |
| tree | 310810dd5458d5ca57b3d53ba87c8b029fa0fa4c | |
| parent | cd7e944abe1a95f03d0181746445409ffa9a4d79 (diff) | |
resolves #2995 use methods on File class instead of IO class (PR #2999)
| -rw-r--r-- | CHANGELOG.adoc | 1 | ||||
| -rw-r--r-- | features/step_definitions.rb | 3 | ||||
| -rw-r--r-- | lib/asciidoctor.rb | 2 | ||||
| -rw-r--r-- | lib/asciidoctor/abstract_node.rb | 10 | ||||
| -rw-r--r-- | lib/asciidoctor/cli/options.rb | 8 | ||||
| -rw-r--r-- | lib/asciidoctor/converter.rb | 2 | ||||
| -rw-r--r-- | lib/asciidoctor/reader.rb | 2 | ||||
| -rw-r--r-- | lib/asciidoctor/stylesheets.rb | 10 | ||||
| -rw-r--r-- | test/api_test.rb | 8 | ||||
| -rw-r--r-- | test/invoker_test.rb | 6 | ||||
| -rw-r--r-- | test/test_helper.rb | 2 |
11 files changed, 24 insertions, 30 deletions
diff --git a/CHANGELOG.adoc b/CHANGELOG.adoc index 189ae91f..e2981c16 100644 --- a/CHANGELOG.adoc +++ b/CHANGELOG.adoc @@ -35,6 +35,7 @@ Improvements:: * define LIB_DIR constant; rename *_PATH constants to *_DIR constants to be consistent with RubyGems terminology (#2764) * only define ROOT_DIR if not already defined (for compatibility with Asciidoctor.js) * move custom docinfo content in footer below built-in docinfo content in footer in HTML converter (#3017) + * read and write files using File methods instead of IO methods (#2995) Bug Fixes:: diff --git a/features/step_definitions.rb b/features/step_definitions.rb index 9c740887..ebaa9bac 100644 --- a/features/step_definitions.rb +++ b/features/step_definitions.rb @@ -16,9 +16,6 @@ end When /it is converted to html/ do @output = Asciidoctor.convert @source - #IO.write '/tmp/test.adoc', @source - #@output = %x{asciidoc -f compat/asciidoc.conf -o - -s /tmp/test.adoc | XMLLINT_INDENT='' xmllint --format - | tail -n +2}.rstrip - ##@output = %x{asciidoc -f compat/asciidoc.conf -o - -s /tmp/test.adoc} end When /it is converted to docbook/ do diff --git a/lib/asciidoctor.rb b/lib/asciidoctor.rb index fcd65b6b..a33827ae 100644 --- a/lib/asciidoctor.rb +++ b/lib/asciidoctor.rb @@ -1509,7 +1509,7 @@ module Asciidoctor # NOTE don't warn if src can't be read and dest already exists (see #2323) if stylesheet_src != stylesheet_dest && (stylesheet_data = doc.read_asset stylesheet_src, warn_on_failure: !(::File.file? stylesheet_dest), label: 'stylesheet') - ::IO.write stylesheet_dest, stylesheet_data + ::File.write stylesheet_dest, stylesheet_data, mode: FILE_WRITE_MODE end end diff --git a/lib/asciidoctor/abstract_node.rb b/lib/asciidoctor/abstract_node.rb index 3c4dd47e..546925f8 100644 --- a/lib/asciidoctor/abstract_node.rb +++ b/lib/asciidoctor/abstract_node.rb @@ -377,7 +377,7 @@ class AbstractNode if ::File.readable? image_path # NOTE base64 is autoloaded by reference to ::Base64 - %(data:#{mimetype};base64,#{::Base64.strict_encode64 ::IO.binread image_path}) + %(data:#{mimetype};base64,#{::Base64.strict_encode64 ::File.binread image_path}) else logger.warn %(image to embed not found or not readable: #{image_path}) %(data:#{mimetype};base64,) @@ -503,12 +503,8 @@ class AbstractNode # remap opts for backwards compatibility opts = { warn_on_failure: (opts != false) } unless ::Hash === opts if ::File.readable? path - if opts[:normalize] - (Helpers.prepare_source_string ::File.open(path, FILE_READ_MODE) {|f| f.read }).join LF - else - # QUESTION should we chomp or rstrip content? - ::IO.read path - end + # QUESTION should we chomp content if normalize is false? + opts[:normalize] ? ((Helpers.prepare_source_string ::File.read path, mode: FILE_READ_MODE).join LF) : (::File.read path, mode: FILE_READ_MODE) elsif opts[:warn_on_failure] logger.warn %(#{(attr 'docfile') || '<stdin>'}: #{opts[:label] || 'file'} does not exist or cannot be read: #{path}) nil diff --git a/lib/asciidoctor/cli/options.rb b/lib/asciidoctor/cli/options.rb index b53a5dbb..c9e49dbd 100644 --- a/lib/asciidoctor/cli/options.rb +++ b/lib/asciidoctor/cli/options.rb @@ -143,14 +143,14 @@ Example: asciidoctor -b html5 source.asciidoc require 'zlib' unless defined? ::Zlib::GzipReader $stdout.puts ::Zlib::GzipReader.open(manpage_path) {|gz| gz.read } else - $stdout.puts ::IO.read manpage_path + $stdout.puts ::File.read manpage_path end else $stderr.puts %(asciidoctor: FAILED: manual page not found: #{manpage_path}) return 1 end elsif ::File.exist?(manpage_path = (::File.join ROOT_DIR, 'man', 'asciidoctor.1')) - $stdout.puts ::IO.read manpage_path + $stdout.puts ::File.read manpage_path else require 'open3' unless defined? ::Open3.popen3 manpage_path = ::Open3.popen3('man -w asciidoctor') {|_, out| out.read }.chop rescue '' @@ -161,7 +161,7 @@ Example: asciidoctor -b html5 source.asciidoc require 'zlib' unless defined? ::Zlib::GzipReader $stdout.puts ::Zlib::GzipReader.open(manpage_path) {|gz| gz.read } else - $stdout.puts ::IO.read manpage_path + $stdout.puts ::File.read manpage_path end end else @@ -287,7 +287,7 @@ Example: asciidoctor -b html5 source.asciidoc def print_version os = $stdout os.puts %(Asciidoctor #{::Asciidoctor::VERSION} [https://asciidoctor.org]) encoding_info = { 'lc' => 'locale', 'fs' => 'filesystem', 'in' => 'internal', 'ex' => 'external' }.map do |k, v| - %(#{k}:#{v == 'internal' ? (::File.open(__FILE__) {|f| f.getc }).encoding : (::Encoding.find v)}) + %(#{k}:#{v == 'internal' ? (::File.open(__FILE__) {|f| f.getc.encoding }) : (::Encoding.find v)}) end os.puts %(Runtime Environment (#{::RUBY_DESCRIPTION}) (#{encoding_info.join ' '})) 0 diff --git a/lib/asciidoctor/converter.rb b/lib/asciidoctor/converter.rb index b1283bf3..8f696c00 100644 --- a/lib/asciidoctor/converter.rb +++ b/lib/asciidoctor/converter.rb @@ -213,7 +213,7 @@ module Asciidoctor # ensure there's a trailing endline to be nice to terminals target.write LF else - ::IO.write target, output + ::File.write target, output, mode: FILE_WRITE_MODE end nil end diff --git a/lib/asciidoctor/reader.rb b/lib/asciidoctor/reader.rb index d8328435..d6786f79 100644 --- a/lib/asciidoctor/reader.rb +++ b/lib/asciidoctor/reader.rb @@ -658,7 +658,7 @@ class PreprocessorReader < Reader # # path = 'partial.adoc' # file = File.expand_path path - # data = IO.read file + # data = File.read file # reader.push_include data, file, path # # Returns this Reader object. diff --git a/lib/asciidoctor/stylesheets.rb b/lib/asciidoctor/stylesheets.rb index 110afd04..07a6b1e3 100644 --- a/lib/asciidoctor/stylesheets.rb +++ b/lib/asciidoctor/stylesheets.rb @@ -23,7 +23,7 @@ class Stylesheets # # returns the [String] Asciidoctor stylesheet data def primary_stylesheet_data - @primary_stylesheet_data ||= ::IO.read(::File.join(STYLESHEETS_DIR, 'asciidoctor-default.css')).rstrip + @primary_stylesheet_data ||= ::File.read(::File.join(STYLESHEETS_DIR, 'asciidoctor-default.css'), mode: FILE_READ_MODE).rstrip end def embed_primary_stylesheet @@ -33,7 +33,7 @@ class Stylesheets end def write_primary_stylesheet target_dir = '.' - ::IO.write(::File.join(target_dir, primary_stylesheet_name), primary_stylesheet_data) + ::File.write (::File.join target_dir, primary_stylesheet_name), primary_stylesheet_data, mode: FILE_WRITE_MODE end def coderay_stylesheet_name @@ -48,7 +48,7 @@ class Stylesheets # unless load_coderay.nil? # ::CodeRay::Encoders[:html]::CSS.new(:default).stylesheet # end - @coderay_stylesheet_data ||= ::IO.read(::File.join(STYLESHEETS_DIR, coderay_stylesheet_name)).rstrip + @coderay_stylesheet_data ||= ::File.read(::File.join(STYLESHEETS_DIR, coderay_stylesheet_name), mode: FILE_READ_MODE).rstrip end def embed_coderay_stylesheet @@ -58,7 +58,7 @@ class Stylesheets end def write_coderay_stylesheet target_dir = '.' - ::IO.write(::File.join(target_dir, coderay_stylesheet_name), coderay_stylesheet_data) + ::File.write (::File.join target_dir, coderay_stylesheet_name), coderay_stylesheet_data, mode: FILE_WRITE_MODE end def pygments_stylesheet_name style = nil @@ -90,7 +90,7 @@ class Stylesheets end def write_pygments_stylesheet target_dir = '.', style = nil - ::IO.write(::File.join(target_dir, pygments_stylesheet_name(style)), pygments_stylesheet_data(style)) + ::File.write (::File.join target_dir, (pygments_stylesheet_name style)), (pygments_stylesheet_data style), mode: FILE_WRITE_MODE end #def load_coderay diff --git a/test/api_test.rb b/test/api_test.rb index c597b5fb..b8f4862a 100644 --- a/test/api_test.rb +++ b/test/api_test.rb @@ -972,7 +972,7 @@ text begin Asciidoctor.convert_file sample_input_path assert File.exist?(sample_output_path) - output = IO.read(sample_output_path) + output = File.read(sample_output_path) refute_empty output assert_xpath '/html', output, 1 assert_xpath '/html/head', output, 1 @@ -990,7 +990,7 @@ text begin Asciidoctor.convert_file sample_input_path, to_file: sample_output_path assert File.exist?(sample_output_path) - output = IO.read(sample_output_path) + output = File.read(sample_output_path) refute_empty output assert_xpath '/html', output, 1 assert_xpath '/html/head', output, 1 @@ -1009,7 +1009,7 @@ text begin Asciidoctor.convert_file sample_input_path, to_file: 'result.html', base_dir: fixture_dir assert File.exist?(sample_output_path) - output = IO.read(sample_output_path) + output = File.read(sample_output_path) refute_empty output assert_xpath '/html', output, 1 assert_xpath '/html/head', output, 1 @@ -1051,7 +1051,7 @@ text begin Asciidoctor.convert sample_input, to_file: sample_output_path, header_footer: false assert File.exist?(sample_output_path) - output = IO.read(sample_output_path) + output = File.read(sample_output_path) refute_empty output assert_includes output, '<p>.htm</p>' ensure diff --git a/test/invoker_test.rb b/test/invoker_test.rb index 6b06aba0..e846e0d9 100644 --- a/test/invoker_test.rb +++ b/test/invoker_test.rb @@ -116,7 +116,7 @@ context 'Invoker' do begin %x(mkfifo #{sample_inpath}) write_thread = Thread.new do - IO.write sample_inpath, 'pipe content' + File.write sample_inpath, 'pipe content' end invoker = invoke_cli_to_buffer %w(-a stylesheet!), sample_inpath result = invoker.read_output @@ -216,7 +216,7 @@ context 'Invoker' do doc = invoker.document assert_equal sample_outpath, doc.attr('outfile') assert File.exist?(sample_outpath) - output = IO.read(sample_outpath) + output = File.read(sample_outpath) refute_empty output assert_xpath '/html', output, 1 assert_xpath '/html/head', output, 1 @@ -443,7 +443,7 @@ eve, islifeform - analyzes an image to determine if it's a picture of a life for invoke_cli(%W(-b manpage -o #{outfile_1}), '-') { input } assert File.exist?(outfile_1) assert File.exist?(outfile_2) - assert_equal '.so eve.1', (IO.read outfile_2).chomp + assert_equal '.so eve.1', (File.read outfile_2).chomp ensure FileUtils.rm_f outfile_1 FileUtils.rm_f outfile_2 diff --git a/test/test_helper.rb b/test/test_helper.rb index 76612c1c..59fc0d94 100644 --- a/test/test_helper.rb +++ b/test/test_helper.rb @@ -75,7 +75,7 @@ class Minitest::Test end def example_document(name, opts = {}) - document_from_string IO.read(sample_doc_path(name)), opts + document_from_string File.read(sample_doc_path(name)), opts end def xmlnodes_at_css(css, content, count = nil) |
