diff options
author | Bjørn Erik Pedersen <bjorn.erik.pedersen@gmail.com> | 2019-08-18 11:21:27 +0200 |
---|---|---|
committer | Bjørn Erik Pedersen <bjorn.erik.pedersen@gmail.com> | 2019-08-26 15:00:44 +0200 |
commit | f9978ed16476ca6d233a89669c62c798cdf9db9d (patch) | |
tree | 02edb31008b997a3e77055060a34971fe9e8c5a4 /resources/resource_transformers/templates | |
parent | 58d4c0a8be8beefbd7437b17bf7a9a381164d09b (diff) |
Image resource refactor
This commit pulls most of the image related logic into its own package, to make it easier to reason about and extend.
This is also a rewrite of the transformation logic used in Hugo Pipes, mostly to allow constructs like the one below:
{{ ($myimg | fingerprint ).Width }}
Fixes #5903
Fixes #6234
Fixes #6266
Diffstat (limited to 'resources/resource_transformers/templates')
-rw-r--r-- | resources/resource_transformers/templates/execute_as_template.go | 22 |
1 files changed, 10 insertions, 12 deletions
diff --git a/resources/resource_transformers/templates/execute_as_template.go b/resources/resource_transformers/templates/execute_as_template.go index b3ec3cf43..422f1bbe1 100644 --- a/resources/resource_transformers/templates/execute_as_template.go +++ b/resources/resource_transformers/templates/execute_as_template.go @@ -17,6 +17,7 @@ package templates import ( "github.com/gohugoio/hugo/helpers" "github.com/gohugoio/hugo/resources" + "github.com/gohugoio/hugo/resources/internal" "github.com/gohugoio/hugo/resources/resource" "github.com/gohugoio/hugo/tpl" "github.com/pkg/errors" @@ -47,8 +48,8 @@ type executeAsTemplateTransform struct { data interface{} } -func (t *executeAsTemplateTransform) Key() resources.ResourceTransformationKey { - return resources.NewResourceTransformationKey("execute-as-template", t.targetPath) +func (t *executeAsTemplateTransform) Key() internal.ResourceTransformationKey { + return internal.NewResourceTransformationKey("execute-as-template", t.targetPath) } func (t *executeAsTemplateTransform) Transform(ctx *resources.ResourceTransformationCtx) error { @@ -63,14 +64,11 @@ func (t *executeAsTemplateTransform) Transform(ctx *resources.ResourceTransforma return templ.Execute(ctx.To, t.data) } -func (c *Client) ExecuteAsTemplate(res resource.Resource, targetPath string, data interface{}) (resource.Resource, error) { - return c.rs.Transform( - res, - &executeAsTemplateTransform{ - rs: c.rs, - targetPath: helpers.ToSlashTrimLeading(targetPath), - textTemplate: c.textTemplate, - data: data, - }, - ) +func (c *Client) ExecuteAsTemplate(res resources.ResourceTransformer, targetPath string, data interface{}) (resource.Resource, error) { + return res.Transform(&executeAsTemplateTransform{ + rs: c.rs, + targetPath: helpers.ToSlashTrimLeading(targetPath), + textTemplate: c.textTemplate, + data: data, + }) } |