Giter VIP home page Giter VIP logo

bash-tpl's People

Contributors

tekwizely 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

Watchers

 avatar  avatar  avatar

bash-tpl's Issues

a conditional .INCLUDE throws error when file does not exist

% 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.

bash-tpl requires Bash >= 5.1

Discussed in #5

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.

Feature request: pass format to printf

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}} |
+---------------+---------+-------------------+

Generated dollar-quote escape sequences are Bash-specific (in practice)

For the code

RUN apt-get update && \
	apt-get -y install --no-install-recommends

… Bash-TPL generates:

printf "%s\n" RUN\ apt-get\ update\ \&\&\ \\
printf "%s\n" $'\tapt-get -y install --no-install-recommends'

Which prints

RUN apt-get update && \
$\tapt-get -y install --no-install-recommends

…when run with Dash.

As the readme says, the generated scripts are not supposed to use Bashisms.

The shell scripts that Bash-TPL generates are not intended to be Bash-specific.

The feature in question is, as far as I can tell, part of POSIX 2024, but it’ll be a while until support for it is added to all shells.
Dash has committed a patch that adds it just a few hours ago.

I’m not sure whether it’s worth fixing it, but I guess this behavior should be at least documented here on the bug tracker.

Namespace the functions and change name of main to bash-tpl or btpl

I have need to source bash-tpl and then run it later via its function main. But to do that without a namespace issue bash-tpl would have to adopt a namespace prefix and main would need to be renamed to btpl or bash-tpl

i.e.

function btpl() {

(return 0 2> /dev/null) || btpl "$@"

and then for all functions and their calls

btpl_somefunctionname

all this would not affect directly executing the script

This would allow bash-tpl to play nice with other sourced code that may already be in a shell session.

as it is when I install the script I have to use sed to make those change those.

sed -i 's/\bmain\b/btpl/g'

using sed to prefix all the functions is a bit harder (at least where they are called)

Allow variable with `.tpl` file path as argument to `.INCLUDE` directive

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:

  1. Create a top-level "layout" file.
printf '<div class="container">\n  .INCLUDE $1\n</div>\n' > layout.tpl

Which produces:

<div class="container">
  .INCLUDE $1
</div>
  1. Create a "partial" view file with some content
echo '<span>Subcontent should be displayed</span>' > partial.tpl

Which produces:

<span>Subcontent should be displayed</span>
  1. Call 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.

Add pp to similar tools

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.

https://adi.onl/pp.html

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.