Skip to content

Commit

Permalink
refactor(render): Move generate_content into render
Browse files Browse the repository at this point in the history
  • Loading branch information
mrwilson committed Oct 8, 2023
1 parent 63fb0f6 commit 754d808
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 16 deletions.
17 changes: 1 addition & 16 deletions adr_viewer/__init__.py
Original file line number Diff line number Diff line change
@@ -1,27 +1,12 @@
import os
from typing import List

from click import option, command

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


def generate_content(adrs: List[Adr], template_dir_override=None, title=None) -> str:
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.records.append(adr)

return render_html(config, template_dir_override)


# fmt: off
@command()
@option('--adr-path', default='doc/adr/', help='Directory containing ADR files.', show_default=True)
Expand Down
15 changes: 15 additions & 0 deletions adr_viewer/render.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import os
from dataclasses import dataclass
from typing import List

Expand Down Expand Up @@ -30,3 +31,17 @@ def render_html(config: AdrTemplateConfig, template_dir_override=None) -> str:
template = env.get_template("index.html")

return template.render(config=config)


def generate_content(adrs: List[Adr], template_dir_override=None, title=None) -> str:
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.records.append(adr)

return render_html(config, template_dir_override)

0 comments on commit 754d808

Please sign in to comment.