Reads a text or markdown file and replaces defined values with contents from previously defined content such as a dictionary or object definitions.
interpolate -in=data/sample -out=out -glob=*.md -search=./data/data-dict -VarNames=desc,domain -keepNames=yes -maxRec=99 -loopDelay=5 -saveHtml=yes
interpolate -in=data/sample -out=out -glob=*.md -search=./data/data-dict,./data/api-com -VarNames=desc,domain -keepNames=yes -maxRec=99 -loopDelay=5 -saveHtml=yes
interpolate -in=data/sample -out=out -glob=*.md -search=./data/data-dict -VarNames=desc,tech_desc,table -keepNames=yes -maxRec=99 -loopDelay=5 -saveHtml=yes
-in = path to input directory containing files to process.
Defaults to ./data
-out = path to output directory where expanded files will be
written. defaults to ./out
-glob= glob pattern to use when selecting files to process in
input directory. Defaults to *.md
-search = Directory Base to search for files named in
interpolated parameters.
-varNames = Default variable name matched in dictionary files.
Can be overridden if variable name is specified using
#varname semantic. May be common separated list to
allow default lookup of backup fields such as look first
in tech_desc then in desc. -varNames=desc,tech_desc -
Causes the system to search first in the desc: field
then in the tech_desc. This would use the business
description to be used first and then filled in tech
desc if desc is not found. Just reverse the order to
cause it to use the technical description first. It
will use the first one found. When the varname is
specified using the # semantic it will use the
specified var name and ignore the default varNames.
-keepNames = when set to true it will keep the supplied path as
part of output text. When not set or false will
replace content of path with content.
-saveHtml=yes when set to yes will convert the md file to Html
and save it in the output directory. When not set the
the system will not save the HTML file.
-maxRec this is a variable defined on command line that is
being interpolated. Resolution of variables defined
on command line take precedence over those resolved
in files.
-loopDelay - When set the system will process the input.
Sleep for a number of seconds and then re-process.
This is intended to keep a generated file available to
easily reload. eg: -loopDelay=30 will cause the system to
reprocess the input files once every 30 seconds.
When not set the system will run once and quit.
-r=yes - When set to yes the system will recursively walk
all directories contained in the -in directory and process
every file that matches the glob pattern. If not set will
only walk the named directory. When recurseDir is set to
yes then it will create directories in the output directory
that mirror the input directory path whenever a matching input
file is found.
-makeCrossRef=yes - when set to yes the system will generate a
.md file and a sorted file containing contents of files
referencing a specific data dictionary item. Defaults to false.
interpolate -in=data/sample -out=out -glob=*.md -search=./data/data-dict -VarNames=desc,tech_desc -keepNames=true -maxRec=99 -saveHtml=yes
interpolate -in=data/sample -out=out -glob=*.md -search=./data/data-dict -VarNames=desc,tech_desc -keepNames=true -maxRec=99 -saveHtml=yes -loopDelay=10
The sample shown here uses md (markdown) syntax but it would work with any text file that can be parsed in a similar fashion.
# Name Search
**path**: addrBook/search
**sample uri**: http://namesearch.com/addrBook/search?fname=joe&lname=jackson&maxRec=389
* **maxRec**={*maxRec}
* **fname**= {*person/fname}
* **lname**= {*person/lname#tech_desc}
* **Type**={*person/lname#type} **len**={*person/lname#len}
## Sample Output
{*inc: share/person/example_person.md}
## Copyright
{*inc: share/legal/copyright.txt}
Any string contained inside of {} will be treated as a variable that needs to be resolved. When first character after { is . The was used to make it easier to avoid parsing and attempted interpolation when sample JSON or other curly brace languages are part of input.
The system will always match the closest } whenever it encounters the opening {. The closing } must not be separated by vertical white space such as /n.
Any variable name not matched with a valid defined string or file will be replaced be included untouched.
Any interpolated variable starting with "inc:" will be treated as a simple file include where the entire file located at the specified path will be read and inserted into the output replacing the {path}.
Dictionary YML must follow a simplified format. The match pattern is simply the variable name that must start on first of line followed by :. It will include text until it detects the next word followed by a : followed by a space.
name: fname
domain: addressbook
table: person
desc: First name of person
type: string
len: 50
name: lname
domain: addressbook
table: person
desc: Last Name of person
tech_desc: Last Name of person stored in addressbook.table.person.lname in primary oracle database.
Must Match legal name as shown on drivers license or passport.
{ 'person' : {'lname' : 'myname' } }
type: string
len: 50
(C) Copyright Joseph Ellsworth Mar-2019
MIT License: https://opensource.org/licenses/MIT
Contact me on linkedin: https://www.linkedin.com/in/joe-ellsworth-68222/
share/person/example_person.md
Used to show the concept of a re-usable shared component.
```
'person': {
'lname': 'Jimbo',
'fname': 'Jackson',
'colors': {
'car': 'red',
'boat': 'blue',
'house': 'cream',
'hair': 'brown'
}
}
```
Once you have the golang compiler installed.
go get -u -t "github.com/joeatbayes/interpolator/interpolate"
It will create a executable in your GOPATH directory in bin/interpolate. For windows it will be httpTest.exe. If GOPATH is set the /tmp then the executable will be written to /tmp/bin/interpolate under Linux or /tmp/bin/interpolate.exe for windows.
Once you build the executable you can copy it to other computers without the compiler. It only requires the single executable file.
HINT: set GOTPATH= your current working directory. Or set it to your desired target directory and the go get command will create the executable in bin inside of that directory which is good because you may not have write privileges to the default GOPATH.
git clone https://github.com/joeatbayes/interpolator interpolate
make-go-all-os.bat: Batch file to build executable for multiple OS. runs on windows
set GOPATH=%cd%
go get -u "github.com/joeatbayes/goutil/jutil"
set GOOS=darwin
set GOARCH=386
go build -o interpolate-darwin-386 interpolate/interpolate.go
set GOOS=linux
set GOARCH=386
go build -o interpolate-linux-386 interpolate/interpolate.go
set GOOS=windows
set GOARCH=386
go build -o interpolate-windows-386 interpolate/interpolate.go
set GOOS=solaris
set GOARCH=amd64
go build -o interpolate-solaris-amd64 interpolate/interpolate.go
Header Fld | Used By |
---|---|
abc | api/defg |
api/mpeg | |
api/mangle | |
abx | api/mgap |
aby | api/killer |