Skip to content

Commit

Permalink
fix(render): Reverse Mermaid feature detection so it gets picked up
Browse files Browse the repository at this point in the history
We were previously assigning the global variable to the local record, rather than accumulating the local record into the global variable.

This change also adds tests to capture this failure in future.
  • Loading branch information
mrwilson committed Jul 7, 2024
1 parent eecf3b8 commit e5638c6
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 5 deletions.
7 changes: 6 additions & 1 deletion adr_viewer/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,12 @@
from click import option, command

from adr_viewer.parse import parse_adr, parse_adr_files, Adr
from adr_viewer.render import render_html, AdrTemplateConfig, generate_content
from adr_viewer.render import (
generate_configuration,
render_html,
AdrTemplateConfig,
generate_content,
)
from adr_viewer.server import run_server


Expand Down
10 changes: 7 additions & 3 deletions adr_viewer/render.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,15 +33,19 @@ def render_html(config: AdrTemplateConfig, template_dir_override=None) -> str:
return template.render(config=config)


def generate_content(adrs: List[Adr], template_dir_override=None, title=None) -> str:
def generate_configuration(adrs: List[Adr], title=None):
config = AdrTemplateConfig(
project_title=title if title else os.path.basename(os.getcwd()), records=[]
)

for index, adr in enumerate(adrs):
adr.index = index
adr.includes_mermaid |= config.include_mermaid
config.include_mermaid |= adr.includes_mermaid

config.records.append(adr)

return render_html(config, template_dir_override)
return config


def generate_content(adrs: List[Adr], template_dir_override=None, title=None) -> str:
return render_html(generate_configuration(adrs, title), template_dir_override)
19 changes: 18 additions & 1 deletion adr_viewer/test_render.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from adr_viewer import render_html, AdrTemplateConfig
from adr_viewer import generate_configuration, render_html, AdrTemplateConfig
from adr_viewer.parse import Adr


Expand Down Expand Up @@ -46,3 +46,20 @@ def test_should_render_html_without_mermaid():
)

assert "mermaid.min.js" not in html


def test_should_add_mermaid_dependency_to_overall_render():
adr = Adr("Record 123", "status", "content")
adr.includes_mermaid = True

config = generate_configuration(adrs=[adr], title="title")

assert config.include_mermaid


def test_should_not_add_mermaid_dependency_to_overall_render_if_not_needed():
adr = Adr("Record 123", "status", "content")

config = generate_configuration(adrs=[adr], title="title")

assert not config.include_mermaid

0 comments on commit e5638c6

Please sign in to comment.