Skip to content

Commit

Permalink
Initial cut at looking up cookiecutter templates from package resources
Browse files Browse the repository at this point in the history
  • Loading branch information
crossjam committed Mar 3, 2024
1 parent 16f42dd commit 730a49d
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 5 deletions.
17 changes: 12 additions & 5 deletions quarto_post_init/cli.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,13 @@
import logging

from importlib import resources

import click

from .logconfig import DEFAULT_LOG_FORMAT, logging_config

from . import templates


@click.group()
@click.version_option()
Expand All @@ -28,10 +32,13 @@ def cli(log_format, log_level, log_file):
logging_config(log_format, log_level, log_file)


@cli.command(name="command")
@click.argument("example")
def first_command(example):
@cli.command(name="post")
def post():
"Command description goes here"

click.echo("Here is some output")
logging.info("Here's some log output")
tmpls = resources.files(templates)
for p in tmpls.iterdir():
logging.info("Checking for template in %s", p)
if (p / "cookiecutter.json").is_file():
logging.info("cookiecutter template: %s", p)
click.echo(f"cookiecutter template: {str(p)}")
8 changes: 8 additions & 0 deletions quarto_post_init/templates/post/cookiecutter.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"post_slug": null,
"post_title": null,
"post_date": null,
"post_categories": null,
"post_author": null,
"post_toc": true
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
---
title: {{ cookiecutter.post_title }}
author: {{ cookiecutter.post_author }}
date: {{ cookiecutter.post_date }}
categories: []
code-block-border-left: true
code-line-numbers: true
format:
html:
toc: {{ cookiecutter.post_toc }}
---

0 comments on commit 730a49d

Please sign in to comment.