Skip to content

Commit

Permalink
Fix collection option related issue
Browse files Browse the repository at this point in the history
We have recently added support to provide collection options either
as an command line arguments or options in the collection file. But
that is only working on the site interface, and the collection cli
still expect the `output-folder` as required option.

This commit changes that, so it's not required anymore and it will
try to read the option from the file, and if none of those source
has this value, then it will use the source as output directory,
and to keep this file separated it will use the `source/output`

Fixes #283
  • Loading branch information
abunashir committed Sep 14, 2022
1 parent 03b7eaa commit 65a5ace
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 6 deletions.
10 changes: 8 additions & 2 deletions lib/metanorma/cli/collection.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion lib/metanorma/cli/command.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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!)"
Expand Down
6 changes: 5 additions & 1 deletion spec/acceptance/collection_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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|
Expand All @@ -24,7 +29,6 @@ def run_metanorma_collection(filename)
command = %W(
collection #{filename}
-x html
-w #{RESULTS}
-c collection_cover.html
--no-install-fonts
)
Expand Down
24 changes: 22 additions & 2 deletions spec/metanorma/cli/collection_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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")
Expand Down

0 comments on commit 65a5ace

Please sign in to comment.