StrictDoc Documentation
strictdoc/features/project_statistics/view_object.py
Source file coverage
Path:
strictdoc/features/project_statistics/view_object.py
Lines:
59
Non-empty lines:
48
Non-empty lines covered with requirements:
48 / 48 (100.0%)
Functions:
6
Functions covered by requirements:
6 / 6 (100.0%)
1
"""
2
View Object class that bridges between project metrics data and the Project
3
Statistics screen Jinja templates.
4
 
5
@relation(SDOC-SRS-97, scope=file)
6
"""
7
 
8
from dataclasses import dataclass
9
from typing import List, Union
10
 
11
from markupsafe import Markup
12
 
13
from strictdoc import __version__
14
from strictdoc.core.document_tree import DocumentTree
15
from strictdoc.core.document_tree_iterator import DocumentTreeIterator
16
from strictdoc.core.project_config import ProjectConfig
17
from strictdoc.core.traceability_index import TraceabilityIndex
18
from strictdoc.export.html.html_templates import JinjaEnvironment
19
from strictdoc.export.html.renderers.link_renderer import LinkRenderer
20
from strictdoc.features.project_statistics.metric import Metric, MetricSection
21
from strictdoc.helpers.cast import assert_cast
22
 
23
 
24
@dataclass
25
class ProjectStatisticsViewObject:
26
    def __init__(
27
        self,
28
        *,
29
        traceability_index: TraceabilityIndex,
30
        project_config: ProjectConfig,
31
        link_renderer: LinkRenderer,
32
        metrics: List[Union[Metric, MetricSection]],
33
    ) -> None:
34
        self.traceability_index: TraceabilityIndex = traceability_index
35
        self.project_config: ProjectConfig = project_config
36
        self.link_renderer: LinkRenderer = link_renderer
37
        self.metrics: List[Union[Metric, MetricSection]] = metrics
38
 
39
        self.document_tree_iterator: DocumentTreeIterator = (
40
            DocumentTreeIterator(
41
                assert_cast(traceability_index.document_tree, DocumentTree)
42
            )
43
        )
44
        self.is_running_on_server: bool = project_config.is_running_on_server
45
        self.strictdoc_version = __version__
46
 
47
    def get_document_level(self) -> int:
48
        return 0
49
 
50
    def render_screen(self, jinja_environment: JinjaEnvironment) -> Markup:
51
        return jinja_environment.render_template_as_markup(
52
            "features/project_statistics/index.jinja", view_object=self
53
        )
54
 
55
    def render_static_url(self, url: str) -> Markup:
56
        return Markup(self.link_renderer.render_static_url(url))
57
 
58
    def render_url(self, url: str) -> Markup:
59
        return Markup(self.link_renderer.render_url(url))