Giter Club home page Giter Club logo

mustache.sh's Introduction

mustache.sh

Mustache in POSIX shell.

There's (as of this writing) only one call to a non-builtin which is probably enough to claim this is fast enough for most uses.

mustache.sh requires GNU sed(1).

Installation

make && sudo make install

Usage

From the command-line:

FOO="foo" BAR="bar" mustache.sh <"tests/test.mustache"

As a library:

. "lib/mustache.sh"
FOO="foo" BAR="bar"
mustache <"tests/test.mustache"

Spec

Deviations from spec

  • mustache.sh accepts input data via the environment, not via YAML frontmatter. This makes sense for shell programmers but may render this Mustache implementation unsuitable for other use.
  • mustache.sh does not descend into a new scope within {{#tag}} or {{^tag}} sections. This again makes sense when being driven by environment variables.
  • mustache.sh doesn't support the --compile or --tokens command-line options and does not accept input file(s) as arguments.
  • mustache.sh doesn't care about escaping output as HTML.
  • mustache.sh will execute tag names surrounded by backticks as shell commands.
  • mustache.sh doesn't support list sections in the traditional sense: it requires the section tag be a shell command and processes the section once for each line on standard output with the line available in _M_LINE.

TODO

  • Lambdas. What is this I don't even.
  • Partials. This is related to supporting shell commands as variables.
  • Set delimeter. This would be very hard to support in general because of the pervasive assumption that tag delimeters are two characters long.

TODONE

  • Variable tags.
  • Section tags.
  • Inverted section tags.
  • Comment tags.
  • Nested sections. Recursion, motherfucker. Do you speak it?
  • List sections. The section tag must be a shell command. The section is processed once for each line on standard output with the line available in _M_LINE.

License

mustache.sh is BSD-licensed.

mustache.sh's People

Contributors

malk avatar rcrowley avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar

mustache.sh's Issues

Comments

Hi,

I have an SQL query computed by pystach on a python3 app.

The is comments on this sql query (not SQL commentn, but pystache comments))

{{ ! my wonderful comment }}

When I use mustache.sh, mustache.sh < query.sql my comment is

$ ! my wonderful comment

Another Encoding problem

per my last patch mustache.sh should be Encoding agnostic, alas:

the newline-detection trickery done with sed do fail when there is a non-unicode accent just before the newline:

supposing, for example, iso-8859-1

echo 'A=é
b=c' | mustache

gives us

A=éb=c

Encoding problems

Hello there,

awesome to see that mustache.sh exists

While using it as a library in an UTF-8 system (vanilla debian Wheezy)
it has the strange tendency of borking characters

as in

echo "télétransmettre" | mustache
# => tltransmettre

So, initially I assumed that mustache.sh, just has a "favourite" encoding
I searched the github page and found no information on the subject

So I tried

echo "télétransmettre" | mustache > /tmp/what-is-mustache.sh-encoding
file -bi /tmp/what-is-mustache.sh-encoding 
# => text/plain; charset=iso-8859-1

and supposed it was iso-8859-1, but no such luck

echo "télétransmettre" | iconv -f utf-8 -t iso-8859-1 | mustache | iconv -f iso-8859-1 -t utf-8
# => tééransmettre

So I tried "brute-guessing" what would be mustache.sh's encoding

iconv --list | while read ENCODING
do
    echo $ENCODING
    echo "télétransmettre" | iconv -f utf-8 -t $ENCODING | mustache | iconv -f $ENCODING -t utf-8
done 

which gave-me surprisingly UTF7 as a working encoding for mustache!? (I did not even know that UTF7 exist at all)

echo "télétransmettre" | iconv -f UTF7 -t iso-8859-1 | mustache | iconv -f iso-8859-1 -t UTF7
# => "télétransmettre"

While this works on Debian, my production machine (AIX) has no UTF7 support, so currently I am more inclined to seek an alternative (mustache.pl probably)

So this issue is for 3 purposes

  1. Can mustache.sh please support UTF8?
  2. Failing that Can you at least confirm if my guess of UTF7 is correct or just dumb luck?
  3. Can you please at least put on the project page a note stating that mustache.sh is encoding dependent and stating the encoding?

Have a nice day!

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.