From ac475cec986772085c70b10d0ebb347ec4d0fc53 Mon Sep 17 00:00:00 2001 From: Evan Czaplicki Date: Tue, 30 Jan 2018 19:12:45 -0800 Subject: [PATCH] Fix variable shadowing and moved imports in Elm code --- src/frontend/Main.elm | 3 ++- src/frontend/Page/Docs.elm | 6 +++--- src/frontend/Page/Docs/Block.elm | 26 +++++++++++------------ src/frontend/Route.elm | 36 ++++++++++++++++++-------------- 4 files changed, 38 insertions(+), 33 deletions(-) diff --git a/src/frontend/Main.elm b/src/frontend/Main.elm index 09b0e4fc..68b17b2e 100644 --- a/src/frontend/Main.elm +++ b/src/frontend/Main.elm @@ -16,6 +16,7 @@ import Session import Session.Query as Query import Session.Status exposing (Status(..)) import Task +import Url.Parser as Parser import Utils.App as App import Utils.OneOrMore as OneOrMore import Version @@ -76,7 +77,7 @@ subscriptions model = -- NAVIGATION -onNavigation : Browser.Url -> Msg +onNavigation : Parser.Url -> Msg onNavigation url = ReactToUrl (Route.fromUrl url) diff --git a/src/frontend/Page/Docs.elm b/src/frontend/Page/Docs.elm index e0fab10d..83d8f4cf 100644 --- a/src/frontend/Page/Docs.elm +++ b/src/frontend/Page/Docs.elm @@ -153,17 +153,17 @@ viewSidebar metadata allDocs query = viewSidebarModules : Metadata -> List Docs.Module -> String -> Html Msg -viewSidebarModules metadata docs query = +viewSidebarModules metadata modules query = if String.isEmpty query then let viewEntry docs = li [] [ viewModuleLink metadata docs.name ] in - ul [] (List.map viewEntry docs) + ul [] (List.map viewEntry modules) else ul [] <| - List.filterMap (viewSearchItem metadata (String.toLower query)) docs + List.filterMap (viewSearchItem metadata (String.toLower query)) modules viewSearchItem : Metadata -> String -> Docs.Module -> Maybe (Html Msg) diff --git a/src/frontend/Page/Docs/Block.elm b/src/frontend/Page/Docs/Block.elm index 22f1eeb9..9fe8232b 100644 --- a/src/frontend/Page/Docs/Block.elm +++ b/src/frontend/Page/Docs/Block.elm @@ -172,8 +172,8 @@ type alias TypeNameDict = makeInfo : String -> String -> Route.Version -> String -> List Docs.Module -> Info makeInfo user project version moduleName docsList = let - addUnion moduleName union docs = - Dict.insert (moduleName ++ "." ++ union.name) (moduleName, union.name) docs + addUnion home union docs = + Dict.insert (home ++ "." ++ union.name) (home, union.name) docs addModule docs dict = List.foldl (addUnion docs.name) dict docs.unions @@ -303,8 +303,8 @@ toLines info context tipe = Type.Record (f :: fs) extension -> let - toLns ( field, tipe ) = - ( field, toLines info Other tipe ) + toLns ( field, fieldType ) = + ( field, toLines info Other fieldType ) in case extension of Nothing -> @@ -648,26 +648,26 @@ toOneLine chunkWidth chunk one entries = toMoreLines : MoreSettings a msg -> a -> List a -> Lines (Line msg) -toMoreLines {open, sep, close, openIndent, sepIndent, toLines} x xs = +toMoreLines s x xs = let (OneOrMore firstLine firstRest) = - toLines x + s.toLines x openIndentation = - text (String.repeat openIndent " ") + text (String.repeat s.openIndent " ") sepIndentation = - text (String.repeat sepIndent " ") + text (String.repeat s.sepIndent " ") - toChunk (OneOrMore x xs) = - (sep :: x) :: List.map ((::) sepIndentation) xs + toChunk (OneOrMore y ys) = + (s.sep :: y) :: List.map ((::) sepIndentation) ys otherLines = List.map ((::) openIndentation) firstRest - ++ List.concatMap (toChunk << toLines) xs + ++ List.concatMap (toChunk << s.toLines) xs in - More (open ++ firstLine) <| - case close of + More (s.open ++ firstLine) <| + case s.close of Nothing -> otherLines diff --git a/src/frontend/Route.elm b/src/frontend/Route.elm index e61035af..ed0177ef 100644 --- a/src/frontend/Route.elm +++ b/src/frontend/Route.elm @@ -11,9 +11,8 @@ module Route exposing ) -import Browser import Url -import Url.Parser exposing (Parser, (), custom, fragment, map, oneOf, parsePath, s, top) +import Url.Parser as Parser exposing (Parser, (), custom, fragment, map, oneOf, s, top) import Version @@ -65,35 +64,40 @@ getHash info = -- LOCATION TO ROUTE -fromUrl : Browser.Url -> Route +fromUrl : Parser.Url -> Route fromUrl url = - parsePath parser NotFound url + case Parser.parse parser url of + Nothing -> + NotFound (Parser.fromUrl url) + + Just route -> + route parser : Parser (Route -> a) a parser = oneOf [ map Home <| top - , map User <| s "packages" user - , map Package <| s "packages" user project - , map Version <| s "packages" user project version versionInfo + , map User <| s "packages" user_ + , map Package <| s "packages" user_ project_ + , map Version <| s "packages" user_ project_ version_ versionInfo , map Guidelines <| s "help" s "design-guidelines" , map DocsHelp <| s "help" s "docs" ] -user : Parser (String -> a) a -user = +user_ : Parser (String -> a) a +user_ = custom "USER" Just -project : Parser (String -> a) a -project = +project_ : Parser (String -> a) a +project_ = custom "PROJECT" Just -version : Parser (Version -> a) a -version = +version_ : Parser (Version -> a) a +version_ = custom "VERSION" <| \string -> if string == "latest" then Just Latest @@ -105,12 +109,12 @@ versionInfo : Parser (VersionInfo -> a) a versionInfo = oneOf [ map Readme top - , map Module (moduleName fragment identity) + , map Module (moduleName_ fragment identity) ] -moduleName : Parser (String -> a) a -moduleName = +moduleName_ : Parser (String -> a) a +moduleName_ = custom "MODULE" (Just << String.replace "-" ".")