From 0602135fd44b0cfa0a51b0ec6e451ae58ac95666 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bj=C3=B8rn=20Erik=20Pedersen?= Date: Thu, 22 Feb 2018 09:15:12 +0100 Subject: Make ge, le etc. work with the Hugo Version number This means that you can do something ala: ```html {{ if ge .Hugo.Version "0.36" }}Reasonable new Hugo version!{{ end }} ``` The intented use is feature toggling, but please note that it will take some time and Hugo versions until this can be trusted. It does not work in older Hugo versions. Fixes #4443 --- hugolib/hugo_info.go | 6 +++--- hugolib/hugo_info_test.go | 33 +++++++++++++++++++++++++++++++++ 2 files changed, 36 insertions(+), 3 deletions(-) create mode 100644 hugolib/hugo_info_test.go (limited to 'hugolib') diff --git a/hugolib/hugo_info.go b/hugolib/hugo_info.go index 1e0c192e5..303231edb 100644 --- a/hugolib/hugo_info.go +++ b/hugolib/hugo_info.go @@ -1,4 +1,4 @@ -// Copyright 2015 The Hugo Authors. All rights reserved. +// Copyright 2018 The Hugo Authors. All rights reserved. // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. @@ -33,7 +33,7 @@ var hugoInfo *HugoInfo // HugoInfo contains information about the current Hugo environment type HugoInfo struct { - Version string + Version helpers.HugoVersionString Generator template.HTML CommitHash string BuildDate string @@ -41,7 +41,7 @@ type HugoInfo struct { func init() { hugoInfo = &HugoInfo{ - Version: helpers.CurrentHugoVersion.String(), + Version: helpers.CurrentHugoVersion.Version(), CommitHash: CommitHash, BuildDate: BuildDate, Generator: template.HTML(fmt.Sprintf(``, helpers.CurrentHugoVersion.String())), diff --git a/hugolib/hugo_info_test.go b/hugolib/hugo_info_test.go new file mode 100644 index 000000000..0a34330ac --- /dev/null +++ b/hugolib/hugo_info_test.go @@ -0,0 +1,33 @@ +// Copyright 2018 The Hugo Authors. All rights reserved. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +package hugolib + +import ( + "fmt" + "testing" + + "github.com/gohugoio/hugo/helpers" + "github.com/stretchr/testify/require" +) + +func TestHugoInfo(t *testing.T) { + assert := require.New(t) + + assert.Equal(helpers.CurrentHugoVersion.Version(), hugoInfo.Version) + assert.IsType(helpers.HugoVersionString(""), hugoInfo.Version) + assert.Equal(CommitHash, hugoInfo.CommitHash) + assert.Equal(BuildDate, hugoInfo.BuildDate) + assert.Contains(hugoInfo.Generator, fmt.Sprintf("Hugo %s", hugoInfo.Version)) + +} -- cgit v1.2.3