-
-
Notifications
You must be signed in to change notification settings - Fork 504
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Pagination: let data key be a function
So that pagination data key can be determined dynamically, based on a callback function that gets passed all template data. So you can do something like: ---js { pagination: { data: (data) => { return "collections." + data.foo; }, ...
- Loading branch information
Showing
6 changed files
with
61 additions
and
14 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
const lodashIsFunction = require("lodash/isFunction"); | ||
|
||
module.exports = function (data) { | ||
return lodashIsFunction(data.pagination.data) | ||
? data.pagination.data(data) | ||
: data.pagination.data; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
const test = require("ava"); | ||
const getPaginationDataKey = require("../src/Util/GetPaginationDataKey"); | ||
|
||
test("getPaginationDataKey when key is string", (t) => { | ||
t.is(getPaginationDataKey({pagination: {data: "foo"}}), "foo"); | ||
}); | ||
|
||
test("getPaginationDataKey when key is function", (t) => { | ||
t.is( | ||
getPaginationDataKey({foo: "bar", pagination: {data: (data) => data.foo}}), | ||
"bar" | ||
); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
---js | ||
{ | ||
dataCanBeFoundIn: "items", | ||
pagination: { | ||
data: (data) => data.dataCanBeFoundIn, | ||
size: 1 | ||
}, | ||
items: ["foo", "woo"] | ||
} | ||
--- | ||
<ol>{% for item in pagination.items %}<li>{{ item }}</li>{% endfor %}</ol> |