defunkt / pystache

Mustache in Python
http://mustache.github.com/
MIT License
1.31k stars 308 forks source link

pystache command always treats template argument as string #183

Open RealSalmon opened 8 years ago

RealSalmon commented 8 years ago

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

dhylbert commented 8 years ago

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

RealSalmon commented 8 years ago

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.

daveloyall commented 5 years ago

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!