mirror of
https://github.com/gohugoio/hugo.git
synced 2025-08-26 22:04:32 +02:00
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
This commit is contained in:
@@ -14,9 +14,13 @@
|
||||
package integrity
|
||||
|
||||
import (
|
||||
"html/template"
|
||||
"testing"
|
||||
|
||||
"github.com/gohugoio/hugo/resources/resource"
|
||||
|
||||
qt "github.com/frankban/quicktest"
|
||||
"github.com/gohugoio/hugo/resources/resource_transformers/htesting"
|
||||
)
|
||||
|
||||
func TestHashFromAlgo(t *testing.T) {
|
||||
@@ -46,3 +50,23 @@ func TestHashFromAlgo(t *testing.T) {
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
func TestTransform(t *testing.T) {
|
||||
c := qt.New(t)
|
||||
|
||||
spec, err := htesting.NewTestResourceSpec()
|
||||
c.Assert(err, qt.IsNil)
|
||||
client := New(spec)
|
||||
|
||||
r, err := htesting.NewResourceTransformerForSpec(spec, "hugo.txt", "Hugo Rocks!")
|
||||
c.Assert(err, qt.IsNil)
|
||||
|
||||
transformed, err := client.Fingerprint(r, "")
|
||||
|
||||
c.Assert(err, qt.IsNil)
|
||||
c.Assert(transformed.RelPermalink(), qt.Equals, "/hugo.a5ad1c6961214a55de53c1ce6e60d27b6b761f54851fa65e33066460dfa6a0db.txt")
|
||||
c.Assert(transformed.Data(), qt.DeepEquals, map[string]interface{}{"Integrity": template.HTMLAttr("sha256-pa0caWEhSlXeU8HObmDSe2t2H1SFH6ZeMwZkYN+moNs=")})
|
||||
content, err := transformed.(resource.ContentProvider).Content()
|
||||
c.Assert(err, qt.IsNil)
|
||||
c.Assert(content, qt.Equals, "Hugo Rocks!")
|
||||
}
|
||||
|
Reference in New Issue
Block a user