Coder Social home page Coder Social logo

erbmash's People

Contributors

mikesimons avatar

Watchers

 avatar  avatar

erbmash's Issues

Hash access helpers

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.

Command line data merge

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

Root pointer

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

Truthy / falsy helpers

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?

Director script support

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.

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.