'Preprocess (populate, generate) files with the content of other files
I'm going to explain what my problem is using a representative example.
Let's say I have these 2 configuration files:
# product-conf.file
seo_title: general_title
seo_description: seo_description
seo_canonical: seo_canonical
product_id: general_id
title: general_title
intro: general_intro
.
# service-conf.file
seo_title: general_title
seo_description: seo_description
seo_canonical: seo_canonical
service_id: general_id
title: general_title
products: list_products
As you can see, the 3 first lines (configuration fields) are exactly the same. I'm actually using YAML for these files. I would like to have pieces of code in maintainable files and include them with calls. I need a preprocessor for these. Something like:
# snippet-seo.file
seo_title: general_title
seo_description: seo_description
seo_canonical: seo_canonical
.
# product-conf-master.file
@include snippet-seo
product_id: general_id
title: general_title
intro: general_intro
.
# service-conf-master.file
@include snippet-seo
service_id: general_id
title: general_title
products: list_products
The preprocessor will read all the master files in /masters/*, attend all the calls and substituting them for the appropriate snippet from /snippets/ and saving the result in /
I'm doing the call with @ but I can choose whatever other format is suitable for the chosen preprocessor. I used this way because it strongly resembles to the SASS directive @extend or @include.
What is the best and easiest way I can achieve this? A package for node would be my first choice.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
