From b510ea8f56cdf87ed57fec4bf2cb8720d996597f Mon Sep 17 00:00:00 2001 From: Volker Schukai <volker.schukai@schukai.com> Date: Sun, 17 Jul 2022 20:45:10 +0200 Subject: [PATCH] chore: commit save point --- .../source/commands/08_document_build.go | 2 +- application/source/document/pdf.go | 8 +- application/source/document/source.go | 4 - application/source/environment/config.go | 3 + application/source/environment/state.go | 15 ++- .../source/environment/state_config.go | 15 +++ .../source/environment/state_document.go | 2 +- application/source/environment/state_pdf.go | 8 +- application/source/environment/template.go | 121 +----------------- development/examples/example1/config.yaml | 19 --- release.json | 2 +- 11 files changed, 43 insertions(+), 156 deletions(-) create mode 100644 application/source/environment/state_config.go diff --git a/application/source/commands/08_document_build.go b/application/source/commands/08_document_build.go index a76327c..818209d 100644 --- a/application/source/commands/08_document_build.go +++ b/application/source/commands/08_document_build.go @@ -50,7 +50,7 @@ func initDocumentBuild(command *flags.Command) { } func buildDocumentation(name string) { - + root := environment.State.GetDocumentPath(definition.Document.SourcePath) path := path.Join(root, name) diff --git a/application/source/document/pdf.go b/application/source/document/pdf.go index eaf58d2..c9b299a 100644 --- a/application/source/document/pdf.go +++ b/application/source/document/pdf.go @@ -12,6 +12,7 @@ import ( "regexp" "strings" "text/template" + "time" ) type BuildPdfEnvironment struct { @@ -26,7 +27,8 @@ type BuildPdfEnvironment struct { } type PdfDataset struct { - Documents string + Documents string + CreatedFormat string } func NewPdfDataset(env BuildPdfEnvironment) (*PdfDataset, error) { @@ -63,6 +65,10 @@ func NewPdfDataset(env BuildPdfEnvironment) (*PdfDataset, error) { d.Documents = strings.Join(docs, "\n") + format := environment.State.GetDocumentDateFormat("") + now := time.Now() + d.CreatedFormat = now.Format(format) + if env.Verbose { fmt.Println(d.Documents) } diff --git a/application/source/document/source.go b/application/source/document/source.go index a5d96a7..806c256 100644 --- a/application/source/document/source.go +++ b/application/source/document/source.go @@ -47,7 +47,3 @@ func NewDefinition(root string, sourcePath string, info os.FileInfo, textMeta te func (d *SourceFile) GetSourcePath() string { return d.absSourcePath } - -//func (d *SourceFile) GetTargetPath() string { -// return d.targetPath -//} diff --git a/application/source/environment/config.go b/application/source/environment/config.go index c51dee1..2bae8a3 100644 --- a/application/source/environment/config.go +++ b/application/source/environment/config.go @@ -5,6 +5,7 @@ import ( "gopkg.in/yaml.v3" "os" "os/user" + "path" "strings" ) @@ -49,6 +50,8 @@ func checkAndInitConfiguration(name string) bool { return false } + State.configurationDirectory = path.Dir(name) + return true } diff --git a/application/source/environment/state.go b/application/source/environment/state.go index 71068bc..28f806d 100644 --- a/application/source/environment/state.go +++ b/application/source/environment/state.go @@ -7,13 +7,14 @@ import ( ) type stateStruct struct { - info InfoStruct - exitCode int - warnings []string - errors []string - messages []string - parser *flags.Parser - configuration *Configuration + info InfoStruct + exitCode int + warnings []string + errors []string + messages []string + parser *flags.Parser + configuration *Configuration + configurationDirectory string } type DefinitionInterface interface { diff --git a/application/source/environment/state_config.go b/application/source/environment/state_config.go new file mode 100644 index 0000000..9c4f8b4 --- /dev/null +++ b/application/source/environment/state_config.go @@ -0,0 +1,15 @@ +package environment + +import ( + "path/filepath" +) + +func (e *stateStruct) sanityConfigPath(arg string) string { + + if filepath.IsAbs(arg) { + return arg + } + + return filepath.Clean(filepath.Join(e.configurationDirectory, arg)) + +} diff --git a/application/source/environment/state_document.go b/application/source/environment/state_document.go index 3336873..659bed5 100644 --- a/application/source/environment/state_document.go +++ b/application/source/environment/state_document.go @@ -21,7 +21,7 @@ func (e *stateStruct) GetDocumentPath(arg string) string { } if e.configuration.Document.Path != "" { - return e.configuration.Document.Path + return e.sanityConfigPath(e.configuration.Document.Path) } path, err := os.Getwd() diff --git a/application/source/environment/state_pdf.go b/application/source/environment/state_pdf.go index 2a86cd9..0ead5c6 100644 --- a/application/source/environment/state_pdf.go +++ b/application/source/environment/state_pdf.go @@ -1,7 +1,7 @@ package environment func (e *stateStruct) GetPDFOutputPath() string { - return e.configuration.Document.PDF.Output + return e.sanityConfigPath(e.configuration.Document.PDF.Output) } func (e *stateStruct) GetPDFLatexTemplatePath(arg string) string { @@ -10,7 +10,7 @@ func (e *stateStruct) GetPDFLatexTemplatePath(arg string) string { } if e.configuration.Document.PDF.Teplates.Latex != "" { - return e.configuration.Document.PDF.Teplates.Latex + return e.sanityConfigPath(e.configuration.Document.PDF.Teplates.Latex) } return "" @@ -22,7 +22,7 @@ func (e *stateStruct) GetPDFMarkdownTemplatePath(arg string) string { } if e.configuration.Document.PDF.Teplates.Markdown != "" { - return e.configuration.Document.PDF.Teplates.Markdown + return e.sanityConfigPath(e.configuration.Document.PDF.Teplates.Markdown) } return "" @@ -33,7 +33,7 @@ func (e *stateStruct) GetDocumentPDFOutputPath(arg string) string { } if e.configuration.Document.PDF.Output != "" { - return e.configuration.Document.PDF.Output + return e.sanityConfigPath(e.configuration.Document.PDF.Output) } return "" diff --git a/application/source/environment/template.go b/application/source/environment/template.go index 32260b8..6e13828 100644 --- a/application/source/environment/template.go +++ b/application/source/environment/template.go @@ -9,6 +9,9 @@ import ( ) const defaultMarkdownTemplate = ` +--- +date: {{ .CreatedFormat }} +... {{ .Documents }} ` @@ -102,121 +105,3 @@ func convertTemplateLatexLogo(content string, absolute string) string { return content } - -/** - -func CreatePDF() error { - - err, pageData := collectStructureFromFiles(config.Path) - if err != nil { - return err - } - - d, err := getDataset(pageData, flagInitChangelog|flagInitTasks|flagInitDocuments) - if err != nil { - return err - } - - outputName := arguments.Build.PDF.Output - - if outputName == "" { - printErrorAndExit(2, "if the type is pdf, the output option must be specified") - } - - file, err := ioutil.TempFile(os.TempDir(), "docman") - if err != nil { - printErrorAndExit(2, "A temporary file cannot be created", err.Error()) - } - defer os.Remove(file.Name()) - - t, err := template.New("pdf").Parse(config.PDF.Template.Internal.MarkdownContent) - if err != nil { - return err - } - - err = t.Execute(file, d) - if err != nil { - return err - } - - createLuaFile() - runPandoc(file.Name(), outputName, config.PDF.Template.Latex) - - if luaRawBlockFile != nil { - luaRawBlockFile.Close() - } - - return nil - -} - -var luaRawBlockFile *os.File - -func createLuaFile() { - var err error - - luaRawBlockFile, err = ioutil.TempFile(os.TempDir(), "lua-raw-block") - if err != nil { - printErrorAndExit(2, "A temporary file cannot be created", err.Error()) - } - - luaRawBlockFile.WriteString(` -function RawBlock (raw) - return raw.format:match 'html' - and pandoc.read(raw.text, 'html').blocks - or raw -end -`) - -} - -func getAdjustedContent(absolute string) string { - - content, err := os.ReadFile(absolute) - if err != nil { - printError("The file cannot be read", absolute) - return "" - } - - err, def := splitYamlParts(content) - if err != nil { - printError(err.Error()) - return "" - } - - s := convertImages(def.text, path.Dir(absolute)) - - return s -} - -func convertImages(content string, absolute string) string { - - todoRegEx := regexp.MustCompile(`(?P<match>\!\[(?P<label>[^]]*)\]\((?P<path>[^)]*)\))`) - - matches := todoRegEx.FindAllStringSubmatch(content, -1) - if matches == nil { - return content - } - - for _, match := range matches { - result := make(map[string]string) - for i, name := range todoRegEx.SubexpNames() { - if i != 0 && name != "" { - result[name] = match[i] - } - } - - if filepath.IsAbs(result["path"]) { - continue - } - - path := path.Clean(absolute + "/" + result["path"]) - content = strings.Replace(content, result["match"], "!["+result["label"]+"]("+path+")", -1) - - } - - return content -} - - -*/ diff --git a/development/examples/example1/config.yaml b/development/examples/example1/config.yaml index b9f0206..f92a347 100644 --- a/development/examples/example1/config.yaml +++ b/development/examples/example1/config.yaml @@ -8,22 +8,3 @@ Document: Latex: /home/volker.schukai/projekte/gitlab/oss/utilities/documentation-manager/development/examples/example1/templates/my.latex Markdown: /home/volker.schukai/projekte/gitlab/oss/utilities/documentation-manager/development/examples/example1/templates/my.md - - -# Document struct { -# Path string `yaml:"Path" envconfig:"PATH"` -# DateFormat string `yaml:"DateFormat" envconfig:"DATE_FORMAT"` -# Add struct { -# Template string `yaml:"Template" envconfig:"NEW_TEMPLATE"` -#} -# Build struct { -# //Path string `yaml:"Path" envconfig:"BUILD_PATH"` -#} `yaml:"Build"` -# PDF struct { -# Output string `yaml:"Output" envconfig:"PDF_OUTPUT"` -# Teplates struct { -# Latex string `yaml:"Latex" envconfig:"PDF_LATEX_TEMPLATE"` -# Markdown string `yaml:"Markdown" envconfig:"PDF_MARKDOWN_TEMPLATE"` -# } `yaml:"Templates"` -#} `yaml:"PDF"` -#} `yaml:"Document"` \ No newline at end of file diff --git a/release.json b/release.json index 331eef0..e972d4b 100644 --- a/release.json +++ b/release.json @@ -1,3 +1,3 @@ { - "version": "1.0.36" + "version": "1.0.38" } \ No newline at end of file -- GitLab