Skip to content

Commit

Permalink
[skip ci] Replace collection parser usages
Browse files Browse the repository at this point in the history
  • Loading branch information
abunashir committed Jul 25, 2021
1 parent 622f08c commit 43e5468
Show file tree
Hide file tree
Showing 4 changed files with 48 additions and 25 deletions.
28 changes: 19 additions & 9 deletions lib/metanorma/cli/collection_parser.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,30 +3,40 @@
module Metanorma
module Cli
class CollectionParser
def initialize(collection_file)
def initialize(collection_file, options = {})
@options = options
@collection_file = collection_file
end

def self.parse(collection_file)
new(collection_file).parse
def self.parse(collection_file, options = {})
new(collection_file, options).parse
end

def parse
puts merged_options(extract_options(yaml_content), options)
# puts options
# puts extract_options(yaml_content)

# extract out the options
options = extract_options(yaml_content)
# options = extract_options(yaml_content)
# puts options

# require "pry"
# binding.pry

# load the file
metanorma_collection.render(options)
# metanorma_collection.render(options)

# pass it down to metanorma
end

def merged_options(base_options, prefered_options)
base_options.merge(prefered_options)
end

private

attr_reader :collection_file
attr_reader :collection_file, :options

def yaml_content
@yaml_content ||= YAML.safe_load(File.read(collection_file.to_s))
Expand All @@ -38,9 +48,9 @@ def metanorma_collection

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)
options["coverpage"] ||= content_hash["cover"]
options["output_folder"] ||= content_hash["output_dir"]
options["format"] ||= content_hash["formats"]&.map(&:to_sym)
end
end
end
Expand Down
15 changes: 10 additions & 5 deletions lib/metanorma/cli/command.rb
Original file line number Diff line number Diff line change
Expand Up @@ -67,11 +67,16 @@ def compile(file_name = nil)

def collection(filename = nil)
if filename
opts = options
opts[:format] &&= opts[:format].split(",").map &:to_sym
opts[:compile] = filter_compile_options(opts)
coll = Metanorma::Collection.parse filename
coll.render opts
# opts = options
# opts[:compile] = filter_compile_options(opts)
# coll = Metanorma::Collection.parse filename
# coll.render opts

col_options = options.dup
col_options[:compile] = filter_compile_options(col_options)
col_options[:format] &&= col_options[:format].split(",").map &:to_sym

Metanorma::Cli::CollectionParser.parse(filename, col_options)
else UI.say("Need to specify a file to process")
end
rescue ArgumentError => e
Expand Down
29 changes: 18 additions & 11 deletions spec/fixtures/collection_with_options.yml
Original file line number Diff line number Diff line change
Expand Up @@ -35,20 +35,27 @@ manifest:
level: brochure
title: Brochure/Brochure

# TODO, not yet supported
# Option 1, specify built files
# Option 2, specify source if not built
documents: # was `docref`
- source: si-brochure-fr.adoc
docref:
- fileref: site/documents/si-brochure-fr.xml
identifier: si-brochure-fr
- fileref: site/documents/si-brochure-en.xml
identifier: si-brochure-en

# was `fileref`
rendered: site/documents/si-brochure-fr.xml

- identifier: si-brochure-en
source: si-brochure-en.adoc
rendered: site/documents/si-brochure-en.xml

# TODO, not yet supported
# Option 1, specify built files
# Option 2, specify source if not built
# documents: # was `docref`
# - source: si-brochure-fr.adoc
# identifier: si-brochure-fr
#
# # was `fileref`
# rendered: site/documents/si-brochure-fr.xml
#
# - identifier: si-brochure-en
# source: si-brochure-en.adoc
# rendered: site/documents/si-brochure-en.xml
#
# TODO, was CLI option, not yet supported
cover: collection_cover.html

Expand Down
1 change: 1 addition & 0 deletions spec/metanorma/cli/collection_parser_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
RSpec.describe Metanorma::Cli::CollectionParser do
describe ".parse" do
it "parse the options properly" do

Metanorma::Cli::CollectionParser.parse(sample_collection_file)
end
end
Expand Down

0 comments on commit 43e5468

Please sign in to comment.