Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add --trim-blocks and --lstrip-blocks #126

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

kenji-miyake-ai
Copy link
Contributor

It's helpful if we can use trim_blocks and lstrip_blocks rendering options.

Explaining with a sample in https://ttl255.com/jinja2-tutorial-part-3-whitespace-control/.

sample.jinja2:

{% for iname, idata in interfaces.items() %}
interface {{ iname }}
 description {{ idata.description }}
  {% if idata.ipv4_address is defined %}
 ip address {{ idata.ipv4_address }}
  {% endif %}
{% endfor %}

input.yaml:

interfaces:
  Ethernet1:
    description: capture-port
  Ethernet2:
    description: leaf01-eth51
    ipv4_address: 10.50.0.0/31
  • No option
$ jinja2 sample.jinja2 input.yaml

interface Ethernet1
 description capture-port


interface Ethernet2
 description leaf01-eth51

 ip address 10.50.0.0/31


  • Only --trim-blocks
jinja2 sample.jinja2 input.yaml --trim-blocks
interface Ethernet1
 description capture-port
  interface Ethernet2
 description leaf01-eth51
   ip address 10.50.0.0/31
  • Both --trim-blocks and --lstrip-blocks
$ jinja2 sample.jinja2 input.yaml --trim-blocks --lstrip-blocks
interface Ethernet1
 description capture-port
interface Ethernet2
 description leaf01-eth51
 ip address 10.50.0.0/31

Signed-off-by: Kenji Miyake <kmiyake@applied.co>
@kenji-miyake-ai
Copy link
Contributor Author

@mattrobenolt Could you also review this? 🙇

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant