From c5279064df9664d6b2ad277e2fba1e4bb3b0f4be Mon Sep 17 00:00:00 2001 From: Kaushal Modi Date: Tue, 2 Oct 2018 13:56:31 -0400 Subject: [PATCH] Re-organize the figure shortcode for better readability --- hugolib/embedded_shortcodes_test.go | 8 ++-- hugolib/page_test.go | 2 +- hugolib/shortcode_test.go | 18 ++++---- tpl/tplimpl/embedded/templates.autogen.go | 45 ++++++++++++------- .../embedded/templates/shortcodes/figure.html | 44 +++++++++++------- 5 files changed, 69 insertions(+), 48 deletions(-) diff --git a/hugolib/embedded_shortcodes_test.go b/hugolib/embedded_shortcodes_test.go index 1ac050ab0..3a6220b53 100644 --- a/hugolib/embedded_shortcodes_test.go +++ b/hugolib/embedded_shortcodes_test.go @@ -123,22 +123,22 @@ func TestShortcodeFigure(t *testing.T) { }{ { `{{< figure src="/img/hugo-logo.png" >}}`, - "(?s)\n
.*?.*?
\n", + "(?s)
.*?.*?
", }, { // set alt `{{< figure src="/img/hugo-logo.png" alt="Hugo logo" >}}`, - "(?s)\n
.*?\"Hugo.*?
\n", + "(?s)
.*?.*?
", }, // set title { `{{< figure src="/img/hugo-logo.png" title="Hugo logo" >}}`, - "(?s)\n
.*?.*?
.*?

Hugo logo

.*?
.*?
\n", + "(?s)
.*?.*?
.*?

Hugo logo

.*?
.*?
", }, // set attr and attrlink { `{{< figure src="/img/hugo-logo.png" attr="Hugo logo" attrlink="/img/hugo-logo.png" >}}`, - "(?s)\n
.*?.*?
.*?

.*?.*?Hugo logo.*?.*?

.*?
.*?
\n", + "(?s)
.*?.*?
.*?

.*?.*?Hugo logo.*?.*?

.*?
.*?
", }, } { diff --git a/hugolib/page_test.go b/hugolib/page_test.go index ee6e73a4d..0e73376e0 100644 --- a/hugolib/page_test.go +++ b/hugolib/page_test.go @@ -792,7 +792,7 @@ func TestPageWithShortCodeInSummary(t *testing.T) { assertFunc := func(t *testing.T, ext string, pages Pages) { p := pages[0] checkPageTitle(t, p, "Simple") - checkPageContent(t, p, normalizeExpected(ext, "

Summary Next Line. \n

\n \n \n \n \n
\n.\nMore text here.

\n\n

Some more text

\n")) + checkPageContent(t, p, normalizeExpected(ext, "

Summary Next Line.

. More text here.

Some more text

")) checkPageSummary(t, p, "Summary Next Line. . More text here. Some more text") checkPageType(t, p, "page") } diff --git a/hugolib/shortcode_test.go b/hugolib/shortcode_test.go index 8188eb48d..084662b7a 100644 --- a/hugolib/shortcode_test.go +++ b/hugolib/shortcode_test.go @@ -255,8 +255,8 @@ This is **plain** text. func TestEmbeddedSC(t *testing.T) { t.Parallel() - CheckShortCodeMatch(t, `{{% figure src="/found/here" class="bananas orange" %}}`, "\n
\n \n \n \n \n
\n", nil) - CheckShortCodeMatch(t, `{{% figure src="/found/here" class="bananas orange" caption="This is a caption" %}}`, "\n
\n \n \"This\n \n \n
\n

\n This is a caption\n \n \n \n

\n
\n \n
\n", nil) + CheckShortCodeMatch(t, `{{% figure src="/found/here" class="bananas orange" %}}`, "
\n \n
", nil) + CheckShortCodeMatch(t, `{{% figure src="/found/here" class="bananas orange" caption="This is a caption" %}}`, "
\n \"This
\n

This is a caption

\n
\n
", nil) } func TestNestedSC(t *testing.T) { @@ -302,37 +302,37 @@ func TestParentShortcode(t *testing.T) { func TestFigureOnlySrc(t *testing.T) { t.Parallel() - CheckShortCodeMatch(t, `{{< figure src="/found/here" >}}`, "\n
\n \n \n \n \n
\n", nil) + CheckShortCodeMatch(t, `{{< figure src="/found/here" >}}`, "
\n \n
", nil) } func TestFigureImgWidth(t *testing.T) { t.Parallel() - CheckShortCodeMatch(t, `{{% figure src="/found/here" class="bananas orange" alt="apple" width="100px" %}}`, "\n
\n \n \"apple\"\n \n \n
\n", nil) + CheckShortCodeMatch(t, `{{% figure src="/found/here" class="bananas orange" alt="apple" width="100px" %}}`, "
\n \"apple\" \n
", nil) } func TestFigureImgHeight(t *testing.T) { t.Parallel() - CheckShortCodeMatch(t, `{{% figure src="/found/here" class="bananas orange" alt="apple" height="100px" %}}`, "\n
\n \n \"apple\"\n \n \n
\n", nil) + CheckShortCodeMatch(t, `{{% figure src="/found/here" class="bananas orange" alt="apple" height="100px" %}}`, "
\n \"apple\" \n
", nil) } func TestFigureImgWidthAndHeight(t *testing.T) { t.Parallel() - CheckShortCodeMatch(t, `{{% figure src="/found/here" class="bananas orange" alt="apple" width="50" height="100" %}}`, "\n
\n \n \"apple\"\n \n \n
\n", nil) + CheckShortCodeMatch(t, `{{% figure src="/found/here" class="bananas orange" alt="apple" width="50" height="100" %}}`, "
\n \"apple\" \n
", nil) } func TestFigureLinkNoTarget(t *testing.T) { t.Parallel() - CheckShortCodeMatch(t, `{{< figure src="/found/here" link="/jump/here/on/clicking" >}}`, "\n
\n \n \n \n \n
\n", nil) + CheckShortCodeMatch(t, `{{< figure src="/found/here" link="/jump/here/on/clicking" >}}`, "
\n \n
", nil) } func TestFigureLinkWithTarget(t *testing.T) { t.Parallel() - CheckShortCodeMatch(t, `{{< figure src="/found/here" link="/jump/here/on/clicking" target="_self" >}}`, "\n
\n \n \n \n \n
\n", nil) + CheckShortCodeMatch(t, `{{< figure src="/found/here" link="/jump/here/on/clicking" target="_self" >}}`, "
\n \n
", nil) } func TestFigureLinkWithTargetAndRel(t *testing.T) { t.Parallel() - CheckShortCodeMatch(t, `{{< figure src="/found/here" link="/jump/here/on/clicking" target="_blank" rel="noopener" >}}`, "\n
\n \n \n \n \n
\n", nil) + CheckShortCodeMatch(t, `{{< figure src="/found/here" link="/jump/here/on/clicking" target="_blank" rel="noopener" >}}`, "
\n \n
", nil) } // #1642 diff --git a/tpl/tplimpl/embedded/templates.autogen.go b/tpl/tplimpl/embedded/templates.autogen.go index 5d319bff0..23f3cfe84 100644 --- a/tpl/tplimpl/embedded/templates.autogen.go +++ b/tpl/tplimpl/embedded/templates.autogen.go @@ -309,24 +309,35 @@ if (!doNotTrack) { {{- end -}} `}, - {`shortcodes/figure.html`, ` - - {{ if .Get "link"}}{{ end }} - - {{ if .Get "link"}}{{ end }} - {{ if or (or (.Get "title") (.Get "caption")) (.Get "attr")}} -
{{ if isset .Params "title" }} -

{{ .Get "title" }}

{{ end }} - {{ if or (.Get "caption") (.Get "attr")}}

- {{ .Get "caption" }} - {{ with .Get "attrlink"}} {{ end }} - {{ .Get "attr" }} - {{ if .Get "attrlink"}} {{ end }} -

{{ end }} -
- {{ end }} + {`shortcodes/figure.html`, ` + {{- if .Get "link" -}} + + {{- end }} + {{ with .Get + {{- if .Get "link" }}{{ end -}} + {{- if or (or (.Get "title") (.Get "caption")) (.Get "attr") -}} +
+ {{ with (.Get "title") -}} +

{{ . }}

+ {{- end -}} + {{- if or (.Get "caption") (.Get "attr") -}}

+ {{- .Get "caption" -}} + {{- with .Get "attrlink" -}} + + {{- end -}} + {{- .Get "attr" -}} + {{- if .Get "attrlink" }}{{ end }}

+ {{- end }} +
+ {{- end }} -`}, +`}, {`shortcodes/gist.html`, ``}, {`shortcodes/highlight.html`, `{{ if len .Params | eq 2 }}{{ highlight (trim .Inner "\n\r") (.Get 0) (.Get 1) }}{{ else }}{{ highlight (trim .Inner "\n\r") (.Get 0) "" }}{{ end }}`}, {`shortcodes/instagram.html`, `{{- $pc := .Page.Site.Config.Privacy.Instagram -}} diff --git a/tpl/tplimpl/embedded/templates/shortcodes/figure.html b/tpl/tplimpl/embedded/templates/shortcodes/figure.html index 258d25bfe..9fa847eaa 100644 --- a/tpl/tplimpl/embedded/templates/shortcodes/figure.html +++ b/tpl/tplimpl/embedded/templates/shortcodes/figure.html @@ -1,18 +1,28 @@ - - - {{ if .Get "link"}}{{ end }} - - {{ if .Get "link"}}{{ end }} - {{ if or (or (.Get "title") (.Get "caption")) (.Get "attr")}} -
{{ if isset .Params "title" }} -

{{ .Get "title" }}

{{ end }} - {{ if or (.Get "caption") (.Get "attr")}}

- {{ .Get "caption" }} - {{ with .Get "attrlink"}} {{ end }} - {{ .Get "attr" }} - {{ if .Get "attrlink"}} {{ end }} -

{{ end }} -
- {{ end }} + + {{- if .Get "link" -}} + + {{- end }} + {{ with .Get + {{- if .Get "link" }}{{ end -}} + {{- if or (or (.Get "title") (.Get "caption")) (.Get "attr") -}} +
+ {{ with (.Get "title") -}} +

{{ . }}

+ {{- end -}} + {{- if or (.Get "caption") (.Get "attr") -}}

+ {{- .Get "caption" -}} + {{- with .Get "attrlink" -}} + + {{- end -}} + {{- .Get "attr" -}} + {{- if .Get "attrlink" }}{{ end }}

+ {{- end }} +
+ {{- end }} - \ No newline at end of file