mustache / mustache.github.com

The {{official}} website
http://mustache.github.io/
Other
2.29k stars 292 forks source link

multi-line yaml input to mustache template outputs as JSON #116

Closed sbutt closed 8 months ago

sbutt commented 5 years ago

I posted this question on stack exchange...

https://stackoverflow.com/questions/53829832/multi-line-yaml-input-to-mustache-template-outputs-as-json

However, it looks like a bug to me after reading the manual and trawling google searches all morning.

I stripped the code down even further, since I posted that example to really try to minimise.

inputs="ingress_test_inputs.yaml"
auth_annotations="
    foo: bar baz
    sam: jam man"
echo "namespace: qa" > $inputs
echo "auth_annotations: ${auth_annotations}" >> $inputs

echo "----- Ingress inputs (${inputs}) -----"
cat $inputs

echo '---
metadata:
  annotations:
    nginx/thing:
      another_thing:
      {{{auth_annotations}}}
spec:
  rules:
    - host: bla-bla-bla.{{{ namespace }}}.example.com' >ingress.mustache

echo "----- Raw Ingress (ingress.mustache): -----"
cat ingress.mustache

mustache $inputs ingress.mustache > ingress-1.0.yaml

echo "----- Will apply the following ingress: -----"
cat ingress-1.0.yaml

Here's the output I get from the above...

----- Ingress inputs (ingress_test_inputs.yaml) -----
namespace: qa
auth_annotations:
    foo: bar baz
    sam: jam man
----- Raw Ingress (ingress.mustache): -----
---
metadata:
  annotations:
    nginx/thing:
      another_thing:
      {{{auth_annotations}}}
spec:
  rules:
    - host: bla-bla-bla.{{{ namespace }}}.example.com
----- Will apply the following ingress: -----
---
metadata:
  annotations:
    nginx/thing:
      another_thing:
      {"foo"=>"bar baz", "sam"=>"jam man"}
spec:
  rules:
    - host: bla-bla-bla.qa.example.com

and I really don't understand why the line after "another_thing" is rendered as JSON instead of YAML.

I'm using mustashe v1.1.0 on Ubuntu 18.04.

Thanks!

sbutt commented 5 years ago

Here's the output of mustache -t

----- Will apply the following ingress: -----
[:multi,
 [:static,
  "namespace: qa\n" +
  "auth_annotations: \n" +
  "    foo: bar baz\n" +
  "    sam: jam man\n"]]

and mustache -c ...

----- Will apply the following ingress: -----
"namespace: qa\nauth_annotations: \n    foo: bar baz\n    sam: jam man\n"
sbutt commented 5 years ago

Correction: It's NOT YAML, it's actually a Ruby Hash. Still a bug though, IMO.

jgonggrijp commented 8 months ago

Closing this, because this repository is only about the Mustache website. https://github.com/mustache/mustache/issues/248 is the correct location for your issue.