diff --git a/lib/metanorma/cli/collection.rb b/lib/metanorma/cli/collection.rb index aab3940..fee0e29 100644 --- a/lib/metanorma/cli/collection.rb +++ b/lib/metanorma/cli/collection.rb @@ -26,11 +26,17 @@ def collection_file @collection_file ||= Metanorma::Collection.parse(file) end + def source_folder + @source_folder ||= Pathname.new( + File.dirname(File.expand_path(file)), + ).join("output").to_s + end + def collection_options - { + @collection_options ||= { compile: @compile_options, coverpage: options.fetch(:coverpage, nil), - output_folder: options.fetch(:output_folder, nil), + output_folder: options.fetch(:output_folder, source_folder), format: collection_output_formats(options.fetch(:format, "")), } end diff --git a/lib/metanorma/cli/command.rb b/lib/metanorma/cli/command.rb index 8a9a902..5f33612 100644 --- a/lib/metanorma/cli/command.rb +++ b/lib/metanorma/cli/command.rb @@ -59,7 +59,7 @@ def compile(file_name = nil) desc "collection FILENAME", "Render HTML pages from XML/YAML colection" option :format, aliases: "-x", type: :string, desc: "Formats to generate" - option :output_folder, aliases: "-w", required: true, desc: "Directory to save compiled files" + option :output_folder, aliases: "-w", desc: "Directory to save compiled files" option :coverpage, aliases: "-c", desc: "Liquid template" option :agree_to_terms, type: :boolean, desc: "Agree / Disagree with all third-party licensing terms "\ "presented (WARNING: do know what you are agreeing with!)" diff --git a/spec/acceptance/collection_spec.rb b/spec/acceptance/collection_spec.rb index 108e289..4f4e88c 100644 --- a/spec/acceptance/collection_spec.rb +++ b/spec/acceptance/collection_spec.rb @@ -11,6 +11,11 @@ run_metanorma_collection("collection1.xml") expect_generated_files_to_match_expectations end + + it "usages file's path as default output folder" do + run_metanorma_collection("collection1.xml") + expect_generated_files_to_match_expectations + end end around(:each) do |example| @@ -24,7 +29,6 @@ def run_metanorma_collection(filename) command = %W( collection #{filename} -x html - -w #{RESULTS} -c collection_cover.html --no-install-fonts ) diff --git a/spec/metanorma/cli/collection_spec.rb b/spec/metanorma/cli/collection_spec.rb index b192c1b..b1b4e70 100644 --- a/spec/metanorma/cli/collection_spec.rb +++ b/spec/metanorma/cli/collection_spec.rb @@ -5,9 +5,16 @@ context "with specified options" do it "compiles and renders the collection files" do collection = mock_collection_instance - Metanorma::Cli::Collection.render(collection_file, format: "html, pdf") - expect(collection).to have_received(:render).with(format: %I(html pdf)) + Metanorma::Cli::Collection.render( + collection_file, + format: "html, pdf", + output_folder: "bilingual-brochure", + ) + + expect(collection).to have_received(:render).with( + format: %I(html pdf), output_folder: "bilingual-brochure", + ) end end @@ -25,6 +32,19 @@ ) end end + + context "with missing options" do + it "usages the source as reference for options" do + collection = mock_collection_instance + + Metanorma::Cli::Collection.render(collection_file) + output_path = File.dirname(collection_file.to_s) + + expect(collection).to have_received(:render).with( + hash_including(output_folder: "#{output_path}/output"), + ) + end + end end def collection_file(collection = "collection1.yml")