Skip to content

Commit 623be55

Browse files
committed
fix: clean up Jinja templates for better readability
1 parent 650a2dd commit 623be55

File tree

1 file changed

+15
-22
lines changed

1 file changed

+15
-22
lines changed

src/gitingest/output_formatter.py

Lines changed: 15 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -212,39 +212,32 @@ def _(self, node: FileSystemFile, query):
212212
{{ SEPARATOR }}
213213
{{ node.name }}
214214
{{ SEPARATOR }}
215-
216215
{{ node.content }}
217216
"""
218217
file_template = self.env.from_string(template)
219218
return file_template.render(SEPARATOR=SEPARATOR, node=node, query=query, formatter=self)
220219

221220
@format.register
222221
def _(self, node: FileSystemDirectory, query):
223-
template = """
224-
{% if node.depth == 0 %}
225-
{{ node.name }}:
222+
template = """{%- if node.depth == 0 %}{{ node.name }}:
226223
{{ node.tree }}
227224
228-
{% endif %}
229-
{% for child in node.children %}
225+
{% endif -%}
226+
{%- for child in node.children -%}
230227
{{ formatter.format(child, query) }}
231-
{% endfor %}
232-
"""
228+
{%- endfor -%}"""
233229
dir_template = self.env.from_string(template)
234230
return dir_template.render(node=node, query=query, formatter=self)
235231

236232
@format.register
237233
def _(self, node: GitRepository, query):
238-
template = """
239-
{% if node.depth == 0 %}
240-
🔗 Git Repository: {{ node.name }}
234+
template = """{%- if node.depth == 0 %}🔗 Git Repository: {{ node.name }}
241235
{{ node.tree }}
242236
243-
{% endif %}
244-
{% for child in node.children %}
237+
{% endif -%}
238+
{%- for child in node.children -%}
245239
{{ formatter.format(child, query) }}
246-
{% endfor %}
247-
"""
240+
{%- endfor -%}"""
248241
git_template = self.env.from_string(template)
249242
return git_template.render(node=node, query=query, formatter=self)
250243

@@ -261,18 +254,18 @@ def _(self, node: FileSystemSymlink, query):
261254
@format.register
262255
def _(self, context: Context, query):
263256
"""Format a Context by formatting all its sources."""
264-
template = """
265-
# Generated using https://gitingest.com/{{ context.query.user_name }}/{{ context.query.repo_name }}
257+
template = \
258+
"""# Generated using https://gitingest.com/{{ context.query.user_name }}/{{ context.query.repo_name }}
259+
266260
Sources used:
267-
{% for source in context.sources %}
261+
{%- for source in context.sources %}
268262
- {{ source.name }}: {{ source.__class__.__name__ }}
269263
{% endfor %}
270264
271-
{% for source in context.sources %}
265+
{%- for source in context.sources %}
272266
{{ formatter.format(source, context.query) }}
273-
{% endfor %}
274-
# End of generated content
275-
"""
267+
{%- endfor %}
268+
# End of generated content"""
276269
context_template = self.env.from_string(template)
277270
return context_template.render(context=context, formatter=self)
278271

0 commit comments

Comments
 (0)