Skip to content

Commit

Permalink
output_file needs access to markata
Browse files Browse the repository at this point in the history
  • Loading branch information
WaylonWalker committed Jul 9, 2023
1 parent 8e2f085 commit cd2a451
Showing 1 changed file with 2 additions and 16 deletions.
18 changes: 2 additions & 16 deletions markata/plugins/service_worker.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,30 +70,16 @@ class ServiceWorkerConfig(pydantic.BaseModel):
precache_feeds: bool = False
template_file: Optional[Path] = None
template: Optional[Template] = None
output_file: Optional[Path] = None

class Config:
arbitrary_types_allowed = True

@pydantic.validator("output_dir", always=True, pre=True)
def validate_output_dir(cls, v):
if v is None:
return cls.markata.config.output_dir
return v

@pydantic.validator("template_file", always=True, pre=True)
def validate_template_file(cls, v):
if v is None:
return Path(__file__).parent / "default_service_worker_template.js"
return v

@pydantic.validator("output_file", always=True, pre=True)
def validate_output_file(cls, v, *, values):
if v is None:
return values["output_dir"] / "service_worker.js"
return v


class Config(pydantic.BaseModel):
service_worker: ServiceWorkerConfig = ServiceWorkerConfig()

Expand Down Expand Up @@ -136,5 +122,5 @@ def save(markata: "Markata") -> None:
output_dirhash=dirhash(markata.config.output_dir),
)

markata.config.service_worker.output_file.parent.mkdir(exist_ok=True)
markata.config.service_worker.output_file.write_text(service_worker_js)
output_file = markata.config.output_dir / "service-worker.js"
output_file.write_text(service_worker_js)

0 comments on commit cd2a451

Please sign in to comment.