Skip to content

Commit

Permalink
Added templating language to shell
Browse files Browse the repository at this point in the history
  • Loading branch information
ajparsons authored Mar 29, 2022
1 parent 5de560d commit a260b4f
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 7 deletions.
2 changes: 2 additions & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -46,3 +46,5 @@ xlrd==1.2.0
PyMuPDF==1.18.16
black==22.1.0
pylint==1.4.0
rich==12.0.1
cookiecutter==2.8.2
24 changes: 17 additions & 7 deletions shell.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,25 +3,24 @@
import cmd
import io
import os
import signal
import shutil
import signal
import sys
from datetime import datetime
from pathlib import Path
from typing import Union, Optional, List, Any, Callable
from subprocess import Popen
from typing import Any, Callable, List, Optional, Union

import django
import fitz
from cookiecutter.main import cookiecutter
from PIL import Image
from PyPDF2 import PdfFileReader, PdfFileWriter
from rich.prompt import Prompt
from rich import print
from rich.prompt import Prompt
from ruamel.yaml import YAML
from useful_inkleby.files import QuickText

from subprocess import Popen


try:
os.environ.pop("DJANGO_SETTINGS_MODULE")
except Exception:
Expand Down Expand Up @@ -307,8 +306,10 @@ def unloaded_docs(self) -> List[str]:
return [x.name for x in self.get_valid_doc_folders() if x.name in slugs]

def get_valid_doc_folders(self) -> List[Path]:
special = ["_template"]
root = Path(self.current_org.storage_dir, "_docs")
l = [x for x in root.iterdir() if (x / "settings.yaml").exists()]
l = [x for x in root.iterdir() if (x / "settings.yaml").exists() and x.name not in [special]]

l.sort()
return l

Expand Down Expand Up @@ -605,6 +606,15 @@ def do_hero(self, inp):
destination = Path(self.doc_folder, "hero.png")
create_hero(hero_path, destination)

def do_newdoc(self, inp):
"""
Create a new document from the template
"""
template_path = str(Path(self.current_org.storage_dir, "_docs", "_template"))
output_dir = str(Path(self.current_org.storage_dir, "_docs"))

cookiecutter(template_path, output_dir=output_dir )

def default(self, line):
options = line.split(" ")
first = options[0]
Expand Down

0 comments on commit a260b4f

Please sign in to comment.