From 70590088d4b05b446fde09e07e5fcedbef3e994f Mon Sep 17 00:00:00 2001 From: Chris Sexton Date: Wed, 14 Aug 2019 17:53:41 -0400 Subject: [PATCH] add lesson plan template --- generate.go | 57 ++++++++++++++++++++++++++++++++++++--- templates/lesson/body.tpl | 19 +++++++++++++ templates/lesson/foot.tpl | 1 + templates/lesson/head.tpl | 38 ++++++++++++++++++++++++++ 4 files changed, 112 insertions(+), 3 deletions(-) create mode 100644 templates/lesson/body.tpl create mode 100644 templates/lesson/foot.tpl create mode 100644 templates/lesson/head.tpl diff --git a/generate.go b/generate.go index a3cac1d..8d10122 100644 --- a/generate.go +++ b/generate.go @@ -13,10 +13,12 @@ import ( ) var ( - fileName = flag.String("file", "output", "Name of output file") - tplPath = flag.String("tpl", "daily", "Path to templates") - startDate = flag.String("start", "", "date of start (yyy-mm-dd)") + fileName = flag.String("file", "output", "name of output file") + tplPath = flag.String("tpl", "daily", "template name") + startDate = flag.String("start", "", "date of start (yyyy-mm-dd)") courseDays = flag.String("courseDays", "Monday,Wednesday,Other", "days for the class template") + holidays = flag.String("holidays", "", "dates (yyyy-mm-dd) comma separated of holidays") + course = flag.String("course", "Cxxx", "course for lesson template") courses = flag.String("courses", "Cxxx,Cyyy,Czzz", "courses for the class template") pages = flag.Int("pages", 7, "number of pages") debug = flag.Bool("debug", false, "leave LaTeX log files") @@ -34,6 +36,8 @@ func main() { daily(tmpfile) case "class": class(tmpfile) + case "lesson": + lesson(tmpfile) default: log.Fatal("Unknown template") } @@ -42,6 +46,8 @@ func main() { } cmd := exec.Command("xelatex", "-halt-on-error", "-jobname="+*fileName, tmpfile.Name()) + cmd.Stderr = os.Stderr + cmd.Stdout = os.Stderr err = cmd.Run() if err != nil { log.Fatal(err) @@ -102,6 +108,51 @@ func daily(file *os.File) { check(foot.Execute(file, nil)) } +func lesson(file *os.File) { + head := template.Must(template.ParseFiles("templates/lesson/head.tpl")) + body := template.Must(template.ParseFiles("templates/lesson/body.tpl")) + foot := template.Must(template.ParseFiles("templates/lesson/foot.tpl")) + + hs := strings.Split(*holidays, ",") + holdayDates := map[time.Time]bool{} + for _, h := range hs { + if h == "" { + continue + } + day, err := time.Parse("2006-01-02", h) + check(err) + holdayDates[day] = true + } + + if *startDate == "" { + *startDate = time.Now().Format("2006-01-02") + } + day, err := time.Parse("2006-01-02", *startDate) + check(err) + + check(head.Execute(file, nil)) + for i := 0; i < *pages*2; { + info := map[string]interface{}{ + "Course": *course, + "Date": fmt.Sprintf("%s", day.Format("2006/01/02")), + "Day": fmt.Sprintf("Day %d", i+1), + } + if !holdayDates[day] { + check(body.Execute(file, info)) + i++ + } + day2 := day.Add(2 * 24 * time.Hour) + info["Date"] = fmt.Sprintf("%s", day2.Format("2006/01/02")) + info["Day"] = fmt.Sprintf("Day %d", i+1) + if !holdayDates[day2] { + check(body.Execute(file, info)) + i++ + } + day = day.Add(24 * 7 * time.Hour) + } + check(foot.Execute(file, nil)) +} + func check(err error) { if err != nil { log.Fatal(err) diff --git a/templates/lesson/body.tpl b/templates/lesson/body.tpl new file mode 100644 index 0000000..6d4a9a7 --- /dev/null +++ b/templates/lesson/body.tpl @@ -0,0 +1,19 @@ +\begin{tabular}{ |c| } + \hline + \cellcolor{anti-flashwhite} + \noindent + \textbox{ {{.Date}} \hfill} + \textbox{\hfil {{.Course}} Lesson Plan \hfil} + \textbox{\hfill {{.Day}} } + \\ + \hline +\end{tabular} + +\begin{tabular*}{189mm}{|@{\extracolsep{\fill} }l|l|}\hline +Title & \\[10mm] \hline +Summary & \\[30mm] \hline +Objectives & \\[90mm] \hline +Assessment & \\[90mm] \hline +\end{tabular*} + +\newpage diff --git a/templates/lesson/foot.tpl b/templates/lesson/foot.tpl new file mode 100644 index 0000000..6b47932 --- /dev/null +++ b/templates/lesson/foot.tpl @@ -0,0 +1 @@ +\end{document} diff --git a/templates/lesson/head.tpl b/templates/lesson/head.tpl new file mode 100644 index 0000000..4e76aa5 --- /dev/null +++ b/templates/lesson/head.tpl @@ -0,0 +1,38 @@ +\documentclass[letter]{article} +%\input \jobname + +\def \colwidth{56mm} + +\usepackage[utf8]{inputenc} +\usepackage[letterpaper, margin=1cm]{geometry} +\usepackage{array} +\usepackage{graphicx} +\usepackage{colortbl} +\usepackage[x11names]{xcolor} +\usepackage{tabularx,booktabs} + +\pagenumbering{gobble} + +\renewcommand{\arraystretch}{1.6} + +\newcolumntype{C}[1]{>{\centering\arraybackslash}p{#1}} +\newcolumntype{M}[1]{>{\centering\arraybackslash}m{#1}} +\newcolumntype{S}{>{\centering\arraybackslash} m{.4\linewidth} } + +\definecolor{anti-flashwhite}{rgb}{0.95, 0.95, 0.96} + +\newcommand*{\grayline}{% + \arrayrulecolor{anti-flashwhite} + \cline{1-3} + \arrayrulecolor{black} +} + +% TODO: Make this reactive +\newcommand\textbox[1]{% + \parbox{60.5mm}{#1}% +} + +\begin{document} +\centering + +