Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adding utility methods to Model #89

Open
robert-schmidtke opened this issue May 30, 2016 · 2 comments
Open

Adding utility methods to Model #89

robert-schmidtke opened this issue May 30, 2016 · 2 comments

Comments

@robert-schmidtke
Copy link

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.

@aalexandrov
Copy link
Member

Do you have a WIP branch for that? I might be able to suggest something better if I can play around with the code.

@robert-schmidtke
Copy link
Author

My code is currently part of a private project, I'll see if I can extract it and set it up as a fork of Peel instead.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants