From 04162a27bc21c790a45ae46952e66cd43a2b7926 Mon Sep 17 00:00:00 2001 From: Dan Anglin Date: Mon, 3 Aug 2020 22:32:26 +0100 Subject: [PATCH] feat: ability to specify a current employment This commit allows the user to specify a company that they are currently employed at. Changes include: - add present field to the Duration type. - add durationToString function to output the duration type as a formatted string. - if the present field is used and the value is either 'true' or 'yes' (case insensitive) this will be reflected on the CV. - add durationToString to fmap. - updated CV template to use the durationToString function. --- main.go | 22 ++++++++++++++++++++-- model.go | 5 +++-- template/cv.tex.tmpl | 4 ++-- 3 files changed, 25 insertions(+), 6 deletions(-) diff --git a/main.go b/main.go index 5b1782e..cc0dd62 100644 --- a/main.go +++ b/main.go @@ -2,6 +2,7 @@ package main import ( "encoding/json" + "fmt" "io/ioutil" "log" "os" @@ -22,8 +23,9 @@ func main() { cvOutputPath := cvOutputDir + cvOutputFileName fmap := template.FuncMap{ - "notLastElement": notLastElement, - "join": join, + "notLastElement": notLastElement, + "join": join, + "durationToString": durationToString, } // Read the JSON data @@ -79,3 +81,19 @@ func notLastElement(pos, length int) bool { func join(s []string) string { return strings.Join(s, " ") } + +// durationToString outputs the employment/education +// duration as a formatted string. +func durationToString(d Duration) string { + start := fmt.Sprintf("%s, %s", d.Start.Month, d.Start.Year) + present := strings.ToLower(d.Present) + end := "" + + if present == "yes" || present == "true" { + end = "Present" + } else { + end = fmt.Sprintf("%s, %s", d.End.Month, d.End.Year) + } + + return start + " - " + end +} diff --git a/model.go b/model.go index 836dda5..6724f06 100644 --- a/model.go +++ b/model.go @@ -41,8 +41,9 @@ type Experience struct { } type Duration struct { - Start Date `json:"start"` - End Date `json:"end"` + Start Date `json:"start"` + End Date `json:"end"` + Present string `json:"present"` } type Date struct { diff --git a/template/cv.tex.tmpl b/template/cv.tex.tmpl index fbbebe6..35fe3d1 100644 --- a/template/cv.tex.tmpl +++ b/template/cv.tex.tmpl @@ -28,7 +28,7 @@ \section{EXPERIENCE} <<- range .Employment>> - \jobsection{<<.Company>>}{<<.Location>>}{<<.JobTitle>>}{<<.Duration.Start.Month>>, <<.Duration.Start.Year>> - <<.Duration.End.Month>>, <<.Duration.End.Year>>} + \jobsection{<<.Company>>}{<<.Location>>}{<<.JobTitle>>}{<>} \startitemize <> \item <<.>> @@ -38,7 +38,7 @@ \section{EDUCATION} <> - \jobsection{<<.School>>}{<<.Location>>}{<<.Qualification>>}{<<.Duration.Start.Month>>, <<.Duration.Start.Year>> - <<.Duration.End.Month>>, <<.Duration.End.Year>>} + \jobsection{<<.School>>}{<<.Location>>}{<<.Qualification>>}{<>} \startitemize <> \item <<.>>