Git Product home page Git Product 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

Watchers

 avatar  avatar  avatar

bash-tpl's Issues

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

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

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.

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.

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.

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.