Skip to content

Commit

Permalink
v.0.32
Browse files Browse the repository at this point in the history
  • Loading branch information
nikolainp committed Oct 29, 2023
1 parent 752dc6b commit 2396cb7
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 5 deletions.
20 changes: 16 additions & 4 deletions toGraph.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ import (
"io"
"log"
"os"
"path/filepath"
"strings"
"text/template"

datarecord "github.com/nikolainp/toGraph/datarecord"
Expand Down Expand Up @@ -34,15 +36,25 @@ func run() {
inputFile, err := os.Open(fileName)
checkErr(err)

outputFile, err := os.OpenFile(fileName+".html", os.O_CREATE|os.O_WRONLY|os.O_TRUNC, 0660)
outFilePath, outFileName := getOutFileName(fileName)

outputFile, err := os.OpenFile(outFilePath, os.O_CREATE|os.O_WRONLY|os.O_TRUNC, 0660)
checkErr(err)

log.Printf("file being processed: %s", fileName)
processFile(inputFile, outputFile, state.Config())
processFile(inputFile, outputFile, state.Config(), outFileName)
}
}

func processFile(sIn io.Reader, sOut io.Writer, config state.Configuration) error {
func getOutFileName(fileName string) (outFilePath string, outFileName string) {
outFilePath = filepath.Dir(fileName)
outFileName = filepath.Base(fileName)
outFileName = strings.TrimSuffix(outFileName, filepath.Ext(outFileName))

return filepath.Join(outFilePath, outFileName+".html"), outFileName
}

func processFile(sIn io.Reader, sOut io.Writer, config state.Configuration, title string) error {

scanner := bufio.NewScanner(sIn)
reader := datarecord.GetDataReader()
Expand All @@ -63,7 +75,7 @@ func processFile(sIn io.Reader, sOut io.Writer, config state.Configuration) erro
Columns []string
DataRows []string
}{
Title: "My page",
Title: title,
Columns: reader.GetColumns(),
DataRows: reader.GetDataRows(),
}
Expand Down
2 changes: 1 addition & 1 deletion toGraphTemplate.go
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ const graphTemplate = `
<body>
<div class="dropdown" style='height: 30px;'>
<span>My page</span>
<span>{{.Title}}</span>
<div class="dropdown-content">
{{range $i, $column := .Columns -}}
<input type="checkbox" name="{{$column}}" value="{{$i}}" onchange="onChangeColumn(this)" checked>
Expand Down

0 comments on commit 2396cb7

Please sign in to comment.