Skip to content

Commit

Permalink
[ci skip] - Add option parsing for collection
Browse files Browse the repository at this point in the history
  • Loading branch information
abunashir committed Jun 29, 2021
1 parent b383a49 commit e194dc2
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 1 deletion.
38 changes: 38 additions & 0 deletions lib/metanorma/cli/collection_parser.rb
Original file line number Diff line number Diff line change
@@ -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
2 changes: 1 addition & 1 deletion spec/metanorma/cli/collection_parser_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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

0 comments on commit e194dc2

Please sign in to comment.