Giter VIP home page Giter VIP logo

handlebars.conf-bitwarden's Introduction

Handlebars.conf

Handlebars templates for config files.

Install

Download the latest release binary for your system from the Releases page. Note that there are different binaries for various architectures on Linux, Alpine, macOS, and Windows.

Linux x64 example:

curl -L -o hbs.zip https://github.com/kspearrin/Handlebars.conf/releases/download/v1.3.0/hbs_linux-x64.zip
sudo unzip hbs.zip -d /usr/local/bin && rm hbs.zip
sudo chmod +x /usr/local/bin/hbs

hbs --help

NOTE: Release binaries with the _dotnet suffix are smaller in size, but require the .NET Core runtime to be installed on the host machine.

Examples

Basic Usage

Handlebars config file: hbs.yaml

templates:
  - src: test.conf.hbs
    dest: test.conf

Source Handlebars template: test.conf.hbs.

Note: Environment variables are available under the env property.

<Section>
    {{env.username}}
</Section>

Run command

hbs -c hbs.yaml

Destination output: test.conf

<Section>
    kyle
</Section>

Multiple Templates

templates:
  - src: foo.conf.hbs
    dest: foo.conf
  - src: bar.conf.hbs
    dest: bar.conf
  - src: baz.conf.hbs
    dest: baz.conf

Handlebars Templating

Learn more about using Handlebars templates here: https://handlebarsjs.com

Handlebars Helpers

You can load Handlebars helpers from the Handlebars.Net Helpers library by specifying helper categories to load in your config file.

Config

helper_categories:
  - String
  - Math
templates:
  - src: test.conf.hbs
    dest: test.conf

Template test.conf.hbs

{{Math.Add 4 5}}

{{#if (String.IsNotNullOrWhitespace env.username)}}
{{String.Append env.username " is awesome."}}
{{/if}}

{{String.Coalesce "" "     " "value" " " "value2"}}

{{#each (String.Split "1,2, 3" ",")}}
Number: {{String Trim .}}
{{/each}}

{{#if (String.Equal env.username "tom")}}
user is tom.
{{else}}
user is {{String.Uppercase env.username}}.
{{/if}}

Result test.conf

9

kyle is awesome.

value

Number: 1
Number: 2
Number: 3

user is KYLE.

Real World Example

You can see this tool in use with Bitwarden's Nginx config here: https://github.com/bitwarden/server/tree/master/docker-unified/hbs

handlebars.conf-bitwarden's People

Contributors

kspearrin 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.