Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Extend Metadata with YAML data files defined in configuration #175

Open
wants to merge 8 commits into
base: master
Choose a base branch
from

Conversation

adrienrn
Copy link

I took the liberty to implement a first attempt at mimicking Jekyll _data directory by loading files in configuration as if it was included in couscous.yml.

It works by defining the dataFiles in your couscous.yml:

...
# List of files to parse and load into the configuration and make available to twig templates by their key
# Paths are relative to the optional source path given when generating the website, repository root by default
dataFiles:
  myCustomFile: data/my-custom-file.yml
  otherFile: data/other-file.yml
...

Path to those files are resolved related to project source directory, repository root by default. You can then use values in any twig templates by their keys, as if it was defined in the couscous.yml file itself.

  • Load YAML files
  • Load JSON files
  • Load CSV files

See #174 for more informations.

@adrienrn adrienrn changed the title Extend Metadata with YAML data files defined in configuration (#174) Extend Metadata with YAML data files defined in configuration Jul 15, 2016
@mnapoli
Copy link
Member

mnapoli commented Jul 20, 2016

Hi, thanks for the pull request. We cannot merge a pull request without tests though, could you write some?

Also I would rather see the section named import rather than dataFiles. That section could also contain a list of files, not a map:

import:
    - data/my-custom-file.yml
    - data/other-file.yml

Since it would be a straight import the keys would not be necessary: it makes the whole thing simpler to think about imports than "data files", and it also restricts less the possibilities (those files could contain configuration, not data).

@adrienrn
Copy link
Author

Hi, thanks for the pull request. We cannot merge a pull request without tests though, could you write some?

Also I would rather see the section named import rather than dataFiles. That section could also contain a list of files, not a map

Done something and added some unit tests too.

Before merging, there's something that I'm not quite sure it's the best idea.

I'm using array_replace_recursive to merge imported files and couscous.yml. It works for the most part but if you want to overwrite a list (such as include) you have to repeat the original value. See the unit test.

Don't sure we want to merge though, but difficult to handle collision if we do not merge.

@mnapoli
Copy link
Member

mnapoli commented Jul 26, 2016

I'm using array_replace_recursive to merge imported files and couscous.yml. It works for the most part but if you want to overwrite a list (such as include) you have to repeat the original value. See the unit test.

I think it's fine to overwrite the whole key and not merge values. It would be very difficult to do otherwise because what we would like to happen depends a lot on the configuration value (sometimes we would want to merge, sometimes we would want to replace). Always replace is easier.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants