From 4712e4b09e015416668a53b1fae3b5b15d25533b Mon Sep 17 00:00:00 2001 From: Chris Penner Date: Sat, 29 Apr 2017 16:53:01 -0600 Subject: [PATCH] Add python-script example --- README.md | 44 +++++++++++++++++++++++++++++++++++++++++ examples/favourites.py | 5 +++++ examples/use-scripts.md | 9 +++++++++ 3 files changed, 58 insertions(+) create mode 100644 examples/favourites.py create mode 100644 examples/use-scripts.md diff --git a/README.md b/README.md index 57f0782..c1d5af7 100644 --- a/README.md +++ b/README.md @@ -82,6 +82,10 @@ $ ./test.txt interpolate that ``` +Shell not powerful enough for you? No problem! Use all your favourite languages and +tools; See the FAQ or examples to see how to integrate with scripts (spoilers, just call them like you do in bash!) + + [**Examples Here**](https://github.com/ChrisPenner/tempered/tree/master/examples) Installation @@ -150,6 +154,46 @@ done }} 97 bottles of beer on the wall ``` +### Other Scripts/Tools? + +Duh! Interpolation works like a shell, just call the scripts or binaries you want! +Here we'll use a simple python script to spice things up! + +```python +# favourites.py +import sys + +print(" and ".join(sys.argv[1:]) + ",") +print("These are a few of my favourite things") +``` + +``` +# My Favourite Things + +{{ python favourites.py Gumdrops Roses Whiskers Kittens }} + +When the dog bites +When the bee stings +When I'm feeling sad +I simply remember my favourite things +And then I don't feel so bad +``` + +Output: + +``` +# My Favourite Things + +Gumdrops and Roses and Whiskers and Kittens, +These are a few of my favourite things + +When the dog bites +When the bee stings +When I'm feeling sad +I simply remember my favourite things +And then I don't feel so bad +``` + ### \_\_: command not found? Chances are you're forgetting to echo an env-var; diff --git a/examples/favourites.py b/examples/favourites.py new file mode 100644 index 0000000..373e2a9 --- /dev/null +++ b/examples/favourites.py @@ -0,0 +1,5 @@ +# You can write scripts in any language you like to level up your templates! +import sys + +print(" and ".join(sys.argv[1:]) + ",") +print("These are a few of my favourite things") diff --git a/examples/use-scripts.md b/examples/use-scripts.md new file mode 100644 index 0000000..6853114 --- /dev/null +++ b/examples/use-scripts.md @@ -0,0 +1,9 @@ +# My Favourite Things + +{{ python favourites.py Gumdrops Roses Whiskers Kittens }} + +When the dog bites +When the bee stings +When I'm feeling sad +I simply remember my favourite things +And then I don't feel so bad