From 172d96e6f0868af6b68d4fad0b634fb11d48c143 Mon Sep 17 00:00:00 2001 From: Dillon Kearns Date: Fri, 6 Sep 2019 14:17:33 +0530 Subject: [PATCH] Manually edit generated code with new Path type experiment. --- elm-package/src/Pages.elm | 4 +- elm-package/src/Pages/Manifest.elm | 8 +- elm-package/src/Pages/Path.elm | 10 +- examples/docs/gen/PagesNew.elm | 144 +++++++++++++++++------------ 4 files changed, 101 insertions(+), 65 deletions(-) diff --git a/elm-package/src/Pages.elm b/elm-package/src/Pages.elm index 09e6f066..49dd2b47 100644 --- a/elm-package/src/Pages.elm +++ b/elm-package/src/Pages.elm @@ -296,7 +296,7 @@ application : , content : Content , toJsPort : Json.Encode.Value -> Cmd (Msg userMsg metadata view) , head : metadata -> List Head.Tag - , manifest : Manifest.Config + , manifest : Manifest.Config pathKey } -> Program userModel userMsg metadata view application config = @@ -346,7 +346,7 @@ cliApplication : , content : Content , toJsPort : Json.Encode.Value -> Cmd (Msg userMsg metadata view) , head : metadata -> List Head.Tag - , manifest : Manifest.Config + , manifest : Manifest.Config pathKey } -> Program userModel userMsg metadata view cliApplication config = diff --git a/elm-package/src/Pages/Manifest.elm b/elm-package/src/Pages/Manifest.elm index 1fb672c2..d4177ce2 100644 --- a/elm-package/src/Pages/Manifest.elm +++ b/elm-package/src/Pages/Manifest.elm @@ -4,6 +4,7 @@ import Color exposing (Color) import Color.Convert import Json.Encode as Encode import Pages.Manifest.Category as Category exposing (Category) +import Pages.Path as Path exposing (Path) @@ -70,7 +71,7 @@ orientationToString orientation = "portrait-secondary" -type alias Config = +type alias Config pathKey = { backgroundColor : Maybe Color , categories : List Category , displayMode : DisplayMode @@ -85,7 +86,7 @@ type alias Config = -- https://developer.mozilla.org/en-US/docs/Web/Manifest/short_name , shortName : Maybe String - , sourceIcon : String + , sourceIcon : Path pathKey } @@ -105,10 +106,11 @@ displayModeToAttribute displayMode = "browser" -toJson : Config -> Encode.Value +toJson : Config pathKey -> Encode.Value toJson config = [ ( "sourceIcon" , config.sourceIcon + |> Path.toString |> Encode.string |> Just ) diff --git a/elm-package/src/Pages/Path.elm b/elm-package/src/Pages/Path.elm index 0b04180f..12a8e74a 100644 --- a/elm-package/src/Pages/Path.elm +++ b/elm-package/src/Pages/Path.elm @@ -1,4 +1,4 @@ -module Pages.Path exposing (Path(..), ResourceType(..), buildPath) +module Pages.Path exposing (Path(..), ResourceType(..), buildPath, toString) type ResourceType @@ -10,6 +10,14 @@ type Path key = Path ResourceType (List String) +toString : Path key -> String +toString (Path resourceType rawPath) = + "/" + ++ (rawPath + |> String.join "/" + ) + + buildPath : ResourceType -> key -> List String -> Path key buildPath resourceType key path = Path resourceType path diff --git a/examples/docs/gen/PagesNew.elm b/examples/docs/gen/PagesNew.elm index 0b2543d8..f343ce75 100644 --- a/examples/docs/gen/PagesNew.elm +++ b/examples/docs/gen/PagesNew.elm @@ -1,7 +1,7 @@ -port module PagesNew exposing (application, PageRoute, all, pages, routeToString, Image, imageUrl, images, allImages, isValidRoute) +port module PagesNew exposing (Image, PageRoute, PathKey, all, allImages, application, imageUrl, images, isValidRoute, pages, routeToString) -import Dict exposing (Dict) import Color exposing (Color) +import Dict exposing (Dict) import Head import Html exposing (Html) import Json.Decode @@ -9,10 +9,20 @@ import Json.Encode import Mark import Pages import Pages.ContentCache exposing (Page) +import Pages.Document import Pages.Manifest exposing (DisplayMode, Orientation) import Pages.Manifest.Category as Category exposing (Category) +import Pages.Path as Path exposing (Path) import Url.Parser as Url exposing ((), s) -import Pages.Document + + +type PathKey + = PathKey + + +buildImage : Image -> Path PathKey +buildImage (Image path) = + Path.buildPath Path.Image PathKey path port toJsPort : Json.Encode.Value -> Cmd msg @@ -61,70 +71,82 @@ application config = , themeColor = config.manifest.themeColor , startUrl = Just (routeToString config.manifest.startUrl) , shortName = config.manifest.shortName - , sourceIcon = "./" ++ imageUrl config.manifest.sourceIcon + + -- , sourceIcon = "./" ++ imageUrl config.manifest.sourceIcon + , sourceIcon = buildImage config.manifest.sourceIcon } } -type PageRoute = PageRoute (List String) +type PageRoute + = PageRoute (List String) + + +type Image + = Image (List String) -type Image = Image (List String) imageUrl : Image -> String imageUrl (Image path) = "/" ++ String.join "/" ("images" :: path) + all : List PageRoute all = - [ (PageRoute [ "blog", "types-over-conventions" ]) - , (PageRoute [ "docs", "directory-structure" ]) - , (PageRoute [ "docs" ]) - , (PageRoute [ ]) - , (PageRoute [ "markdown" ]) + [ PageRoute [ "blog", "types-over-conventions" ] + , PageRoute [ "docs", "directory-structure" ] + , PageRoute [ "docs" ] + , PageRoute [] + , PageRoute [ "markdown" ] ] + pages = { blog = - { typesOverConventions = (PageRoute [ "blog", "types-over-conventions" ]) - , all = [ (PageRoute [ "blog", "types-over-conventions" ]) ] + { typesOverConventions = PageRoute [ "blog", "types-over-conventions" ] + , all = [ PageRoute [ "blog", "types-over-conventions" ] ] } , docs = - { directoryStructure = (PageRoute [ "docs", "directory-structure" ]) - , index = (PageRoute [ "docs" ]) - , all = [ (PageRoute [ "docs", "directory-structure" ]), (PageRoute [ "docs" ]) ] + { directoryStructure = PageRoute [ "docs", "directory-structure" ] + , index = PageRoute [ "docs" ] + , all = [ PageRoute [ "docs", "directory-structure" ], PageRoute [ "docs" ] ] } - , index = (PageRoute [ ]) - , markdown = (PageRoute [ "markdown" ]) - , all = [ (PageRoute [ ]), (PageRoute [ "markdown" ]) ] + , index = PageRoute [] + , markdown = PageRoute [ "markdown" ] + , all = [ PageRoute [], PageRoute [ "markdown" ] ] } + urlParser : Url.Parser (PageRoute -> a) a urlParser = Url.oneOf [ Url.map (PageRoute [ "blog", "types-over-conventions" ]) (s "blog" s "types-over-conventions") , Url.map (PageRoute [ "docs", "directory-structure" ]) (s "docs" s "directory-structure") , Url.map (PageRoute [ "docs" ]) (s "docs" s "index") - , Url.map (PageRoute [ ]) (s "index") + , Url.map (PageRoute []) (s "index") , Url.map (PageRoute [ "markdown" ]) (s "markdown") - ] + ] + images = - { icon = (Image [ "icon.svg" ]) - , mountains = (Image [ "mountains.jpg" ]) - , all = [ (Image [ "icon.svg" ]), (Image [ "mountains.jpg" ]) ] + { icon = Image [ "icon.svg" ] + , mountains = Image [ "mountains.jpg" ] + , all = [ Image [ "icon.svg" ], Image [ "mountains.jpg" ] ] } + allImages : List Image allImages = - [(Image [ "icon.svg" ]) - , (Image [ "mountains.jpg" ]) + [ Image [ "icon.svg" ] + , Image [ "mountains.jpg" ] ] + routeToString : PageRoute -> String routeToString (PageRoute route) = "/" - ++ (route |> String.join "/") + ++ (route |> String.join "/") isValidRoute : String -> Result String () @@ -147,37 +169,41 @@ isValidRoute route = |> Err -content : List ( List String, { extension: String, frontMatter : String, body : Maybe String } ) +content : List ( List String, { extension : String, frontMatter : String, body : Maybe String } ) content = - [ - ( ["blog", "types-over-conventions"] - , { frontMatter = """{"author":"Dillon Kearns","title":"Types Over Conventions","description":"TODO"} -""" , body = Nothing - , extension = "md" - } ) - , - ( ["docs", "directory-structure"] - , { frontMatter = """{"title":"Directory Structure","type":"doc"} -""" , body = Nothing - , extension = "md" - } ) - , - ( ["docs"] - , { frontMatter = """{"title":"Quick Start","type":"doc"} -""" , body = Nothing - , extension = "md" - } ) - , - ( [] - , { frontMatter = """{"title":"elm-pages - a statically typed site generator"} -""" , body = Nothing - , extension = "md" - } ) - , - ( ["markdown"] - , { frontMatter = """{"title":"Hello from markdown! 👋"} -""" , body = Nothing - , extension = "md" - } ) - + [ ( [ "blog", "types-over-conventions" ] + , { frontMatter = """{"author":"Dillon Kearns","title":"Types Over Conventions","description":"TODO"} +""" + , body = Nothing + , extension = "md" + } + ) + , ( [ "docs", "directory-structure" ] + , { frontMatter = """{"title":"Directory Structure","type":"doc"} +""" + , body = Nothing + , extension = "md" + } + ) + , ( [ "docs" ] + , { frontMatter = """{"title":"Quick Start","type":"doc"} +""" + , body = Nothing + , extension = "md" + } + ) + , ( [] + , { frontMatter = """{"title":"elm-pages - a statically typed site generator"} +""" + , body = Nothing + , extension = "md" + } + ) + , ( [ "markdown" ] + , { frontMatter = """{"title":"Hello from markdown! 👋"} +""" + , body = Nothing + , extension = "md" + } + ) ]