joeatbayes / interpolator

Produce finished Markdown documents by Interpolating content from previously defined entities by reference. Avoid the need manually update markdown files using cut and paste commonly used terms descriptions or object definitions.
MIT License
2 stars 1 forks source link
api-documentation golang-tools markdown markdown-interpolation markdown-parser markdown-viewer

Interpolator

Reads a text or markdown file and replaces defined values with contents from previously defined content such as a dictionary or object definitions.

Command Line API

Sample Invocation

interpolate  -in=data/sample -out=out -glob=*.md -search=./data/data-dict  -VarNames=desc,domain  -keepNames=yes -maxRec=99 -loopDelay=5 -saveHtml=yes

Sample Invocation with multiple search directory inputs

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

Sample Invocation with 3 VarNames inputs (which doesn't work)

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.

Save version with markdown converted to HTML

interpolate  -in=data/sample -out=out -glob=*.md -search=./data/data-dict  -VarNames=desc,tech_desc  -keepNames=true -maxRec=99 -saveHtml=yes

Run in a Continuous Loop to support easy preview

interpolate  -in=data/sample -out=out -glob=*.md -search=./data/data-dict  -VarNames=desc,tech_desc  -keepNames=true -maxRec=99 -saveHtml=yes -loopDelay=10

Data Format API

The sample shown here uses md (markdown) syntax but it would work with any text file that can be parsed in a similar fashion.

Sample Input

sample-api.md

# 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}

Sample Data Dictionary LOOKUP

person/fname.yml

name: fname
domain: addressbook
table: person
desc: First name of person
type: string
len: 50

person/lname.yml

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

legal/copyright.txt

(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'
    }
  } 
​```

Sample Output

sample output

Build

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.

To Download all pre-built test cases, scripts and source code
git clone https://github.com/joeatbayes/interpolator interpolate

Important Files

Build for Multiple OS Linux / Windows / Mac

make-go-all-os.bat: Batch file to build executable for multiple OS. runs on windows

Windows example to build for other OS

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 

Contributing

Header Fld Used By
abc api/defg
api/mpeg
api/mangle
abx api/mgap
aby api/killer