tekwizely / bash-tpl Goto Github PK
View Code? Open in Web Editor NEWA smart, lightweight shell script templating engine, written in Bash
License: MIT License
A smart, lightweight shell script templating engine, written in Bash
License: MIT License
Hi, nice work
Would it be possible to pass a format string to printf? Here's an example without
.DELIMS stmt-block="<% %>" tag="{{ }}"
<%
ENV_VARIABLE="$(printf "%17s" "$ENV_VARIABLE")"
name1="$(printf "%-13s" "$1")"
name2="$(printf "%-13s" "$2")"
%>
+---------------+---------+-------------------+
| | | |
+---------------+---------+-------------------+
| {{ $name1 }} | ....... | {{$ENV_VARIABLE}} |
| {{ $name2 }} | ....... | {{$ENV_VARIABLE}} |
+---------------+---------+-------------------+
and with,
.DELIMS tag="{{ }}"
+------------------+---------+-------------------+
| | | |
+------------------+---------+-------------------+
| {{%-13s $1 }} | ....... | {{%17s $ENV_VARIABLE}} |
| {{%-13s $2 }} | ....... | {{%17s $ENV_VARIABLE}} |
+---------------+---------+-------------------+
You can add Adrian's tool pp to similar tools section.
description of pp:
pp
a preprocessor
pp allows embedding sh code in files of any type by nesting it inside the #!\n token, where \n is a new line. That means that if you'd like a simple loop or an if inside an HTML file for instance, you could use pp.
Hello,
I'm using your project inside mine.
It is a kind of bash compiler (it aggregates several files together in order to generate a unique bash file).
bash-tpl is in the heart of this compiler, so this message is just to say thank you for your work.
I added a reference to your project here
https://github.com/fchastanet/bash-tools-framework#4-acknowledgements
kind regards,
François Chastanet
First, thanks for the great work on bash-tpl
-- I've been using it to great effect when making some new static sites.
I ran across an issue recently -- it appears that .INCLUDE
cannot be used with a variable to render another .tpl
file dynamically (eg., .INCLUDE $1
).
Bash version:
GNU bash, version 3.2.57(1)-release (arm64-apple-darwin22)
Repro steps:
printf '<div class="container">\n .INCLUDE $1\n</div>\n' > layout.tpl
Which produces:
<div class="container">
.INCLUDE $1
</div>
echo '<span>Subcontent should be displayed</span>' > partial.tpl
Which produces:
<span>Subcontent should be displayed</span>
bash-tpl
bash-tpl layout.tpl partial.tpl
This produces the following:
printf "%s\n" \<div\ class=\"container\"\>
printf "%s\n" \ \ \</div\>
I expected this output:
printf "%s\n" \<div\ class=\"container\"\>
printf "%s\n" \ \ Subcontent\ should\ be\ displayed
printf "%s\n" \</div\>
I would expect that the argument $1
could be used in the .INCLUDE
directive to dynamically pass in the .tpl
file that should be rendered. I also could be missing something straightforward here, in which case any insight would be appreciated.
If this is not currently a feature, having this ability in bash-tpl
would be great.
Originally posted by flaix November 10, 2021
I noticed that bash-tpl
requires a Bash version 5.1 or higher. That might be worth pointing out in the Readme. Or even a runtime check and warning?
It looks like a really nice tool and people interested in it might stumble over the fact that their machine uses an older version of Bash. One example is macOS, which uses a really old v3 Bash (and will never update). But I also tried it on a Ubuntu based Docker container that wouldn't run bash-tpl
either, as it comes with a Bash 4.4.
hi, thanks for a great project
i'm trying to use .INCLUDE inside a statement block but can't quite figure it out. is it supported?
% if [[ -f "$BUILD_SRC/Dockerfile" ]]; then
.INCLUDE "$BUILD_SRC/Dockerfile"
% fi
if the file "$BUILD_SRC/Dockerfile"
does not exist then the .INCLUDE statement is ignored BUT bash-tpl STILL seems to want to check that the .INCLUDE file exists thus throwing an error. This is unexpected.
File not found: '/data/Hacking/computing/docker/uci-docker-nextcloud/src/Dockerfile'
/dev/fd/63: line 142: syntax error near unexpected token `fi'
/dev/fd/63: line 142: `fi'
if "$BUILD_SRC/Dockerfile"
exists it all works as expected.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.