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

ENH: support int32 and float32 #15

Closed
brentp opened this issue Jun 9, 2021 · 2 comments
Closed

ENH: support int32 and float32 #15

brentp opened this issue Jun 9, 2021 · 2 comments
Assignees
Labels
enhancement New feature or request

Comments

@brentp
Copy link

brentp commented Jun 9, 2021

Hi, I am attempting to add seq[int32] and seq[float32] to a context.
I have made this work by doing this:

import mustache
import mustachepkg/values

proc castValue*(values:seq[float32]): Value =
  var vs: seq[Value]
  for v in values:
    vs.add(v.float.castValue)
  Value(kind: vkSeq, vSeq: vs)
  
var ctx = newContext()
ctx["a"] = @[23'f32, 33'f32]

but it would be nice if this were supported in the library.
thanks for the nice package.

@soasme soasme added the enhancement New feature or request label Jun 10, 2021
@soasme soasme self-assigned this Jun 10, 2021
@soasme
Copy link
Owner

soasme commented Jun 10, 2021

@brentp I have released this feature in nim-mustache v0.4.2. Please upgrade your project dependency.

Example:

# File: issue_15.nim

import mustache

let ctx = newContext()
ctx["f32seq"] = @[0'f32, 1'f32]

let s = """
{{# f32seq }}
{{ . }}
{{/ f32seq }}

{{ f32seq }}
"""

echo(s.render(ctx))

Output:

0.0
1.0

[0.0,1.0]

@brentp
Copy link
Author

brentp commented Jun 10, 2021

thank you! (and see my comment in the commit)

@brentp brentp closed this as completed Jun 10, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants