summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDan Allen <dan.j.allen@gmail.com>2014-03-01 02:04:45 -0700
committerDan Allen <dan.j.allen@gmail.com>2014-03-01 02:04:45 -0700
commit1329875559cf22c4c6ed758fe1b155cadf91bae9 (patch)
treedf3209a1d18c12600e9654316bd2dda1f42204f2
parentcedc33627bf702abd1dd4a3eefaf7ed83eba0840 (diff)
parent882e132123471a04bd99cb3ed66ef90767afe41d (diff)
Merge pull request #910 from mojavelinux/issue-907
resolves #907 write to file by default if input is file
-rw-r--r--lib/asciidoctor.rb82
-rw-r--r--lib/asciidoctor/cli/invoker.rb5
-rw-r--r--lib/asciidoctor/cli/options.rb6
-rw-r--r--lib/asciidoctor/document.rb1
-rw-r--r--test/document_test.rb156
5 files changed, 134 insertions, 116 deletions
diff --git a/lib/asciidoctor.rb b/lib/asciidoctor.rb
index 2755cfb7..c0a375c7 100644
--- a/lib/asciidoctor.rb
+++ b/lib/asciidoctor.rb
@@ -1214,7 +1214,8 @@ module Asciidoctor
if input.is_a? ::File
lines = input.readlines
input_mtime = input.mtime
- input_path = ::File.expand_path input.path
+ input = ::File.new ::File.expand_path input.path
+ input_path = input.path
# hold off on setting infile and indir until we get a better sense of their purpose
attributes['docfile'] = input_path
attributes['docdir'] = ::File.dirname input_path
@@ -1293,21 +1294,29 @@ module Asciidoctor
# file, otherwise the converted String
def convert input, options = {}
options = options.dup
- in_place = options.delete(:in_place) || false
to_file = options.delete(:to_file)
to_dir = options.delete(:to_dir)
mkdirs = options.delete(:mkdirs) || false
timings = options[:timings]
- write_in_place = in_place && input.is_a?(::File)
- write_to_target = to_file || to_dir
- stream_output = to_file && to_file.respond_to?(:write)
-
- if write_in_place && write_to_target
- raise ::ArgumentError, 'the option :in_place cannot be used with either the :to_dir or :to_file option'
+ case to_file
+ when true, nil
+ write_to_same_dir = !to_dir && (input.is_a? ::File)
+ stream_output = false
+ write_to_target = to_dir
+ to_file = nil
+ when false
+ write_to_same_dir = false
+ stream_output = false
+ write_to_target = false
+ to_file = nil
+ else
+ write_to_same_dir = false
+ stream_output = to_file.respond_to? :write
+ write_to_target = stream_output ? false : to_file
end
- if !options.has_key?(:header_footer) && (write_in_place || write_to_target)
+ if !options.key?(:header_footer) && (write_to_same_dir || write_to_target)
options[:header_footer] = true
end
@@ -1315,57 +1324,56 @@ module Asciidoctor
if to_file == '/dev/null'
return doc
- elsif write_in_place
- to_file = ::File.join(::File.dirname(input.path), "#{doc.attributes['docname']}#{doc.attributes['outfilesuffix']}")
- elsif !stream_output && write_to_target
+ elsif write_to_same_dir
+ infile = ::File.expand_path input.path
+ outfile = ::File.join ::File.dirname(infile), %(#{doc.attributes['docname']}#{doc.attributes['outfilesuffix']})
+ if outfile == infile
+ raise ::IOError, 'Input file and output file are the same!'
+ end
+ outdir = ::File.dirname outfile
+ elsif write_to_target
working_dir = options.has_key?(:base_dir) ? ::File.expand_path(options[:base_dir]) : ::File.expand_path(::Dir.pwd)
# QUESTION should the jail be the working_dir or doc.base_dir???
jail = doc.safe >= SafeMode::SAFE ? working_dir : nil
if to_dir
- to_dir = doc.normalize_system_path(to_dir, working_dir, jail, :target_name => 'to_dir', :recover => false)
+ outdir = doc.normalize_system_path(to_dir, working_dir, jail, :target_name => 'to_dir', :recover => false)
if to_file
- to_file = doc.normalize_system_path(to_file, to_dir, nil, :target_name => 'to_dir', :recover => false)
- # reestablish to_dir as the final target directory (in the case to_file had directory segments)
- to_dir = ::File.dirname(to_file)
+ outfile = doc.normalize_system_path(to_file, outdir, nil, :target_name => 'to_dir', :recover => false)
+ # reestablish outdir as the final target directory (in the case to_file had directory segments)
+ outdir = ::File.dirname outfile
else
- to_file = ::File.join(to_dir, "#{doc.attributes['docname']}#{doc.attributes['outfilesuffix']}")
+ outfile = ::File.join outdir, %(#{doc.attributes['docname']}#{doc.attributes['outfilesuffix']})
end
elsif to_file
- to_file = doc.normalize_system_path(to_file, working_dir, jail, :target_name => 'to_dir', :recover => false)
- # establish to_dir as the final target directory (in the case to_file had directory segments)
- to_dir = ::File.dirname(to_file)
+ outfile = doc.normalize_system_path(to_file, working_dir, jail, :target_name => 'to_dir', :recover => false)
+ # establish outdir as the final target directory (in the case to_file had directory segments)
+ outdir = ::File.dirname outfile
end
- if !::File.directory? to_dir
+ unless ::File.directory? outdir
if mkdirs
- ::FileUtils.mkdir_p to_dir
+ ::FileUtils.mkdir_p outdir
else
- raise ::IOError, "target directory does not exist: #{to_dir}"
+ # NOTE we intentionally refer to the directory as it was passed to the API
+ raise ::IOError, %(target directory does not exist: #{to_dir})
end
end
+ else
+ outfile = to_file
+ outdir = nil
end
- # concept::
- #if to_file
- # doc.convert_to to_file, :timings => timings
- # # write stylesheets
- # doc
- #else
- # doc.convert, :timings => timings
- #end
-
timings.start :convert if timings
output = doc.convert
timings.record :convert if timings
- if to_file
+ if outfile
timings.start :write if timings
unless stream_output
- to_file = ::File.expand_path to_file
- doc.attributes['outfile'] = ::File.expand_path to_file
- doc.attributes['outdir'] = ::File.dirname to_file
+ doc.attributes['outfile'] = outfile
+ doc.attributes['outdir'] = outdir
end
- doc.write output, to_file
+ doc.write output, outfile
timings.record :write if timings
# NOTE document cannot control this behavior if safe >= SafeMode::SERVER
diff --git a/lib/asciidoctor/cli/invoker.rb b/lib/asciidoctor/cli/invoker.rb
index 924ce661..1cb02606 100644
--- a/lib/asciidoctor/cli/invoker.rb
+++ b/lib/asciidoctor/cli/invoker.rb
@@ -79,15 +79,14 @@ module Asciidoctor
tofile = outfile
opts[:mkdirs] = true
else
+ # automatically calculate outfile based on infile unless to_dir is set
tofile = nil
- # automatically calculate outfile based on infile
- opts[:in_place] = true unless opts.has_key? :to_dir
opts[:mkdirs] = true
end
inputs.each do |input|
# NOTE processor will dup options and attributes internally
- input_opts = tofile ? opts.merge(:to_file => tofile) : opts
+ input_opts = tofile.nil? ? opts : opts.merge(:to_file => tofile)
if show_timings
timings = Timings.new
@documents << ::Asciidoctor.convert(input, input_opts.merge(:timings => timings))
diff --git a/lib/asciidoctor/cli/options.rb b/lib/asciidoctor/cli/options.rb
index 31d4cb18..542587b3 100644
--- a/lib/asciidoctor/cli/options.rb
+++ b/lib/asciidoctor/cli/options.rb
@@ -162,7 +162,7 @@ Example: asciidoctor -b html5 source.asciidoc
file = file.tr '\\', '/'
end
if (matches = ::Dir.glob file).empty?
- $stderr.puts "asciidoctor: FAILED: input file #{file} missing or cannot be read"
+ $stderr.puts %(asciidoctor: FAILED: input file #{file} missing or cannot be read)
return 1
end
end
@@ -174,13 +174,15 @@ Example: asciidoctor -b html5 source.asciidoc
infiles.each do |file|
unless file == '-' || (::File.readable? file)
- $stderr.puts "asciidoctor: FAILED: input file #{file} missing or cannot be read"
+ $stderr.puts %(asciidoctor: FAILED: input file #{file} missing or cannot be read)
return 1
end
end
self[:input_files] = infiles
+ self.delete(:attributes) if self[:attributes].empty?
+
if self[:template_dirs]
begin
require 'tilt' unless defined? ::Tilt
diff --git a/lib/asciidoctor/document.rb b/lib/asciidoctor/document.rb
index 85fdb7cb..a902d28c 100644
--- a/lib/asciidoctor/document.rb
+++ b/lib/asciidoctor/document.rb
@@ -845,6 +845,7 @@ class Document < AbstractBlock
end
end
+ # TODO document me
def create_converter
converter_opts = {}
converter_opts[:htmlsyntax] = @attributes['htmlsyntax']
diff --git a/test/document_test.rb b/test/document_test.rb
index 0e41e7f2..cf887f0b 100644
--- a/test/document_test.rb
+++ b/test/document_test.rb
@@ -255,11 +255,11 @@ preamble
end
end
- context 'Render APIs' do
- test 'should render document to string' do
+ context 'Convert APIs' do
+ test 'should convert source document to string when to_file is false' do
sample_input_path = fixture_path('sample.asciidoc')
- output = Asciidoctor.render_file(sample_input_path, :header_footer => true)
+ output = Asciidoctor.convert_file sample_input_path, :header_footer => true, :to_file => false
assert !output.empty?
assert_xpath '/html', output, 1
assert_xpath '/html/head', output, 1
@@ -270,19 +270,19 @@ preamble
test 'should accept attributes as array' do
sample_input_path = fixture_path('sample.asciidoc')
- output = Asciidoctor.render_file(sample_input_path, :attributes => %w(numbered idprefix idseparator=-))
+ output = Asciidoctor.convert_file sample_input_path, :attributes => %w(numbered idprefix idseparator=-), :to_file => false
assert_css '#section-a', output, 1
end
test 'should accept attributes as string' do
sample_input_path = fixture_path('sample.asciidoc')
- output = Asciidoctor.render_file(sample_input_path, :attributes => 'numbered idprefix idseparator=-')
+ output = Asciidoctor.convert_file sample_input_path, :attributes => 'numbered idprefix idseparator=-', :to_file => false
assert_css '#section-a', output, 1
end
test 'should link to default stylesheet by default when safe mode is SECURE or greater' do
sample_input_path = fixture_path('basic.asciidoc')
- output = Asciidoctor.render_file(sample_input_path, :header_footer => true)
+ output = Asciidoctor.convert_file sample_input_path, :header_footer => true, :to_file => false
assert_css 'html:root > head > link[rel="stylesheet"][href="./asciidoctor.css"]', output, 1
end
@@ -326,8 +326,8 @@ text
test 'should embed default stylesheet if safe mode is less than secure and linkcss is unset' do
sample_input_path = fixture_path('basic.asciidoc')
- output = Asciidoctor.render_file(sample_input_path, :header_footer => true,
- :safe => Asciidoctor::SafeMode::SAFE, :attributes => {'linkcss!' => ''})
+ output = Asciidoctor.convert_file sample_input_path, :header_footer => true, :to_file => false,
+ :safe => Asciidoctor::SafeMode::SAFE, :attributes => {'linkcss!' => ''}
assert_css 'html:root > head > style', output, 1
stylenode = xmlnodes_at_css 'html:root > head > style', output, 1
styles = stylenode.first.content
@@ -370,19 +370,19 @@ text
test 'should resolve custom stylesheet to embed relative to stylesdir' do
sample_input_path = fixture_path('basic.asciidoc')
- output = Asciidoctor.render_file(sample_input_path, :header_footer => true, :safe => Asciidoctor::SafeMode::SAFE,
- :attributes => {'stylesheet' => 'custom.css', 'stylesdir' => './stylesheets', 'linkcss!' => ''})
+ output = Asciidoctor.convert_file sample_input_path, :header_footer => true, :safe => Asciidoctor::SafeMode::SAFE, :to_file => false,
+ :attributes => {'stylesheet' => 'custom.css', 'stylesdir' => './stylesheets', 'linkcss!' => ''}
stylenode = xmlnodes_at_css 'html:root > head > style', output, 1
styles = stylenode.first.content
assert !styles.nil?
assert !styles.strip.empty?
end
- test 'should render document in place' do
+ test 'should convert source file and write result to adjacent file by default' do
sample_input_path = fixture_path('sample.asciidoc')
sample_output_path = fixture_path('sample.html')
begin
- Asciidoctor.render_file(sample_input_path, :in_place => true)
+ Asciidoctor.convert_file sample_input_path
assert File.exist?(sample_output_path)
output = File.read(sample_output_path)
assert !output.empty?
@@ -396,11 +396,11 @@ text
end
end
- test 'should render document to file' do
+ test 'should convert source file and write to specified file' do
sample_input_path = fixture_path('sample.asciidoc')
sample_output_path = fixture_path('result.html')
begin
- Asciidoctor.render_file(sample_input_path, :to_file => sample_output_path)
+ Asciidoctor.convert_file sample_input_path, :to_file => sample_output_path
assert File.exist?(sample_output_path)
output = File.read(sample_output_path)
assert !output.empty?
@@ -414,12 +414,12 @@ text
end
end
- test 'should render document to file when base dir is set' do
+ test 'should convert source file and write to specified file in base_dir' do
sample_input_path = fixture_path('sample.asciidoc')
sample_output_path = fixture_path('result.html')
fixture_dir = fixture_path('')
begin
- Asciidoctor.render_file(sample_input_path, :to_file => 'result.html', :base_dir => fixture_dir)
+ Asciidoctor.convert_file sample_input_path, :to_file => 'result.html', :base_dir => fixture_dir
assert File.exist?(sample_output_path)
output = File.read(sample_output_path)
assert !output.empty?
@@ -435,27 +435,25 @@ text
end
end
- test 'in_place option must not be used with to_file option' do
+ test 'in_place option is ignored when to_file is specified' do
sample_input_path = fixture_path('sample.asciidoc')
sample_output_path = fixture_path('result.html')
- assert_raise ArgumentError do
- begin
- Asciidoctor.render_file(sample_input_path, :to_file => sample_output_path, :in_place => true)
- ensure
- FileUtils.rm(sample_output_path) if File.exist? sample_output_path
- end
+ begin
+ Asciidoctor.convert_file sample_input_path, :to_file => sample_output_path, :in_place => true
+ assert File.exist?(sample_output_path)
+ ensure
+ FileUtils.rm(sample_output_path) if File.exist? sample_output_path
end
end
- test 'in_place option must not be used with to_dir option' do
+ test 'in_place option is ignored when to_dir is specified' do
sample_input_path = fixture_path('sample.asciidoc')
- sample_output_path = fixture_path('result.html')
- assert_raise ArgumentError do
- begin
- Asciidoctor.render_file(sample_input_path, :to_dir => '', :in_place => true)
- ensure
- FileUtils.rm(sample_output_path) if File.exist? sample_output_path
- end
+ sample_output_path = fixture_path('sample.html')
+ begin
+ Asciidoctor.convert_file sample_input_path, :to_dir => File.dirname(sample_output_path), :in_place => true
+ assert File.exist?(sample_output_path)
+ ensure
+ FileUtils.rm(sample_output_path) if File.exist? sample_output_path
end
end
@@ -465,7 +463,7 @@ text
Dir.mkdir output_dir if !File.exist? output_dir
sample_output_path = File.join(output_dir, 'sample.html')
begin
- Asciidoctor.render_file(sample_input_path, :to_dir => output_dir)
+ Asciidoctor.convert_file sample_input_path, :to_dir => output_dir
assert File.exist? sample_output_path
ensure
FileUtils.rm(sample_output_path) if File.exist? sample_output_path
@@ -478,7 +476,7 @@ text
output_dir = File.join(File.join(File.dirname(sample_input_path), 'test_output'), 'subdir')
sample_output_path = File.join(output_dir, 'sample.html')
begin
- Asciidoctor.render_file(sample_input_path, :to_dir => output_dir, :mkdirs => true)
+ Asciidoctor.convert_file sample_input_path, :to_dir => output_dir, :mkdirs => true
assert File.exist? sample_output_path
ensure
FileUtils.rm(sample_output_path) if File.exist? sample_output_path
@@ -487,6 +485,15 @@ text
end
end
+ # TODO need similar test for when to_dir is specified
+ test 'should raise exception if an attempt is made to overwrite input file' do
+ sample_input_path = fixture_path('sample.asciidoc')
+
+ assert_raise IOError do
+ Asciidoctor.convert_file sample_input_path, :attributes => { 'outfilesuffix' => '.asciidoc' }
+ end
+ end
+
test 'to_file should be relative to to_dir when both given' do
sample_input_path = fixture_path('sample.asciidoc')
base_dir = File.dirname(sample_input_path)
@@ -495,7 +502,7 @@ text
Dir.mkdir output_dir if !File.exist? output_dir
sample_output_path = File.join(base_dir, sample_rel_output_path)
begin
- Asciidoctor.render_file(sample_input_path, :to_dir => base_dir, :to_file => sample_rel_output_path)
+ Asciidoctor.convert_file sample_input_path, :to_dir => base_dir, :to_file => sample_rel_output_path
assert File.exist? sample_output_path
ensure
FileUtils.rm(sample_output_path) if File.exist? sample_output_path
@@ -505,12 +512,13 @@ text
test 'should not modify options argument' do
options = {
- :safe => Asciidoctor::SafeMode::SAFE
+ :safe => Asciidoctor::SafeMode::SAFE,
+ :to_file => false
}
options.freeze
sample_input_path = fixture_path('sample.asciidoc')
begin
- Asciidoctor.render_file sample_input_path, options
+ Asciidoctor.convert_file sample_input_path, options
rescue
flunk %(options argument should not be modified)
end
@@ -521,20 +529,20 @@ text
test 'should include docinfo files for html backend' do
sample_input_path = fixture_path('basic.asciidoc')
- output = Asciidoctor.render_file(sample_input_path,
- :header_footer => true, :safe => Asciidoctor::SafeMode::SERVER, :attributes => {'docinfo' => ''})
+ output = Asciidoctor.convert_file sample_input_path, :to_file => false,
+ :header_footer => true, :safe => Asciidoctor::SafeMode::SERVER, :attributes => {'docinfo' => ''}
assert !output.empty?
assert_css 'script[src="modernizr.js"]', output, 1
assert_css 'meta[http-equiv="imagetoolbar"]', output, 0
- output = Asciidoctor.render_file(sample_input_path,
- :header_footer => true, :safe => Asciidoctor::SafeMode::SERVER, :attributes => {'docinfo1' => ''})
+ output = Asciidoctor.convert_file sample_input_path, :to_file => false,
+ :header_footer => true, :safe => Asciidoctor::SafeMode::SERVER, :attributes => {'docinfo1' => ''}
assert !output.empty?
assert_css 'script[src="modernizr.js"]', output, 0
assert_css 'meta[http-equiv="imagetoolbar"]', output, 1
- output = Asciidoctor.render_file(sample_input_path,
- :header_footer => true, :safe => Asciidoctor::SafeMode::SERVER, :attributes => {'docinfo2' => ''})
+ output = Asciidoctor.convert_file sample_input_path, :to_file => false,
+ :header_footer => true, :safe => Asciidoctor::SafeMode::SERVER, :attributes => {'docinfo2' => ''}
assert !output.empty?
assert_css 'script[src="modernizr.js"]', output, 1
assert_css 'meta[http-equiv="imagetoolbar"]', output, 1
@@ -543,14 +551,14 @@ text
test 'should include docinfo files for docbook backend' do
sample_input_path = fixture_path('basic.asciidoc')
- output = Asciidoctor.render_file(sample_input_path,
- :header_footer => true, :backend => 'docbook', :safe => Asciidoctor::SafeMode::SERVER, :attributes => {'docinfo' => ''})
+ output = Asciidoctor.convert_file sample_input_path, :to_file => false,
+ :header_footer => true, :backend => 'docbook', :safe => Asciidoctor::SafeMode::SERVER, :attributes => {'docinfo' => ''}
assert !output.empty?
assert_css 'productname', output, 0
assert_css 'copyright', output, 1
- output = Asciidoctor.render_file(sample_input_path,
- :header_footer => true, :backend => 'docbook', :safe => Asciidoctor::SafeMode::SERVER, :attributes => {'docinfo1' => ''})
+ output = Asciidoctor.convert_file sample_input_path, :to_file => false,
+ :header_footer => true, :backend => 'docbook', :safe => Asciidoctor::SafeMode::SERVER, :attributes => {'docinfo1' => ''}
assert !output.empty?
assert_css 'productname', output, 1
assert_xpath '//xmlns:productname[text()="Asciidoctorâ„¢"]', output, 1
@@ -558,8 +566,8 @@ text
assert_xpath '//xmlns:edition[text()="1.0"]', output, 1 # verifies substitutions are performed
assert_css 'copyright', output, 0
- output = Asciidoctor.render_file(sample_input_path,
- :header_footer => true, :backend => 'docbook', :safe => Asciidoctor::SafeMode::SERVER, :attributes => {'docinfo2' => ''})
+ output = Asciidoctor.convert_file sample_input_path, :to_file => false,
+ :header_footer => true, :backend => 'docbook', :safe => Asciidoctor::SafeMode::SERVER, :attributes => {'docinfo2' => ''}
assert !output.empty?
assert_css 'productname', output, 1
assert_xpath '//xmlns:productname[text()="Asciidoctorâ„¢"]', output, 1
@@ -571,20 +579,20 @@ text
test 'should include docinfo footer files for html backend' do
sample_input_path = fixture_path('basic.asciidoc')
- output = Asciidoctor.render_file(sample_input_path,
- :header_footer => true, :safe => Asciidoctor::SafeMode::SERVER, :attributes => {'docinfo' => ''})
+ output = Asciidoctor.convert_file sample_input_path, :to_file => false,
+ :header_footer => true, :safe => Asciidoctor::SafeMode::SERVER, :attributes => {'docinfo' => ''}
assert !output.empty?
assert_css 'body script', output, 1
assert_css 'a#top', output, 0
- output = Asciidoctor.render_file(sample_input_path,
- :header_footer => true, :safe => Asciidoctor::SafeMode::SERVER, :attributes => {'docinfo1' => ''})
+ output = Asciidoctor.convert_file sample_input_path, :to_file => false,
+ :header_footer => true, :safe => Asciidoctor::SafeMode::SERVER, :attributes => {'docinfo1' => ''}
assert !output.empty?
assert_css 'body script', output, 0
assert_css 'a#top', output, 1
- output = Asciidoctor.render_file(sample_input_path,
- :header_footer => true, :safe => Asciidoctor::SafeMode::SERVER, :attributes => {'docinfo2' => ''})
+ output = Asciidoctor.convert_file sample_input_path, :to_file => false,
+ :header_footer => true, :safe => Asciidoctor::SafeMode::SERVER, :attributes => {'docinfo2' => ''}
assert !output.empty?
assert_css 'body script', output, 1
assert_css 'a#top', output, 1
@@ -593,21 +601,21 @@ text
test 'should include docinfo footer files for docbook backend' do
sample_input_path = fixture_path('basic.asciidoc')
- output = Asciidoctor.render_file(sample_input_path,
- :header_footer => true, :backend => 'docbook', :safe => Asciidoctor::SafeMode::SERVER, :attributes => {'docinfo' => ''})
+ output = Asciidoctor.convert_file sample_input_path, :to_file => false,
+ :header_footer => true, :backend => 'docbook', :safe => Asciidoctor::SafeMode::SERVER, :attributes => {'docinfo' => ''}
assert !output.empty?
assert_css 'article > revhistory', output, 1
assert_xpath '/xmlns:article/xmlns:revhistory/xmlns:revision/xmlns:revnumber[text()="1.0"]', output, 1 # verifies substitutions are performed
assert_css 'glossary#_glossary', output, 0
- output = Asciidoctor.render_file(sample_input_path,
- :header_footer => true, :backend => 'docbook', :safe => Asciidoctor::SafeMode::SERVER, :attributes => {'docinfo1' => ''})
+ output = Asciidoctor.convert_file sample_input_path, :to_file => false,
+ :header_footer => true, :backend => 'docbook', :safe => Asciidoctor::SafeMode::SERVER, :attributes => {'docinfo1' => ''}
assert !output.empty?
assert_css 'article > revhistory', output, 0
assert_css 'glossary#_glossary', output, 1
- output = Asciidoctor.render_file(sample_input_path,
- :header_footer => true, :backend => 'docbook', :safe => Asciidoctor::SafeMode::SERVER, :attributes => {'docinfo2' => ''})
+ output = Asciidoctor.convert_file sample_input_path, :to_file => false,
+ :header_footer => true, :backend => 'docbook', :safe => Asciidoctor::SafeMode::SERVER, :attributes => {'docinfo2' => ''}
assert !output.empty?
assert_css 'article > revhistory', output, 1
assert_xpath '/xmlns:article/xmlns:revhistory/xmlns:revision/xmlns:revnumber[text()="1.0"]', output, 1 # verifies substitutions are performed
@@ -629,8 +637,8 @@ text
Encoding.default_external = 'US-ASCII'
Asciidoctor::FORCE_ENCODING = true
end
- output = Asciidoctor.render_file(sample_input_path,
- :header_footer => true, :backend => 'docbook', :safe => Asciidoctor::SafeMode::SERVER, :attributes => {'docinfo2' => ''})
+ output = Asciidoctor.convert_file sample_input_path, :to_file => false,
+ :header_footer => true, :backend => 'docbook', :safe => Asciidoctor::SafeMode::SERVER, :attributes => {'docinfo2' => ''}
assert !output.empty?
assert_css 'productname', output, 1
assert_css 'edition', output, 1
@@ -648,14 +656,14 @@ text
test 'should not include docinfo files by default' do
sample_input_path = fixture_path('basic.asciidoc')
- output = Asciidoctor.render_file(sample_input_path,
- :header_footer => true, :safe => Asciidoctor::SafeMode::SERVER)
+ output = Asciidoctor.convert_file sample_input_path, :to_file => false,
+ :header_footer => true, :safe => Asciidoctor::SafeMode::SERVER
assert !output.empty?
assert_css 'script[src="modernizr.js"]', output, 0
assert_css 'meta[http-equiv="imagetoolbar"]', output, 0
- output = Asciidoctor.render_file(sample_input_path,
- :header_footer => true, :backend => 'docbook', :safe => Asciidoctor::SafeMode::SERVER)
+ output = Asciidoctor.convert_file sample_input_path, :to_file => false,
+ :header_footer => true, :backend => 'docbook', :safe => Asciidoctor::SafeMode::SERVER
assert !output.empty?
assert_css 'productname', output, 0
assert_css 'copyright', output, 0
@@ -664,14 +672,14 @@ text
test 'should not include docinfo files if safe mode is SECURE or greater' do
sample_input_path = fixture_path('basic.asciidoc')
- output = Asciidoctor.render_file(sample_input_path,
- :header_footer => true, :attributes => {'docinfo2' => ''})
+ output = Asciidoctor.convert_file sample_input_path, :to_file => false,
+ :header_footer => true, :attributes => {'docinfo2' => ''}
assert !output.empty?
assert_css 'script[src="modernizr.js"]', output, 0
assert_css 'meta[http-equiv="imagetoolbar"]', output, 0
- output = Asciidoctor.render_file(sample_input_path,
- :header_footer => true, :backend => 'docbook', :attributes => {'docinfo2' => ''})
+ output = Asciidoctor.convert_file sample_input_path, :to_file => false,
+ :header_footer => true, :backend => 'docbook', :attributes => {'docinfo2' => ''}
assert !output.empty?
assert_css 'productname', output, 0
assert_css 'copyright', output, 0
@@ -1097,7 +1105,7 @@ content
content
EOS
- result = render_string input, :header_footer => false, :attributes => {'notitle!' => ''}
+ result = render_embedded_string input, :attributes => {'notitle!' => ''}
assert_xpath '/html', result, 0
assert_xpath '/h1', result, 1
assert_xpath '/*[@id="header"]', result, 0
@@ -1114,7 +1122,7 @@ content
content
EOS
- result = render_string input, :header_footer => false, :attributes => {'showtitle' => ''}
+ result = render_embedded_string input, :attributes => {'showtitle' => ''}
assert_xpath '/html', result, 0
assert_xpath '/h1', result, 1
assert_xpath '/*[@id="header"]', result, 0
@@ -1166,7 +1174,7 @@ finally a reference to the second footnote footnoteref:[note2].
Text that has supporting information{empty}footnote:[An example footnote.].
EOS
- output = render_string input, :header_footer => false
+ output = render_embedded_string input
assert_css '#footnotes', output, 1
end
@@ -1175,7 +1183,7 @@ Text that has supporting information{empty}footnote:[An example footnote.].
Text that has supporting information{empty}footnote:[An example footnote.].
EOS
- output = render_string input, :header_footer => false, :attributes => {'nofootnotes' => ''}
+ output = render_embedded_string input, :attributes => {'nofootnotes' => ''}
assert_css '#footnotes', output, 0
end
end