-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
e265514
commit 71f68a2
Showing
4 changed files
with
140 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,100 @@ | ||
package output | ||
|
||
import ( | ||
"fmt" | ||
"errors" | ||
"strings" | ||
"regexp" | ||
"os" | ||
) | ||
|
||
|
||
//Fill if existing the section of the template with the section given | ||
func applySectionToTemplate(template string,section string, headers []string, items []string)error{ return nil } | ||
|
||
//Read the template file in the assets directory | ||
func readCVTemplate(path string)(string, error){ | ||
file, err := os.ReadFile(path+"/assets/latex/template/template.tex") | ||
if err != nil { | ||
return "", err | ||
} | ||
return string(file), nil | ||
} | ||
|
||
//Write the template file in the assets directory | ||
func makeNewCV(path string, template string, name string)error{ | ||
err := os.WriteFile(path+"/assets/latex/output/"+name, | ||
[]byte(template), 0644) | ||
return err | ||
} | ||
|
||
//In the core we will read the template | ||
//iterate by section | ||
//Apply to template | ||
//Write | ||
|
||
//Apply a section to a section type on a latex template | ||
func ApplyToSectionToTemplate(template string, headers []string,item []string, section string) (string,error){ | ||
switch{ | ||
case section == "Professional": | ||
template = strings.Replace(template,"%EXPERIENCE_SECTIONS%", | ||
"%EXPERIENCE_SECTIONS%\n"+replace_param(prof_template,headers),1) | ||
template = replace_items(template,item) | ||
|
||
case section == "Project": | ||
template = strings.Replace(template,"%PROJECTS_SECTIONS%", | ||
"%PROJECTS_SECTIONS%\n"+replace_param(proj_template,headers),1) | ||
template = replace_items(template, item) | ||
|
||
case section == "Education": | ||
template = strings.Replace(template,"%EDUCATION_SECTIONS%", | ||
"%EDUCATION_SECTIONS%\n"+replace_param(edu_template,headers),1) | ||
|
||
case section == "Skill"://TODO https://github.com/Theo-Hafsaoui/Anemon/issues/1 | ||
template = strings.Replace(template,"%SKILL_SECTIONS%", | ||
"%SKILL_SECTIONS%\n"+replace_param(sk_template,headers),1) | ||
default: | ||
return "",errors.New("Don't know type "+section) | ||
} | ||
return template,nil | ||
} | ||
|
||
|
||
//Search and replace the number in range of `nb_params` by their replacement | ||
func replace_param(sec_template string, replacements []string)string{ | ||
for i := 0; i < len(replacements); i++ { | ||
position := fmt.Sprintf("$%d", i+1) | ||
sec_template = strings.Replace(sec_template, | ||
position, replacements[i], 1) | ||
} | ||
return sanitize(sec_template) | ||
} | ||
|
||
|
||
func replace_items(template string, section_items []string)string{ | ||
items := "" | ||
for _,item := range section_items{ | ||
items += strings.Replace(pro_item,"%ITEM%",item,1) | ||
} | ||
template = strings.Replace(template, | ||
"%ITEMS%", items, 1) | ||
return sanitize(template) | ||
} | ||
|
||
//Sanitize the special charactere | ||
func sanitize(template string)(string){ | ||
replacements := []struct { | ||
pattern string | ||
replacement string | ||
}{ | ||
{`[0-9]\%`, `\\%`}, | ||
{`\*\*(.*?)\*\*`, `\textbf{$1}`}, | ||
{`\*(.*?)\*`, `\emph{$1}`}, | ||
//{`\[(.*?)\]\((.*?)\)`, `\href{$2}{$1}`}, | ||
} | ||
for _, r := range replacements { | ||
re := regexp.MustCompile(r.pattern) | ||
template = re.ReplaceAllString(template, r.replacement) | ||
} | ||
return template | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
package output | ||
|
||
const pro_item = "\\resumeItem{%ITEM%}\n" | ||
|
||
const prof_template = ` | ||
\resumeSubheading | ||
{$1}{$2} | ||
{\href{$3}{$4}}{ } | ||
\resumeItemListStart | ||
%ITEMS% | ||
\resumeItemListEnd | ||
` | ||
const NB_P_PROF = 4 | ||
|
||
const proj_template = ` | ||
\resumeProjectHeading | ||
{\textbf{$1} | \emph{$2 \href{$3}{\faIcon{github}}}}{} | ||
\resumeItemListStart | ||
%ITEMS% | ||
\resumeItemListEnd | ||
` | ||
const NB_P_PROJ = 3 | ||
|
||
const edu_template = ` | ||
\resumeSubheading | ||
{\href{$2}{$1}}{} | ||
{$3}{$4} | ||
` | ||
const NB_P_EDU = 4 | ||
|
||
const sk_template = ` | ||
\item \textbf{$1}{: $2} \\ | ||
` | ||
const NB_P_SK = 2 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters