Skip to content

Commit

Permalink
[DSW-2069] Fix detection of PDF output format
Browse files Browse the repository at this point in the history
  • Loading branch information
MarekSuchanek committed Sep 20, 2023
1 parent 20d4072 commit afab0aa
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
from ..consts import FormatField, StepField
from ..documents import DocumentFile
from ..templates.steps import create_step, Step, \
FormatStepException, WkHtmlToPdfStep
FormatStepException


LOG = logging.getLogger(__name__)
Expand Down Expand Up @@ -59,8 +59,7 @@ def _create_steps(self, metadata: dict) -> list[Step]:

@property
def is_pdf(self) -> bool:
# TODO: refactor to check output FileFormat for step (instead of specific step)
return isinstance(self.steps[-1], WkHtmlToPdfStep)
return self.steps[-1].produces_only_pdf

def requires_via_extras(self, requirement: str) -> bool:
return any(step.requires_via_extras(requirement)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,10 @@ def execute_follow(self, document: DocumentFile, context: dict) -> DocumentFile:
def raise_exc(self, message: str):
raise FormatStepException(message)

@property
def produces_only_pdf(self):
return False


STEPS = dict()

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,10 @@ def execute_follow(self, document: DocumentFile, context: dict) -> DocumentFile:
)
return DocumentFile(self.OUTPUT_FORMAT, data)

@property
def produces_only_pdf(self):
return True


class WeasyPrintStep(Step):
NAME = 'weasyprint'
Expand Down Expand Up @@ -76,6 +80,10 @@ def execute_follow(self, document: DocumentFile, context: dict) -> DocumentFile:
)
return DocumentFile(self.OUTPUT_FORMAT, data)

@property
def produces_only_pdf(self):
return True


class PandocStep(Step):
NAME = 'pandoc'
Expand Down

0 comments on commit afab0aa

Please sign in to comment.