Skip to content

Commit

Permalink
Rename return option to returnType to match Fetch API
Browse files Browse the repository at this point in the history
  • Loading branch information
zachleat committed Jan 7, 2025
1 parent 0216380 commit 43dba7e
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 10 deletions.
2 changes: 1 addition & 1 deletion src/global-options.js
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ const DEFAULTS = {
transform: undefined,

// return HTML from generateHTML directly
return: "object", // or "html"
returnType: "object", // or "html"

// Defaults used when generateHTML is called from a result set
htmlOptions: {
Expand Down
3 changes: 2 additions & 1 deletion src/image.js
Original file line number Diff line number Diff line change
Expand Up @@ -337,7 +337,8 @@ class Image {
}
});

if(this.options.return === "html") {
// renamed `return` to `returnType` to match Fetch API in v6.0.0-beta.3
if(this.options.returnType === "html" || this.options.return === "html") {
return generateHTML(results);
}

Expand Down
16 changes: 8 additions & 8 deletions test/test-markup.js
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,7 @@ test("Image markup (throws on missing alt)", async t => {
test("Image markup (throws on missing alt return html)", async t => {
await t.throwsAsync(() => eleventyImage("./test/bio-2017.jpg", {
dryRun: true,
return: "html"
returnType: "html"
}), {
message: "Missing `alt` attribute on eleventy-img shortcode from: ./test/bio-2017.jpg"
});
Expand All @@ -179,7 +179,7 @@ test("Image markup (throws on missing sizes return html)", async t => {
await t.throwsAsync(() => eleventyImage("./test/bio-2017.jpg", {
dryRun: true,
widths: [100,200],
return: "html",
returnType: "html",
htmlOptions: {
imgAttributes: {
alt: "",
Expand All @@ -194,7 +194,7 @@ test("#207 Uses sizes=auto as fallback when loading=lazy to avoid error message"
let html = await eleventyImage("./test/bio-2017.jpg", {
dryRun: true,
widths: [100,200],
return: "html",
returnType: "html",
htmlOptions: {
imgAttributes: {
alt: "",
Expand Down Expand Up @@ -401,11 +401,11 @@ test("Image markup with smallest fallback dimensions", async t => {
}), `<img src="/img/KkPMmHd3hP-300.jpeg" alt="" width="300" height="199" srcset="/img/KkPMmHd3hP-300.jpeg 300w, /img/KkPMmHd3hP-1280.jpeg 1280w" sizes="100vw">`);
});

test("return: html to <img>", async t => {
test("returnType: html to <img>", async t => {
let html = await eleventyImage("./test/bio-2017.jpg", {
dryRun: true,
formats: ["auto"],
return: "html",
returnType: "html",

// passed to generateHTML
htmlOptions: {
Expand All @@ -418,10 +418,10 @@ test("return: html to <img>", async t => {
t.is(html, `<img alt="" src="/img/KkPMmHd3hP-1280.jpeg" width="1280" height="853">`);
});

test("return: html to <picture>", async t => {
test("returnType: html to <picture>", async t => {
let html = await eleventyImage("./test/bio-2017.jpg", {
dryRun: true,
return: "html",
returnType: "html",

// passed to generateHTML
htmlOptions: {
Expand All @@ -442,7 +442,7 @@ test("#239 full urls in urlPath", async t => {
let html = await eleventyImage("./test/bio-2017.jpg", {
dryRun: true,
formats: ["auto"],
return: "html",
returnType: "html",
urlPath: "http://example.com/img/",

htmlOptions: {
Expand Down

0 comments on commit 43dba7e

Please sign in to comment.