-
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.
[skip ci] - Add support for collection options
- Loading branch information
Showing
6 changed files
with
173 additions
and
5 deletions.
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 |
---|---|---|
|
@@ -20,6 +20,7 @@ | |
.rspec_status | ||
.vscode/ | ||
relaton/ | ||
*.log | ||
|
||
*.gem | ||
|
||
|
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 |
---|---|---|
@@ -0,0 +1,58 @@ | ||
require "yaml" | ||
|
||
module Metanorma | ||
module Cli | ||
class CollectionParser | ||
def initialize(collection_file, options = {}) | ||
@options = options | ||
@collection_file = collection_file.to_s | ||
end | ||
|
||
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) | ||
# puts options | ||
|
||
# require "pry" | ||
# binding.pry | ||
|
||
# load the file | ||
# 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, :options | ||
|
||
def yaml_content | ||
@yaml_content ||= YAML.safe_load(File.read(collection_file)) | ||
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
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 |
---|---|---|
@@ -0,0 +1,67 @@ | ||
directives: | ||
- documents-inline | ||
|
||
bibdata: | ||
title: | ||
- language: en | ||
content: The International System of Units (SI) | ||
- language: fr | ||
content: Le Système international d’unités (SI) | ||
type: collection | ||
docid: | ||
type: bipm | ||
id: sibrochure | ||
edition: 9 | ||
date: | ||
- type: updated | ||
value: "2019-05-20" | ||
copyright: | ||
owner: | ||
name: Bureau International des Poids et Mesures | ||
abbreviation: BIPM | ||
from: 2019 | ||
|
||
# TODO, was CLI option, not yet supported | ||
output_dir: bilingual-brochure | ||
|
||
# TODO, was CLI option, not yet supported | ||
formats: | ||
- xml | ||
- html | ||
- presentation | ||
|
||
manifest: | ||
level: brochure | ||
title: Brochure/Brochure | ||
|
||
docref: | ||
- fileref: site/documents/si-brochure-fr.xml | ||
identifier: si-brochure-fr | ||
- fileref: site/documents/si-brochure-en.xml | ||
identifier: si-brochure-en | ||
|
||
|
||
# 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 | ||
|
||
prefatory-content: | ||
| | ||
|
||
|
||
final-content: | ||
| |
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 |
---|---|---|
@@ -0,0 +1,16 @@ | ||
require "spec_helper" | ||
|
||
RSpec.describe Metanorma::Cli::CollectionParser do | ||
describe ".parse" do | ||
it "parse the options properly" do | ||
|
||
Metanorma::Cli::CollectionParser.parse(sample_collection_file) | ||
end | ||
end | ||
|
||
def sample_collection_file | ||
@sample_collection_file ||= Metanorma::Cli.root_path.join( | ||
"spec", "fixtures", "collection_with_options.yml" | ||
) | ||
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
### Site generate with collection | ||
|
||
On the site generator configuration: we want to add an option/field, where | ||
a user can provide collection file as configuration. | ||
|
||
During site generation, we want the generator to take this into consideration | ||
and based on this we also want to the site generator to invoke the collection | ||
building happening. | ||
|
||
In the collection interface, we also want to support configuration options, | ||
instead of passing around we also want to be specified in form of data filed | ||
and use that one to pass it down to the metanorma xml | ||
|
||
### Todos | ||
|
||
- [ ] Add support for collection option parsing | ||
- [ ] Adopt the field changes for the collection | ||
- [ ] Define collection config in the generator | ||
- [ ] Invoke the parsing from the site generator | ||
- [ ] Adopt this interface in collection, maybe? |