Skip to content

Commit

Permalink
Add combine_levels filter
Browse files Browse the repository at this point in the history
  • Loading branch information
jcmiller11 committed Aug 7, 2023
1 parent ad81135 commit 302aa8a
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 2 deletions.
23 changes: 23 additions & 0 deletions psbs/extensions/filters.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ class Filters(Extension):
def __init__(self, config):
super().__init__(config)
self.register_filter("wrap", self.wrap_to_width)
self.register_filter("combine_levels", self.combine_levels)

def wrap_to_width(self, input_text, width=5):
output = ""
Expand All @@ -13,3 +14,25 @@ def wrap_to_width(self, input_text, width=5):
[line[i : i + width] for i in range(0, len(line), width)]
)
return output

def combine_levels(self, levels_list, columns = 0):
if columns == 0:
columns = len(levels_list)
rows = (levels_list[pos:pos + columns] for pos in range(0, len(levels_list), columns))
def combine_row(list):
level_lines = []
for level_number, level in enumerate(list):
level = level.strip()
for line_number, line in enumerate(level.splitlines()):
line = line.strip()
if len(level_lines) <= line_number:
level_lines.append(line)
else:
level_lines[line_number] += line
return level_lines
output = ""
for row in rows:
for line in combine_row(row):
output += line
output += "\n"
return output.strip()
1 change: 1 addition & 0 deletions psbs/template.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ def __init__(self, filename, config):
variable_end_string="))",
comment_start_string="(#",
comment_end_string="#)",
extensions=['jinja2.ext.do'],
)
self.postprocessing_steps = []
extensions = Extension.get_extensions()
Expand Down
4 changes: 2 additions & 2 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,15 @@

setup(
name='psbs',
version='0.2.2',
version='0.2.3',
python_requires='>=3.8',
description='PuzzleScript Build System',
long_description=long_description,
long_description_content_type='text/markdown',
author='J.C. Miller',
author_email='[email protected]',
url='https://github.com/jcmiller11/PSBS',
download_url = 'https://github.com/jcmiller11/PSBS/archive/refs/tags/0.2.2.tar.gz',
download_url = 'https://github.com/jcmiller11/PSBS/archive/refs/tags/0.2.3.tar.gz',
license='MIT',
packages=find_packages(),
package_data={'': ['example.txt']},
Expand Down

0 comments on commit 302aa8a

Please sign in to comment.