pystache icon indicating copy to clipboard operation
pystache copied to clipboard

pystache command always treats template argument as string

Open RealSalmon opened this issue 10 years ago • 3 comments

The command line version of pystache always treats the template argument as a string. Based on the documentation, it should recognize a file if one exists, which is how the context argument currently works.

echo "Hello {{world}}" > template
echo '{"world": "everybody"}' > context

# expecting "Hello everybody" but the actual result is "template"
pystache template context

https://github.com/defunkt/pystache/blob/17a5dfdcd56eb76af731d141de395a7632a905b8/pystache/commands/render.py#L72

RealSalmon avatar Feb 12 '16 23:02 RealSalmon

It seems like unless the template input ends in .mustache it won't try to consider it as a filename.

dhylbert avatar Oct 01 '16 00:10 dhylbert

Actually it seems like it work as advertised for me now (pystache==0.5.4). . . even with my own test case posted above. I'm not sure why I was seeing this before . . .

Edit . . . nevermind. You are correct. I had a .mustache template hanging around which is why I thought my original test case was working.

pystache template context will automatically look for 'template.mustache' and use that if found.

RealSalmon avatar Oct 01 '16 14:10 RealSalmon

Three years after this was originally reported, I had to dig through source code and issues to find out that it expects filenames ending with the magic string .mustache.

I recommend adding --context-file, --context-string, --template-file, and --template-string.

This leaves alone the behavior of the overloaded positional arguments, in case some users depend on that behavior.

Update: now that I've got pystache3 working, I just want you to know that I find it quite useful. Thanks!

daveloyall avatar May 01 '19 20:05 daveloyall