-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[ci skip] - Add option parsing for collection
- Loading branch information
Showing
2 changed files
with
39 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters