GithubHelp home page GithubHelp logo

punkunicorn / scribancsvtemplateengine Goto Github PK

View Code? Open in Web Editor NEW
0.0 2.0 0.0 274 KB

ScribanCsvTemplateEngine - text (code) templating from csv file input ...featuring Scriban!

License: MIT License

C# 80.57% Smalltalk 19.43%
csv yaml scriban template-engine

scribancsvtemplateengine's Introduction

ScribanCsvTemplateEngine

ScribanCsvTemplateEngine - text (code) templating from csv file input ...featuring Scriban!

previously YamlCodeGenThing

  1. Take a bunch of template text files, using {{ }} for variable placement (Scriban style) for values to be exchanged.

  2. Take a csv file, with the first row being csv headers to give the columns names, and then these names can be referenced in the template corpus as exchange variables, e.g:

  "age,  name,   origin_story,
  27, John, Blah blah,
  32, Jill, Etc etc"

And in the template file:

  "Their age is {{age}}, and their name is {{name}.
  {{origin_story}}"
  1. This command line utility then creates a copy of each of the template files for each row in the csv file, exchanging the values using Scriban.

In addition to csv data variables, data variables can also be added globally. These are put in the yaml file, and add to the model for each csv row. The global data lives in the 'data:' section of the yaml (see below)

These yaml data variables are added to the csv model for each row. Note that data items in the csv file will override data items in the global yaml data, if they share the same name.

Here is an example yaml file. The free form values are directly under the 'data:' section:

input:
  csv_filename: .\Example\input.csv
template:
  scriban_filenames:
    - .\Example\Templates\test1.cs
    - .\Example\Templates\test2.cs
    - .\Example\Templates\test3.cs
    - .\Example\Templates\Subfolder\test4.cs
  base_path: .\Example\Templates\
output:
  output_path: .\Example\Output\
  csv_column_for_ouput_path_part: name #<-- references the csv header from the input file, and uses this to build the output path to separate the results for each csv row. Spaces in names are stripped
data:
  add_your_extra_data_items_here_which_are_accessable_by_all_template_files:
    using_standard_yaml: true
  which_means_you_can_make_lists:
    - like_this
    - and_this
    - etc
  and:
    nested:
      data_items:
         - name: bob
           age: 50
           fav_colour: blue
         - name: alf
           age: 70
           fav_colour: red
  more_data:
    and_more: A Little Lamb

Then you can reference this data in the template files, using Scriban notation:

<html><body>{{for item in which_means_you_can_make_lists}}

Or

Mary had {{more_data.and_more}}

Template file data overrides: Data items can also be added for each template file. This is done by adding a .yaml file of the same name as the template file, except changing the extension to be 'yaml' instead of what it was originally, and putting this yaml file in the same folder as the template file of the same name. You do not need a 'data:' section for these template override yaml files, as the whole yaml is added as the model.

Order of precedence, amongst the different data source, for data members name clashes is:

1st - Csv data items (if the value is blank, it is ignored and the value is taken from the next in order of precedence. Only blank csv data items give way to lesser presidence. 2nd - ScribanCsvTemplateEngine.yaml 'data:' 3rd - template file yaml data

That is, main program yaml 'data:' items will override the template level yaml.

And csv data will override all others.

scribancsvtemplateengine's People

Contributors

punkunicorn avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.