Import css into html

This commit is contained in:
Arnaud Ysmal 2018-05-07 22:24:43 +02:00
parent a5c24c4e46
commit 63df11b783
5 changed files with 144 additions and 99 deletions

View File

@ -27,26 +27,48 @@ package kendall
import (
"fmt"
"io/ioutil"
"jsonresume/model"
"jsonresume/themes"
"path"
"strings"
"text/template"
)
const (
packageDirectory = "themes/kendall"
fileCSS = "style.css"
fileCSSPrint = "print.css"
fileTemplate = "resume.template"
)
var Theme = themes.Theme{
Name: "kendall",
Name: "kendall",
Directory: packageDirectory,
Functions: template.FuncMap{
"iconClass": iconClass,
"formatDateWork": formatDateWork,
"formatDateEdu": formatDateEdu,
"formatDatePub": formatDatePub,
"css": getCSS,
"printcss": getPrintCSS,
},
Template: "themes/kendall/resume.template",
Template: fileTemplate,
}
func init() {
(&Theme).Register()
}
func getCSS() string {
r, _ := ioutil.ReadFile(path.Join(packageDirectory, fileCSS))
return string(r)
}
func getPrintCSS() string {
r, _ := ioutil.ReadFile(path.Join(packageDirectory, fileCSSPrint))
return string(r)
}
func iconClass(network string) string {
network = strings.ToLower(network)
switch network {

View File

@ -8,8 +8,8 @@
<title>Resume of {{.Basic.Name}}</title>
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" rel="stylesheet">
<link href="https://maxcdn.bootstrapcdn.com/font-awesome/4.7.0/css/font-awesome.min.css" rel="stylesheet">
<link rel="stylesheet" type="text/css" href="style.css" media="screen">
<link rel="stylesheet" type="text/css" href="print.css" media="print">
<style type="text/css">{{css}}</style>
<style type="text/css" media="print">{{printcss}}</style>
</head>
<body>
<div class="container">
@ -21,9 +21,9 @@
<div id="photo">
<img src="{{.Basic.Image}}" alt="avatar">
</div>
{{end -}}
<div id="text-header" {{if not .Basic.Image}}style="margin-top: 90px;"{{end -}}>
<h1>{{.Basic.Name}}<br>{{if .Basic.Label}}<span>{{.Basic.Label}}</span>{{end -}}</h1>
{{- end}}
<div id="text-header" {{if not .Basic.Image}}style="margin-top: 90px;"{{- end}}>
<h1>{{.Basic.Name}}<br>{{if .Basic.Label}}<span>{{.Basic.Label}}</span>{{- end}}</h1>
</div>
</div>
</div>
@ -36,7 +36,7 @@
<h2><i class="fa fa-user ico"></i> About</h2>
<p>{{.Basic.Summary}}</p>
</div>
{{end -}}
{{- end}}
{{if .Work -}}
<!-- WORK EXPERIENCE -->
<div class="box">
@ -50,7 +50,7 @@
<div class="address">
<a href="{{.URL}}" target= "_blank"><i class="fa fa-globe ico"></i> {{.URL}}</a>
</div>
{{end -}}
{{- end}}
<div class="year">{{formatDateWork .StartDate}} {{formatDateWork .EndDate}}</div>
</div>
</div>
@ -64,16 +64,16 @@
<ul class="list-group">
{{range .Highlights -}}
<li class="list-group-item">{{.}}</li>
{{end -}}
{{- end}}
</ul>
{{end -}}
{{- end}}
</div>
</div>
</div>
</div>
{{end -}}
{{- end}}
</div>
{{end -}}
{{- end}}
{{if .Awards -}}
<!-- AWARDS -->
<div class="box">
@ -88,10 +88,10 @@
<p>{{.Summary}}</p>
</div>
</li>
{{end -}}
{{- end}}
</ul>
</div>
{{end -}}
{{- end}}
{{if .Volunteer -}}
<!-- VOLUNTEER -->
<div class="box">
@ -105,7 +105,7 @@
<div class="address">
<a href="{{.URL}}" target= "_blank"><i class="fa fa-globe ico"></i> {{.URL}}</a>
</div>
{{end -}}
{{- end}}
<div class="year">{{formatDateWork .StartDate}} {{formatDateWork .EndDate}}</div>
</div>
</div>
@ -119,16 +119,16 @@
<ul class="list-group">
{{range .Highlights -}}
<li class="list-group-item">{{.}}</li>
{{end -}}
{{- end}}
</ul>
{{end -}}
{{- end}}
</div>
</div>
</div>
</div>
{{end -}}
{{- end}}
</div>
{{end -}}
{{- end}}
</div>
<div class="col-xs-12 col-sm-5">
<!-- CONTACT -->
@ -137,35 +137,35 @@
{{if .Basic.ResumeLocation.City -}}
<div class="contact-item">
<div class="icon pull-left text-center"><span class="fa fa-map-marker fa-fw"></span></div>
{{if .Basic.ResumeLocation.Address}}<div class="title pull-right">{{.Basic.ResumeLocation.Address}}</div>{{end -}}
<div class="title {{if not .Basic.ResumeLocation.Address}}only {{end -}} pull-right">{{.Basic.ResumeLocation.City}}{{if .Basic.ResumeLocation.Region}}, {{.Basic.ResumeLocation.Region}}{{end -}}{{if .Basic.ResumeLocation.PostalCode}} {{.Basic.ResumeLocation.PostalCode}}{{end -}}{{if .Basic.ResumeLocation.CountryCode}} {{.Basic.ResumeLocation.CountryCode}}{{end -}}</div>
{{if .Basic.ResumeLocation.Address}}<div class="title pull-right">{{.Basic.ResumeLocation.Address}}</div>{{- end}}
<div class="title {{if not .Basic.ResumeLocation.Address}}only {{- end}} pull-right">{{.Basic.ResumeLocation.City}}{{if .Basic.ResumeLocation.Region}}, {{.Basic.ResumeLocation.Region}}{{- end}}{{if .Basic.ResumeLocation.PostalCode}} {{.Basic.ResumeLocation.PostalCode}}{{- end}}{{if .Basic.ResumeLocation.CountryCode}} {{.Basic.ResumeLocation.CountryCode}}{{- end}}</div>
</div>
{{end -}}
{{- end}}
{{if .Basic.Phone -}}
<div class="contact-item">
<div class="icon pull-left text-center"><span class="fa fa-phone fa-fw"></span></div>
<div class="title only pull-right">{{.Basic.Phone}}</div>
</div>
{{end -}}
{{- end}}
{{if .Basic.Email -}}
<div class="contact-item">
<div class="icon pull-left text-center"><span class="fa fa-envelope fa-fw"></span></div>
<div class="title only pull-right"><a href="mailto:{{.Basic.Email}}" target="_blank">{{.Basic.Email}}</a></div>
</div>
{{end -}}
{{- end}}
{{if .Basic.URL -}}
<div class="contact-item">
<div class="icon pull-left text-center"><span class="fa fa-globe fa-fw"></span></div>
<div class="title only pull-right"><a href="{{.Basic.URL}}" target="_blank">{{.Basic.URL}}</a></div>
</div>
{{end -}}
{{- end}}
{{range .Basic.Profiles -}}
<div class="contact-item">
<div class="icon pull-left text-center"><span class="{{iconClass .Network}} fa-fw"></span></div>
<div class="title pull-right">{{.Network}}</div>
<div class="description pull-right"><a href="{{.URL}}" target="_blank">{{if .UserName}}{{.UserName}}{{end -}}{{if not .UserName}}{{.URL}}{{end -}}</a></div>
<div class="description pull-right"><a href="{{.URL}}" target="_blank">{{if .UserName}}{{.UserName}}{{- end}}{{if not .UserName}}{{.URL}}{{- end}}</a></div>
</div>
{{end -}}
{{- end}}
</div>
{{if .Education -}}
<!-- EDUCATION -->
@ -183,21 +183,21 @@
<p>
GPA: {{.GPA}}
</p>
{{end -}}
{{- end}}
{{if .Courses -}}
<div>Courses</div>
<ul class="list-group">
{{range .Courses -}}
<li class="list-group-item">{{.}}</li>
{{end -}}
{{- end}}
</ul>
{{end -}}
{{- end}}
</div>
</li>
{{end -}}
{{- end}}
</ul>
</div>
{{end -}}
{{- end}}
{{if .Skills -}}
<!-- SKILLS -->
<div class="box">
@ -206,17 +206,17 @@
<div class="skills clearfix">
<div class="item-skills">
{{.Name}}
{{if .Level}}<span class="skill-level">{{.Level}}</span>{{end -}}
{{if .Level}}<span class="skill-level">{{.Level}}</span>{{- end}}
</div>
<div class="col-sm-offset-1 col-sm-12 clearfix">
{{range .Keywords -}}
<span class= "skill badge">{{.}}</span>
{{end -}}
{{- end}}
</div>
</div>
{{end -}}
{{- end}}
</div>
{{end -}}
{{- end}}
{{if .Publications -}}
<!-- PUBLICATIONS -->
<div class="box">
@ -229,21 +229,21 @@
<div class="panel-body">
{{if .Publisher -}}
<div class="publisher"><i class= "fa fa-bookmark ico"></i> {{.Publisher}}</div>
{{end -}}
{{- end}}
<div class="year">{{formatDatePub .ReleaseDate}}</div>
{{if .URL -}}
<div class="address">
<a href="{{.URL}}" target= "_blank"><i class="fa fa-globe ico"></i> {{.URL}}</a>
</div>
{{end -}}
{{- end}}
{{if .Summary -}}
<p>{{.Summary}}</p>
{{end -}}
{{- end}}
</div>
</div>
{{end -}}
{{- end}}
</div>
{{end -}}
{{- end}}
{{if .Languages -}}
<!-- LANGUAGES -->
<div class="box">
@ -251,10 +251,10 @@
<ul class="list-group">
{{range .Languages -}}
<li class=" list-group-item">{{.Language}}<span class="skill badge pull-right">{{.Fluency}}</span></li>
{{end -}}
{{- end}}
</ul>
</div>
{{end -}}
{{- end}}
{{if .Interests -}}
<!-- HOBBIES -->
<div class="box">
@ -267,12 +267,12 @@
<div class="col-sm-offset-1 col-sm-12 clearfix">
{{range .Keywords -}}
<span class= "interest badge">{{.}}</span>
{{end -}}
{{- end}}
</div>
</div>
{{end -}}
{{- end}}
</div>
{{end -}}
{{- end}}
{{if .References -}}
<div class="box">
<h2><i class= "fa fa-check-square ico"></i> References</h2>
@ -281,9 +281,9 @@
<div>{{.Reference}}</div>
<footer>{{.Name}}</footer>
</blockquote><br>
{{end -}}
{{- end}}
</div>
{{end -}}
{{- end}}
</div>
</div>
</div>

View File

@ -27,21 +27,43 @@ package kendallfr
import (
"fmt"
"io/ioutil"
"jsonresume/model"
"jsonresume/themes"
"path"
"strings"
"text/template"
)
const (
packageDirectory = "themes/kendallfr"
fileCSS = "style.css"
fileCSSPrint = "print.css"
fileTemplate = "resume.template"
)
var Theme = themes.Theme{
Name: "kendallfr",
Name: "kendallfr",
Directory: packageDirectory,
Functions: template.FuncMap{
"iconClass": iconClass,
"formatDateWork": formatDateWork,
"formatDateEdu": formatDateEdu,
"formatDatePub": formatDatePub,
"css": getCSS,
"printcss": getPrintCSS,
},
Template: "themes/kendallfr/resume.template",
Template: fileTemplate,
}
func getCSS() string {
r, _ := ioutil.ReadFile(path.Join(packageDirectory, fileCSS))
return string(r)
}
func getPrintCSS() string {
r, _ := ioutil.ReadFile(path.Join(packageDirectory, fileCSSPrint))
return string(r)
}
func init() {

View File

@ -8,8 +8,8 @@
<title>CV de {{.Basic.Name}}</title>
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" rel="stylesheet">
<link href="https://maxcdn.bootstrapcdn.com/font-awesome/4.7.0/css/font-awesome.min.css" rel="stylesheet">
<link rel="stylesheet" type="text/css" href="style.css" media="screen">
<link rel="stylesheet" type="text/css" href="print.css" media="print">
<style type="text/css">{{css}}</style>
<style type="text/css" media="print">{{printcss}}</style>
</head>
<body>
<div class="container">
@ -21,9 +21,9 @@
<div id="photo">
<img src="{{.Basic.Image}}" alt="avatar">
</div>
{{end -}}
<div id="text-header" {{if not .Basic.Image}}style="margin-top: 90px;"{{end -}}>
<h1>{{.Basic.Name}}<br>{{if .Basic.Label}}<span>{{.Basic.Label}}</span>{{end -}}</h1>
{{- end}}
<div id="text-header" {{if not .Basic.Image}}style="margin-top: 90px;"{{- end}}>
<h1>{{.Basic.Name}}<br>{{if .Basic.Label}}<span>{{.Basic.Label}}</span>{{- end}}</h1>
</div>
</div>
</div>
@ -36,7 +36,7 @@
<h2><i class="fa fa-user ico"></i> À propos</h2>
<p>{{.Basic.Summary}}</p>
</div>
{{end -}}
{{- end}}
{{if .Work -}}
<!-- WORK EXPERIENCE -->
<div class="box">
@ -50,7 +50,7 @@
<div class="address">
<a href="{{.URL}}" target= "_blank"><i class="fa fa-globe ico"></i> {{.URL}}</a>
</div>
{{end -}}
{{- end}}
<div class="year">{{formatDateWork .StartDate}} {{formatDateWork .EndDate}}</div>
</div>
</div>
@ -64,16 +64,16 @@
<ul class="list-group">
{{range .Highlights -}}
<li class="list-group-item">{{.}}</li>
{{end -}}
{{- end}}
</ul>
{{end -}}
{{- end}}
</div>
</div>
</div>
</div>
{{end -}}
{{- end}}
</div>
{{end -}}
{{- end}}
{{if .Awards -}}
<!-- AWARDS -->
<div class="box">
@ -88,10 +88,10 @@
<p>{{.Summary}}</p>
</div>
</li>
{{end -}}
{{- end}}
</ul>
</div>
{{end -}}
{{- end}}
{{if .Volunteer -}}
<!-- VOLUNTEER -->
<div class="box">
@ -105,7 +105,7 @@
<div class="address">
<a href="{{.URL}}" target= "_blank"><i class="fa fa-globe ico"></i> {{.URL}}</a>
</div>
{{end -}}
{{- end}}
<div class="year">{{formatDateWork .StartDate}} {{formatDateWork .EndDate}}</div>
</div>
</div>
@ -119,16 +119,16 @@
<ul class="list-group">
{{range .Highlights -}}
<li class="list-group-item">{{.}}</li>
{{end -}}
{{- end}}
</ul>
{{end -}}
{{- end}}
</div>
</div>
</div>
</div>
{{end -}}
{{- end}}
</div>
{{end -}}
{{- end}}
</div>
<div class="col-xs-12 col-sm-5">
<!-- CONTACT -->
@ -137,35 +137,35 @@
{{if .Basic.ResumeLocation.City -}}
<div class="contact-item">
<div class="icon pull-left text-center"><span class="fa fa-map-marker fa-fw"></span></div>
{{if .Basic.ResumeLocation.Address}}<div class="title pull-right">{{.Basic.ResumeLocation.Address}}</div>{{end -}}
<div class="title {{if not .Basic.ResumeLocation.Address}}only {{end -}} pull-right">{{.Basic.ResumeLocation.City}}{{if .Basic.ResumeLocation.Region}}, {{.Basic.ResumeLocation.Region}}{{end -}}{{if .Basic.ResumeLocation.PostalCode}} {{.Basic.ResumeLocation.PostalCode}}{{end -}}{{if .Basic.ResumeLocation.CountryCode}} {{.Basic.ResumeLocation.CountryCode}}{{end -}}</div>
{{if .Basic.ResumeLocation.Address}}<div class="title pull-right">{{.Basic.ResumeLocation.Address}}</div>{{- end}}
<div class="title {{if not .Basic.ResumeLocation.Address}}only {{- end}} pull-right">{{.Basic.ResumeLocation.City}}{{if .Basic.ResumeLocation.Region}}, {{.Basic.ResumeLocation.Region}}{{- end}}{{if .Basic.ResumeLocation.PostalCode}} {{.Basic.ResumeLocation.PostalCode}}{{- end}}{{if .Basic.ResumeLocation.CountryCode}} {{.Basic.ResumeLocation.CountryCode}}{{- end}}</div>
</div>
{{end -}}
{{- end}}
{{if .Basic.Phone -}}
<div class="contact-item">
<div class="icon pull-left text-center"><span class="fa fa-phone fa-fw"></span></div>
<div class="title only pull-right">{{.Basic.Phone}}</div>
</div>
{{end -}}
{{- end}}
{{if .Basic.Email -}}
<div class="contact-item">
<div class="icon pull-left text-center"><span class="fa fa-envelope fa-fw"></span></div>
<div class="title only pull-right"><a href="mailto:{{.Basic.Email}}" target="_blank">{{.Basic.Email}}</a></div>
</div>
{{end -}}
{{- end}}
{{if .Basic.URL -}}
<div class="contact-item">
<div class="icon pull-left text-center"><span class="fa fa-globe fa-fw"></span></div>
<div class="title only pull-right"><a href="{{.Basic.URL}}" target="_blank">{{.Basic.URL}}</a></div>
</div>
{{end -}}
{{- end}}
{{range .Basic.Profiles -}}
<div class="contact-item">
<div class="icon pull-left text-center"><span class="{{iconClass .Network}} fa-fw"></span></div>
<div class="title pull-right">{{.Network}}</div>
<div class="description pull-right"><a href="{{.URL}}" target="_blank">{{if .UserName}}{{.UserName}}{{end -}}{{if not .UserName}}{{.URL}}{{end -}}</a></div>
<div class="description pull-right"><a href="{{.URL}}" target="_blank">{{if .UserName}}{{.UserName}}{{- end}}{{if not .UserName}}{{.URL}}{{- end}}</a></div>
</div>
{{end -}}
{{- end}}
</div>
{{if .Education -}}
<!-- EDUCATION -->
@ -183,21 +183,21 @@
<p>
GPA: {{.GPA}}
</p>
{{end -}}
{{- end}}
{{if .Courses -}}
<div>Courses</div>
<ul class="list-group">
{{range .Courses -}}
<li class="list-group-item">{{.}}</li>
{{end -}}
{{- end}}
</ul>
{{end -}}
{{- end}}
</div>
</li>
{{end -}}
{{- end}}
</ul>
</div>
{{end -}}
{{- end}}
{{if .Skills -}}
<!-- SKILLS -->
<div class="box">
@ -206,17 +206,17 @@
<div class="skills clearfix">
<div class="item-skills">
{{.Name}}
{{if .Level}}<span class="skill-level">{{.Level}}</span>{{end -}}
{{if .Level}}<span class="skill-level">{{.Level}}</span>{{- end}}
</div>
<div class="col-sm-offset-1 col-sm-12 clearfix">
{{range .Keywords -}}
<span class= "skill badge">{{.}}</span>
{{end -}}
{{- end}}
</div>
</div>
{{end -}}
{{- end}}
</div>
{{end -}}
{{- end}}
{{if .Publications -}}
<!-- PUBLICATIONS -->
<div class="box">
@ -229,21 +229,21 @@
<div class="panel-body">
{{if .Publisher -}}
<div class="publisher"><i class= "fa fa-bookmark ico"></i> {{.Publisher}}</div>
{{end -}}
{{- end}}
<div class="year">{{formatDatePub .ReleaseDate}}</div>
{{if .URL -}}
<div class="address">
<a href="{{.URL}}" target= "_blank"><i class="fa fa-globe ico"></i> {{.URL}}</a>
</div>
{{end -}}
{{- end}}
{{if .Summary -}}
<p>{{.Summary}}</p>
{{end -}}
{{- end}}
</div>
</div>
{{end -}}
{{- end}}
</div>
{{end -}}
{{- end}}
{{if .Languages -}}
<!-- LANGUAGES -->
<div class="box">
@ -251,10 +251,10 @@
<ul class="list-group">
{{range .Languages -}}
<li class=" list-group-item">{{.Language}}<span class="skill badge pull-right">{{.Fluency}}</span></li>
{{end -}}
{{- end}}
</ul>
</div>
{{end -}}
{{- end}}
{{if .Interests -}}
<!-- HOBBIES -->
<div class="box">
@ -267,12 +267,12 @@
<div class="col-sm-offset-1 col-sm-12 clearfix">
{{range .Keywords -}}
<span class= "interest badge">{{.}}</span>
{{end -}}
{{- end}}
</div>
</div>
{{end -}}
{{- end}}
</div>
{{end -}}
{{- end}}
{{if .References -}}
<div class="box">
<h2><i class= "fa fa-check-square ico"></i> Références</h2>
@ -281,9 +281,9 @@
<div>{{.Reference}}</div>
<footer>{{.Name}}</footer>
</blockquote><br>
{{end -}}
{{- end}}
</div>
{{end -}}
{{- end}}
</div>
</div>
</div>

View File

@ -35,6 +35,7 @@ import (
type Theme struct {
Name string
Directory string
Functions template.FuncMap
Template string
}
@ -46,7 +47,7 @@ func init() {
}
func (t *Theme) Render(r *model.Resume, w io.Writer) error {
tmpl := template.Must(template.New(path.Base(t.Template)).Funcs(t.Functions).ParseFiles(t.Template))
tmpl := template.Must(template.New(t.Template).Funcs(t.Functions).ParseFiles(path.Join(t.Directory, t.Template)))
return tmpl.Execute(w, r)
}