github.com/ijc/docker-app@v0.6.1-0.20181012090447-c7ca8bc483fb/internal/renderer/yatee/driver.go (about)

     1  // +build experimental
     2  
     3  package yatee
     4  
     5  import (
     6  	"strings"
     7  
     8  	"github.com/docker/app/internal/renderer"
     9  	"github.com/docker/app/internal/yaml"
    10  	"github.com/docker/app/pkg/yatee"
    11  	"github.com/pkg/errors"
    12  )
    13  
    14  func init() {
    15  	renderer.Register("yatee", &Driver{})
    16  }
    17  
    18  // Driver is the yatee implementation of rendered drivers.
    19  type Driver struct{}
    20  
    21  // Apply applies the settings to the string
    22  func (d *Driver) Apply(s string, settings map[string]interface{}) (string, error) {
    23  	yateed, err := yatee.Process(s, settings, yatee.OptionErrOnMissingKey)
    24  	if err != nil {
    25  		return "", err
    26  	}
    27  	m, err := yaml.Marshal(yateed)
    28  	if err != nil {
    29  		return "", errors.Wrap(err, "failed to execute yatee template")
    30  	}
    31  	return strings.Replace(string(m), "$", "$$", -1), nil
    32  }