diff options
author | Bjørn Erik Pedersen <bjorn.erik.pedersen@gmail.com> | 2017-04-30 22:32:40 +0200 |
---|---|---|
committer | Bjørn Erik Pedersen <bjorn.erik.pedersen@gmail.com> | 2017-05-01 15:13:41 +0200 |
commit | 9aee8ace4e04b6b164b3c13d622021168b072baf (patch) | |
tree | 6a41a9a5ae8f7b1aace39de5186ae388cbf1fbda /tpl/encoding/init.go | |
parent | 744dccbea4a0dfecea4777a7f0d3bba99c2a9adb (diff) |
tpl/encoding: Make it a package that stands on its own
See #3042
Diffstat (limited to 'tpl/encoding/init.go')
-rw-r--r-- | tpl/encoding/init.go | 48 |
1 files changed, 48 insertions, 0 deletions
diff --git a/tpl/encoding/init.go b/tpl/encoding/init.go new file mode 100644 index 000000000..5bc0eb145 --- /dev/null +++ b/tpl/encoding/init.go @@ -0,0 +1,48 @@ +// Copyright 2017 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 encoding + +import ( + "github.com/spf13/hugo/deps" + "github.com/spf13/hugo/tpl/internal" +) + +const name = "encoding" + +func init() { + f := func(d *deps.Deps) *internal.TemplateFuncsNamespace { + ctx := New() + + examples := [][2]string{ + {`{{ (slice "A" "B" "C") | jsonify }}`, `["A","B","C"]`}, + {`{{ "SGVsbG8gd29ybGQ=" | base64Decode }}`, `Hello world`}, + {`{{ 42 | base64Encode | base64Decode }}`, `42`}, + {`{{ "Hello world" | base64Encode }}`, `SGVsbG8gd29ybGQ=`}, + } + + return &internal.TemplateFuncsNamespace{ + Name: name, + Context: func() interface{} { return ctx }, + Aliases: map[string]interface{}{ + "base64Decode": ctx.Base64Decode, + "base64Encode": ctx.Base64Encode, + "jsonify": ctx.Jsonify, + }, + Examples: examples, + } + + } + + internal.AddTemplateFuncsNamespace(f) +} |