mikesimons / erbmash Goto Github PK
View Code? Open in Web Editor NEWStatically compiled tool to ingest json + erb and produce config files
License: MIT License
Statically compiled tool to ingest json + erb and produce config files
License: MIT License
Guarding against nil
is a bit of a PITA.
Consider:
@data['items'].each ...
If @data
is empty or @data['items']
is not set you get template errors.
To make these optional you need to do...
((@data || {})['items'] || {})
... which is obviously horrendous.
In some cases the error may be desirable to protect output integrity but an optional --maybe-data
flag or some way of accessing the data optionally could be handy.
Would be useful to be able to override / provide additional parameters that are merged in to @data
from the command line.
e.g. data.yaml
item1:
sub_item1: x
item2:
sub_item2: y
templateer --data item1.sub_item2=z data.yml -
would yield @data
:
item1:
sub_item1: x
sub_item2: z
item2:
sub_item2: y
Need to consider the following scenarios:
--data some_bool=true
should be Boolean
, not the string true
.
--data some_int=1
should be Numeric
, not the string 1
--data some_array[]=append
should append the string append
to some_array
--data some_array=[1,2,3]
should be an Array
type containing Numeric
types 1
, 2
& 3
Where templateer is operating on a subset of a larger configuration file it may be handy to be able to change where in the tree @data
is from.
Consider data.yaml
metadata:
somestuff: hello
config:
nested:
subnest:
useful_data1: 1
useful_data2: 2
Where a template only operates on config -> nested -> subnest
it would make sense for @data
to only contain the contents of that.
A cli flag, --root
of a dotted or slashed path type notation would make most sense I think.
Examples:
templateer --root config.nested.subnest data.yaml sometemplate.erb
or
templateer --root config/nested/subnest data.yaml sometemplate.erb
To support nicer inputs a truthy helper should be implemented (to be used at the discretion of template authors) that supports the following:
True
y, yes, numeric type != 0, true
False
n, no, 0, false, ""
Invocation forms could be truthy(val)
or val.truthy?
Provide the ability to supply a director script as an argument that can massage input data and direct output data.
Example
# director.rb
template = load_template(ARGV[1])
@data['network']['interfaces'].each do |name, interface|
File.write("/etc/sysconfig/network-scripts/ifcfg-#{name}", process(interface, template)
end
templateer --director director.rb some_data.yaml
Note that the director script controls template loading, processing order and output writing.
In this capacity templateer becomes far more general purpose but allows for higher level usage.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.