add S20 stuff

This commit is contained in:
Chris Sexton 2020-01-13 09:40:44 -05:00
parent 348ce72532
commit 9487dda008
5 changed files with 26 additions and 61 deletions

View File

@ -2,11 +2,14 @@ package main
import (
"flag"
"fmt"
"log"
"os"
"strings"
"text/template"
"time"
"github.com/gobuffalo/packd"
"github.com/gobuffalo/packr/v2"
"github.com/BurntSushi/toml"
@ -15,10 +18,10 @@ import (
const layout = "2006-01-02"
var tplMap = map[string]string{
"assignments": "tpl/assignments.adoc.tpl",
"schedule": "tpl/schedule.adoc.tpl",
"syllabus": "tpl/syllabus.adoc.tpl",
"course": "tpl/course.task.tpl",
"assignments": "assignments.adoc.tpl",
"schedule": "schedule.adoc.tpl",
"syllabus": "syllabus.adoc.tpl",
"course": "course.task.tpl",
}
type DayMap map[int]time.Time
@ -96,7 +99,7 @@ type Config struct {
Days []Day
Assignments []Assignment
Resources []Link
Resources string
Evaluation []Eval
EvalText string
@ -114,6 +117,13 @@ func main() {
box = packr.New("templates", "./tpl")
log.Println("semestergen 0.02")
box.Walk(func(s string, file packd.File) error {
log.Printf("box file: %s", s)
return nil
})
for i := 0; i < flag.NArg(); i++ {
c := mkConfig(flag.Arg(i))
if err := writeSyllabus(c); err != nil {
@ -141,7 +151,7 @@ func writeTaskPaper(c Config) error {
"getDate": c.GetDate,
"dueTime": func() string { return c.DueTime },
}
tplName := "course"
tplName := tplMap["course"]
src, _ := box.FindString(tplName)
tpl, err := template.New(tplName).Funcs(funcs).Parse(src)
if err != nil {
@ -160,7 +170,7 @@ func writeAssignments(c Config) error {
funcs := template.FuncMap{
"getDate": c.GetDate,
}
tplName := "assignments"
tplName := tplMap["assignments"]
src, _ := box.FindString(tplName)
tpl, err := template.New(tplName).Funcs(funcs).Parse(src)
if err != nil {
@ -176,10 +186,14 @@ func writeSchedule(c Config) error {
if err != nil {
return err
}
tplName := "schedule"
src, _ := box.FindString(tplName)
tplName := tplMap["schedule"]
src, err := box.FindString(tplName)
if err != nil {
return fmt.Errorf("error finding template: %w", err)
}
tpl, err := template.New(tplName).Parse(src)
if err != nil {
return fmt.Errorf("error parsing template: %w", err)
return err
}
err = tpl.Execute(f, c)
@ -192,7 +206,7 @@ func writeSyllabus(c Config) error {
if err != nil {
return err
}
tplName := "syllabus"
tplName := tplMap["syllabus"]
src, _ := box.FindString(tplName)
tpl, err := template.New(tplName).Parse(src)
if err != nil {

1
go.mod
View File

@ -4,5 +4,6 @@ go 1.13
require (
github.com/BurntSushi/toml v0.3.1
github.com/gobuffalo/packd v0.3.0
github.com/gobuffalo/packr/v2 v2.7.1
)

View File

@ -1,8 +0,0 @@
// +build !skippackr
// Code generated by github.com/gobuffalo/packr/v2. DO NOT EDIT.
// You can use the "packr clean" command to clean up this,
// and any other packr generated files.
package main
import _ "code.chrissexton.org/cws/semestergen/packrd"

File diff suppressed because one or more lines are too long

View File

@ -45,13 +45,7 @@ This schedule is tentative.
== Some F# resources
{{range .Resources -}}
{{- if .URL}}
{{.Stars}} {{.URL}}[{{.Title}}]
{{- else}}
{{.Stars}} {{.Title}}
{{- end}}
{{- end}}
{{.Resources}}
== Grading Scale