Skip to content

Commit

Permalink
Version 0.8.0 - Line ending change
Browse files Browse the repository at this point in the history
## Changed

- `FileRenderer` (and thus `DirectoryRenderer`) now use `\n` line endings in the
  resulting file. This should probably just be an option with the default being
  to preserve the line ending format of the template file, but since this is
  being used to render files that should run on Linux and apparently incorrect
  line endings mess up the shebang reading and sh*t like that so I'm applying
  this "sh*t fix" for now.
  • Loading branch information
CCP-Zeulix committed Jun 4, 2024
1 parent 2ee878b commit 00e961f
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 4 deletions.
11 changes: 11 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,17 @@ All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## [0.8.0] - 2024-06-04

## Changed

- `FileRenderer` (and thus `DirectoryRenderer`) now use `\n` line endings in the
resulting file. This should probably just be an option with the default being
to preserve the line ending format of the template file, but since this is
being used to render files that should run on Linux and apparently incorrect
line endings mess up the shebang reading and sh*t like that so I'm applying
this "sh*t fix" for now.

## [0.7.0] - 2024-05-30

## Added
Expand Down
2 changes: 1 addition & 1 deletion _sandbox_string.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ def main():

# rnd = stencils.StringRenderer(ctx, tpl)
# rnd = stencils.StdOutRenderer(ctx, tpl)
rnd = stencils.FileRenderer('./build/something/', ctx, tpl, overwrite=True)
rnd = stencils.FileRenderer('./build/something2/', ctx, tpl, overwrite=True)
print(rnd.render())


Expand Down
4 changes: 3 additions & 1 deletion _sandbox_template.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
{% setfilename %}
{{colors.favorite}}_file.txt
{% endsetfilename %}
My name is {{name}} and I am {{age}} years old and my favorite color is NOT {{colors.weakness}}
My name is {{name}} and
I am {{age}} years old and my
favorite color is NOT {{colors.weakness}}
2 changes: 1 addition & 1 deletion ccpstencil/__init__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
__version__ = '0.7.0'
__version__ = '0.8.0'

__author__ = 'Thordur Matthiasson <[email protected]>'
__license__ = 'MIT License'
Expand Down
4 changes: 3 additions & 1 deletion ccpstencil/renderer/_file.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,10 @@ class FileRenderer(StringRenderer):
def __init__(self, output_path: Union[str, Path],
context: Optional[IContext] = None, template: Optional[ITemplate] = None,
overwrite: bool = True,
new_line_char: str = '\n',
**kwargs):
self._overwrite = overwrite
self._new_line_char = new_line_char
super().__init__(context, template, **kwargs)
is_dir = False
log.debug(f'{output_path=}')
Expand Down Expand Up @@ -46,7 +48,7 @@ def _output_rendered_results(self, rendered_string: str) -> str:
f' disabled: {fout_path.absolute()}')
fout_path.parent.mkdir(parents=True, exist_ok=True)

with open(fout_path, 'w') as fout:
with open(fout_path, 'w', newline=self._new_line_char) as fout:
fout.write(results)
return str(fout_path.absolute())

Expand Down

0 comments on commit 00e961f

Please sign in to comment.