Skip to content

Commit

Permalink
fix blocks stripping on non-changing lines
Browse files Browse the repository at this point in the history
  • Loading branch information
gi0baro committed Mar 15, 2022
1 parent 6b08e4d commit 9a83904
Show file tree
Hide file tree
Showing 5 changed files with 31 additions and 2 deletions.
5 changes: 3 additions & 2 deletions renoir/parsing/contents.py
Original file line number Diff line number Diff line change
Expand Up @@ -117,9 +117,10 @@ def __init__(self, parent: Element):
text=line,
indent=0,
original_indent=0,
ignore_reindent=False
ignore_reindent=False,
offset=idx
)
for line in self.parent.text.split('\n')
for idx, line in enumerate(self.parent.text.split('\n'))
]

@property
Expand Down
8 changes: 8 additions & 0 deletions renoir/parsing/parsers.py
Original file line number Diff line number Diff line change
Expand Up @@ -225,14 +225,22 @@ class IndentTemplateParser(TemplateParser):
re_wspace = re.compile("^( *)")

def parse_plain_block(self, ctx, element):
current_line, new_line = ctx.state.lines.end, False
lines_element = element.split()
ctx.update_lines_count(lines_element.linesn)
if ctx.state.lines.start != current_line:
new_line = True
for line in lines_element.lines:
if line.offset:
new_line = True
if not new_line:
continue
indent = len(self.re_wspace.search(line.text).group(0))
ctx.state.indent = indent
ctx.state.offset = len(line.text) - indent
line.text = line.text[indent:]
line.indent = ctx.state.indent
new_line = False
ctx._plain(WrappedNode, lines_element)


Expand Down
10 changes: 10 additions & 0 deletions tests/test_render.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,11 @@ def templater_html_indent():
- foo
- 1
- 1.2
- bar: foo bar
- bar2: foo foo2 bar
- bar3: foo foo2 bar bar2
- bar3: foo foo2 barbar2
- bar4: foo foo2 barbar2 bar3
"""


Expand All @@ -96,6 +101,11 @@ def test_plain(templater):
- foo
- foo: bar
array: []
- bar: foo bar
- bar2: foo foo2 bar
- bar3: foo foo2 bar bar2
- bar3: foo foo2 barbar2
- bar4: foo foo2 barbar2 bar3
inclusion:
- inclusion_key: inclusion_val
inclusion_nest:
Expand Down
5 changes: 5 additions & 0 deletions tests/yaml/basic.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -17,3 +17,8 @@ obj:
- foo
- {{ =1 }}
- {{ =2.4 / 2 }}
- bar: {{ ="foo" }} bar
- bar2: {{ ="foo" }} foo2 {{ ="bar" }}
- bar3: {{ ="foo" }} foo2 {{ ="bar" }} bar2
- bar3: {{ ="foo" }} foo2 {{ ="bar" }}{{ ="bar2" }}
- bar4: {{ ="foo" }} foo2 {{ ="bar" }}{{ ="bar2" }} bar3
5 changes: 5 additions & 0 deletions tests/yaml/blocks.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,9 @@ obj:
- foo
- foo: bar
array: {{ block array }}[]{{ end }}
- bar: {{ ="foo" }} bar
- bar2: {{ ="foo" }} foo2 {{ ="bar" }}
- bar3: {{ ="foo" }} foo2 {{ ="bar" }} bar2
- bar3: {{ ="foo" }} foo2 {{ ="bar" }}{{ ="bar2" }}
- bar4: {{ ="foo" }} foo2 {{ ="bar" }}{{ ="bar2" }} bar3
{{ include }}

0 comments on commit 9a83904

Please sign in to comment.