From 51fda8819a8f05b55bfcb4cb86ae2ab0435220f7 Mon Sep 17 00:00:00 2001 From: Vasiliy Solovey Date: Tue, 18 Jul 2017 11:54:37 +0300 Subject: [PATCH 1/3] helpers: Add --trace to asciidoctor args This will help to understand and fix errors by seeing stacktrace of an error. --- helpers/content.go | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/helpers/content.go b/helpers/content.go index 6db35263f24..b7f9db6e63f 100644 --- a/helpers/content.go +++ b/helpers/content.go @@ -573,7 +573,12 @@ func getAsciidocContent(ctx *RenderingContext) []byte { } jww.INFO.Println("Rendering", ctx.DocumentName, "with", path, "...") - cmd := exec.Command(path, "--no-header-footer", "--safe", "-") + cmd := exec.Command(path, "--no-header-footer", "--safe") + if strings.HasSuffix(path, "asciidoctor") { + // asciidoctor-specific arg to show stack traces on errors + cmd.Args = append(cmd.Args, "--trace") + } + cmd.Args = append(cmd.Args, "-") cmd.Stdin = bytes.NewReader(cleanContent) var out, cmderr bytes.Buffer cmd.Stdout = &out From 6ceb0b42fce272b4a1ffadd3cc162c6dd4d4adcf Mon Sep 17 00:00:00 2001 From: Vasiliy Solovey Date: Tue, 18 Jul 2017 13:07:34 +0300 Subject: [PATCH 2/3] helpers: Add smarter check for asciidoctor --- helpers/content.go | 37 ++++++++++++++++++++++++++----------- hugolib/page_test.go | 2 +- hugolib/shortcode_test.go | 2 +- 3 files changed, 28 insertions(+), 13 deletions(-) diff --git a/helpers/content.go b/helpers/content.go index b7f9db6e63f..187dd602892 100644 --- a/helpers/content.go +++ b/helpers/content.go @@ -544,37 +544,52 @@ func truncateWordsToWholeSentenceOld(content string, max int) (string, bool) { } func getAsciidocExecPath() string { - path, err := exec.LookPath("asciidoctor") + path, err := exec.LookPath("asciidoc") if err != nil { - path, err = exec.LookPath("asciidoc") - if err != nil { - return "" - } + return "" } return path } -// HasAsciidoc returns whether Asciidoctor or Asciidoc is installed on this computer. +// HasAsciidoc returns whether Asciidoc is installed on this computer. func HasAsciidoc() bool { return getAsciidocExecPath() != "" } +func getAsciidoctorExecPath() string { + path, err := exec.LookPath("asciidoctor") + if err != nil { + return "" + } + return path +} + +// HasAsciidoctor returns whether Asciidoctor is installed on this computer. +func HasAsciidoctor() bool { + return getAsciidoctorExecPath() != "" +} + // getAsciidocContent calls asciidoctor or asciidoc as an external helper // to convert AsciiDoc content to HTML. func getAsciidocContent(ctx *RenderingContext) []byte { content := ctx.Content cleanContent := bytes.Replace(content, SummaryDivider, []byte(""), 1) + var isAsciidoctor bool path := getAsciidocExecPath() if path == "" { - jww.ERROR.Println("asciidoctor / asciidoc not found in $PATH: Please install.\n", - " Leaving AsciiDoc content unrendered.") - return content + path := getAsciidoctorExecPath() + if path == "" { + jww.ERROR.Println("asciidoctor / asciidoc not found in $PATH: Please install.\n", + " Leaving AsciiDoc content unrendered.") + return content + } + isAsciidoctor = true } jww.INFO.Println("Rendering", ctx.DocumentName, "with", path, "...") cmd := exec.Command(path, "--no-header-footer", "--safe") - if strings.HasSuffix(path, "asciidoctor") { + if isAsciidoctor { // asciidoctor-specific arg to show stack traces on errors cmd.Args = append(cmd.Args, "--trace") } @@ -677,7 +692,7 @@ func getRstContent(ctx *RenderingContext) []byte { } } - return result[bodyStart+7 : bodyEnd] + return result[bodyStart+7: bodyEnd] } func orgRender(ctx *RenderingContext, c ContentSpec) []byte { diff --git a/hugolib/page_test.go b/hugolib/page_test.go index 88724cd1c74..1b45b286dd6 100644 --- a/hugolib/page_test.go +++ b/hugolib/page_test.go @@ -561,7 +561,7 @@ func testAllMarkdownEnginesForPages(t *testing.T, }{ {"md", func() bool { return true }}, {"mmark", func() bool { return true }}, - {"ad", func() bool { return helpers.HasAsciidoc() }}, + {"ad", func() bool { return helpers.HasAsciidoc() || helpers.HasAsciidoctor() }}, // TODO(bep) figure a way to include this without too much work.{"html", func() bool { return true }}, {"rst", func() bool { return helpers.HasRst() }}, } diff --git a/hugolib/shortcode_test.go b/hugolib/shortcode_test.go index 3d355f947ee..7ddf985678b 100644 --- a/hugolib/shortcode_test.go +++ b/hugolib/shortcode_test.go @@ -555,7 +555,7 @@ tags: th := testHelper{s.Cfg, s.Fs, t} for _, test := range tests { - if strings.HasSuffix(test.contentPath, ".ad") && !helpers.HasAsciidoc() { + if strings.HasSuffix(test.contentPath, ".ad") && !helpers.HasAsciidoc() && !helpers.HasAsciidoctor() { fmt.Println("Skip Asciidoc test case as no Asciidoc present.") continue } else if strings.HasSuffix(test.contentPath, ".rst") && !helpers.HasRst() { From 089b8782f56b81ed35e8ca3b86b3984be891f004 Mon Sep 17 00:00:00 2001 From: Vasiliy Solovey Date: Tue, 18 Jul 2017 13:09:36 +0300 Subject: [PATCH 3/3] helpers: Add smarter check for asciidoctor --- helpers/content.go | 14 ++++++++------ hugolib/page_test.go | 2 +- hugolib/shortcode_test.go | 2 +- 3 files changed, 10 insertions(+), 8 deletions(-) diff --git a/helpers/content.go b/helpers/content.go index 187dd602892..350d1a68582 100644 --- a/helpers/content.go +++ b/helpers/content.go @@ -576,24 +576,26 @@ func getAsciidocContent(ctx *RenderingContext) []byte { cleanContent := bytes.Replace(content, SummaryDivider, []byte(""), 1) var isAsciidoctor bool - path := getAsciidocExecPath() + path := getAsciidoctorExecPath() if path == "" { - path := getAsciidoctorExecPath() + path = getAsciidocExecPath() if path == "" { jww.ERROR.Println("asciidoctor / asciidoc not found in $PATH: Please install.\n", " Leaving AsciiDoc content unrendered.") return content } + } else { isAsciidoctor = true } jww.INFO.Println("Rendering", ctx.DocumentName, "with", path, "...") - cmd := exec.Command(path, "--no-header-footer", "--safe") + args := []string{"--no-header-footer", "--safe"} if isAsciidoctor { // asciidoctor-specific arg to show stack traces on errors - cmd.Args = append(cmd.Args, "--trace") + args = append(args, "--trace") } - cmd.Args = append(cmd.Args, "-") + args = append(args, "-") + cmd := exec.Command(path, args...) cmd.Stdin = bytes.NewReader(cleanContent) var out, cmderr bytes.Buffer cmd.Stdout = &out @@ -692,7 +694,7 @@ func getRstContent(ctx *RenderingContext) []byte { } } - return result[bodyStart+7: bodyEnd] + return result[bodyStart+7 : bodyEnd] } func orgRender(ctx *RenderingContext, c ContentSpec) []byte { diff --git a/hugolib/page_test.go b/hugolib/page_test.go index 1b45b286dd6..5c5c06b07a5 100644 --- a/hugolib/page_test.go +++ b/hugolib/page_test.go @@ -561,7 +561,7 @@ func testAllMarkdownEnginesForPages(t *testing.T, }{ {"md", func() bool { return true }}, {"mmark", func() bool { return true }}, - {"ad", func() bool { return helpers.HasAsciidoc() || helpers.HasAsciidoctor() }}, + {"ad", func() bool { return helpers.HasAsciidoctor() || helpers.HasAsciidoc() }}, // TODO(bep) figure a way to include this without too much work.{"html", func() bool { return true }}, {"rst", func() bool { return helpers.HasRst() }}, } diff --git a/hugolib/shortcode_test.go b/hugolib/shortcode_test.go index 7ddf985678b..485ae4b69d3 100644 --- a/hugolib/shortcode_test.go +++ b/hugolib/shortcode_test.go @@ -555,7 +555,7 @@ tags: th := testHelper{s.Cfg, s.Fs, t} for _, test := range tests { - if strings.HasSuffix(test.contentPath, ".ad") && !helpers.HasAsciidoc() && !helpers.HasAsciidoctor() { + if strings.HasSuffix(test.contentPath, ".ad") && !helpers.HasAsciidoctor() && !helpers.HasAsciidoc() { fmt.Println("Skip Asciidoc test case as no Asciidoc present.") continue } else if strings.HasSuffix(test.contentPath, ".rst") && !helpers.HasRst() {