Generate allImages list.

This commit is contained in:
Dillon Kearns 2019-08-22 07:42:00 -07:00
parent c8c7efc067
commit e1ac97706d
2 changed files with 23 additions and 2 deletions

View File

@ -1,5 +1,5 @@
const exposingList =
"(application, PageRoute, all, pages, routeToString, Image, imageUrl, images)";
"(application, PageRoute, all, pages, routeToString, Image, imageUrl, images, allImages)";
function staticRouteStuff(staticRoutes) {
return `
@ -21,6 +21,11 @@ ${staticRoutes.urlParser}
${staticRoutes.imageAssetsRecord}
allImages : List Image
allImages =
[${staticRoutes.allImages.join("\n , ")}
]
routeToString : PageRoute -> String
routeToString (PageRoute route) =
"/"

View File

@ -101,7 +101,8 @@ function generate(scanned) {
// routeToMetadata: formatCaseStatement("toMetadata", routeToMetadata),
// routeToDocExtension: formatCaseStatement("toExt", routeToExt),
// routeToSource: formatCaseStatement("toSourcePath", routeToSource),
imageAssetsRecord: toElmRecord("images", getImageAssets(), true)
imageAssetsRecord: toElmRecord("images", getImageAssets(), true),
allImages: allImageAssetNames()
};
}
function getImageAssets() {
@ -123,6 +124,21 @@ function getImageAssets() {
});
return assetsRecord;
}
function allImageAssetNames() {
return glob
.sync("images/**/*", {})
.filter(filePath => !fs.lstatSync(filePath).isDirectory())
.map(relativeImagePath)
.map(info => {
return (
"(Image [ " +
info.fragmentsWithExtension
.map(fragment => `"${fragment}"`)
.join(", ") +
" ])"
);
});
}
function toPascalCase(str) {
var pascal = str.replace(/(\-\w)/g, function(m) {
return m[1].toUpperCase();