Skip to content

Adding utility methods to Model #89

@robert-schmidtke

Description

@robert-schmidtke

I have come across the issue that I'd like to be able to call some utility functions from a Mustache template. The situation is as follows: I have one template that needs to be rendered once for each slave, and each slave needs a unique ID. Because there can be many slaves, I don't want to provide sufficiently many templates, but rather have one template and render it multiple times with different input. I have worked around the issue for now myself by extending Model.Yaml and adding a custom property:

class YamlWithRandom(c: Config, prefix: String) extends Model.Yaml(c, prefix) {
  {
    put("random", Random)
  }
}

and my Mustache template then looks as follows:

uuid = xtreemfs-dir-{{random.nextLong}}

This works for now, but feels a little 'hacky' and I'd like to have it more natively integrated into Peel. Now I'm not too familiar with Scala yet, so maybe there's something clever that could be done with mixins to the existing models. I couldn't figure it out in a finite amount of time however, which is why I resorted to creating my own model.

If you have any hints how to do this more properly, I greatly appreciate any tips!

Thanks.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions