From e194dc2ebda93f061c6b35c49e948ac34d2b2de6 Mon Sep 17 00:00:00 2001 From: Abu Nashir Date: Tue, 29 Jun 2021 11:05:03 +0200 Subject: [PATCH] [ci skip] - Add option parsing for collection --- lib/metanorma/cli/collection_parser.rb | 38 ++++++++++++++++++++ spec/metanorma/cli/collection_parser_spec.rb | 2 +- 2 files changed, 39 insertions(+), 1 deletion(-) diff --git a/lib/metanorma/cli/collection_parser.rb b/lib/metanorma/cli/collection_parser.rb index 4366405..1a7a314 100644 --- a/lib/metanorma/cli/collection_parser.rb +++ b/lib/metanorma/cli/collection_parser.rb @@ -1,6 +1,44 @@ +require "yaml" + module Metanorma module Cli class CollectionParser + def initialize(collection_file) + @collection_file = collection_file + end + + def self.parse(collection_file) + new(collection_file).parse + end + + def parse + # extract out the options + options = extract_options(yaml_content) + # load the file + metanorma_collection.render(options) + + # pass it down to metanorma + end + + private + + attr_reader :collection_file + + def yaml_content + @yaml_content ||= YAML.load(File.read(collection_file.to_s)) + end + + def metanorma_collection + @metanorma_collection ||= Metanorma::Collection.parse(collection_file) + end + + def extract_options(content_hash) + Hash.new.tap do |options| + options[:coverpage] = content_hash["cover"] + options[:output_folder] = content_hash["output_dir"] + options[:format] = content_hash["formats"].map(&:to_sym) + end + end end end end diff --git a/spec/metanorma/cli/collection_parser_spec.rb b/spec/metanorma/cli/collection_parser_spec.rb index 55ae3a8..e945e76 100644 --- a/spec/metanorma/cli/collection_parser_spec.rb +++ b/spec/metanorma/cli/collection_parser_spec.rb @@ -9,7 +9,7 @@ def sample_collection_file @sample_collection_file ||= Metanorma::Cli.root_path.join( - "collection_with_options.yml", + "spec", "fixtures", "collection_with_options.yml", ) end end