bookends

commit 6c98679eb5e4907d0d6a1fe740eebde5e04593c3

Author: Honza Pokorny <honza@redhat.com>

Remove hardcoded template path

 cmd/build.go | 9 +++++----
 cmd/cache.go | 9 +++++----
 cmd/root.go | 2 ++
 pkg/bookends/bookends.go | 15 ++++++++-------


diff --git a/cmd/build.go b/cmd/build.go
index 8ec4c73b7f61f1035d38ef8a42593f7c26aa0484..b58970656b732d438175c8d9918eb76003d5b64f 100644
--- a/cmd/build.go
+++ b/cmd/build.go
@@ -29,10 +29,11 @@ 	Use:   "build",
 	Short: "",
 	Run: func(cmd *cobra.Command, args []string) {
 		config := bookends.Config{
-			BookLogFilename: bookLogFilename,
-			CacheDir:        cacheDir,
-			CoversDir:       coversDir,
-			OutputFilename:  outputFilename,
+			BookLogFilename:  bookLogFilename,
+			CacheDir:         cacheDir,
+			CoversDir:        coversDir,
+			OutputFilename:   outputFilename,
+			TemplateFilename: templateFilename,
 		}
 		err := bookends.Build(config)
 		if err != nil {




diff --git a/cmd/cache.go b/cmd/cache.go
index 4be3490b7d8008f75c150809761123d3a15e5182..86e63b3628cd0b82e982aa6f4eb2fa464c49d3a2 100644
--- a/cmd/cache.go
+++ b/cmd/cache.go
@@ -29,10 +29,11 @@ 	Use:   "cache",
 	Short: "",
 	Run: func(cmd *cobra.Command, args []string) {
 		config := bookends.Config{
-			BookLogFilename: bookLogFilename,
-			CacheDir:        cacheDir,
-			CoversDir:       coversDir,
-			OutputFilename:  outputFilename,
+			BookLogFilename:  bookLogFilename,
+			CacheDir:         cacheDir,
+			CoversDir:        coversDir,
+			OutputFilename:   outputFilename,
+			TemplateFilename: templateFilename,
 		}
 		err := bookends.CacheCovers(config)
 		if err != nil {




diff --git a/cmd/root.go b/cmd/root.go
index 3827dad07700580511a43fa67e5c9a05419dea39..e4e063f2cb8d026e40ad5aaddd91d5549565dc42 100644
--- a/cmd/root.go
+++ b/cmd/root.go
@@ -27,6 +27,7 @@ var bookLogFilename string
 var cacheDir string
 var coversDir string
 var outputFilename string
+var templateFilename string
 
 var rootCmd = &cobra.Command{
 	Use:   "bookends",
@@ -49,6 +50,7 @@ 	rootCmd.PersistentFlags().StringVar(&bookLogFilename, "book-log-filename", "book-log.org", "")
 	rootCmd.PersistentFlags().StringVar(&cacheDir, "cache-dir", "cache", "")
 	rootCmd.PersistentFlags().StringVar(&coversDir, "covers-dir", "covers", "")
 	rootCmd.PersistentFlags().StringVar(&outputFilename, "output-filename", "output.html", "")
+	rootCmd.PersistentFlags().StringVar(&templateFilename, "template-filename", "template.html", "")
 
 	rootCmd.AddCommand(buildCmd)
 	rootCmd.AddCommand(cacheCovers)




diff --git a/pkg/bookends/bookends.go b/pkg/bookends/bookends.go
index 629241521eba880475c15397d4daafc1aa408610..e04ae6ff7e4fe7c98c51924085673fa2ebc6ff31 100644
--- a/pkg/bookends/bookends.go
+++ b/pkg/bookends/bookends.go
@@ -35,10 +35,11 @@ 	"github.com/niklasfasching/go-org/org"
 )
 
 type Config struct {
-	BookLogFilename string
-	CacheDir        string
-	CoversDir       string
-	OutputFilename  string
+	BookLogFilename  string
+	CacheDir         string
+	CoversDir        string
+	OutputFilename   string
+	TemplateFilename string
 }
 
 type Book struct {
@@ -93,8 +94,8 @@ func (b Book) DownloadCover() error {
 	return nil
 }
 
-func BuildHTML(books []Book) (string, error) {
-	t, err := template.ParseFiles("template.html")
+func BuildHTML(config Config, books []Book) (string, error) {
+	t, err := template.ParseFiles(config.TemplateFilename)
 
 	if err != nil {
 		return "", err
@@ -144,7 +145,7 @@ 	}
 
 	sort.Sort(BooksByDateRead(books))
 
-	htmlOutput, err := BuildHTML(books)
+	htmlOutput, err := BuildHTML(config, books)
 
 	if err != nil {
 		return err