diff options
Diffstat (limited to 'Biz/Namespace.hs')
-rw-r--r-- | Biz/Namespace.hs | 26 |
1 files changed, 21 insertions, 5 deletions
diff --git a/Biz/Namespace.hs b/Biz/Namespace.hs index 6fb40f7..cdc4464 100644 --- a/Biz/Namespace.hs +++ b/Biz/Namespace.hs @@ -1,4 +1,5 @@ {-# LANGUAGE DeriveAnyClass #-} +{-# LANGUAGE LambdaCase #-} {-# LANGUAGE OverloadedStrings #-} {-# LANGUAGE RecordWildCards #-} {-# LANGUAGE NoImplicitPrelude #-} @@ -37,10 +38,10 @@ data Ext | Rs | Scm | Sh - deriving (Eq, Show, Generic, Aeson.ToJSON) + deriving (Eq, Show, Generic, Aeson.ToJSON, Ord) data Namespace = Namespace {path :: [String], ext :: Ext} - deriving (Eq, Show, Generic, Aeson.ToJSON) + deriving (Eq, Show, Generic, Aeson.ToJSON, Ord) fromPath :: String -> String -> Maybe Namespace fromPath bizRoot absPath = @@ -50,9 +51,24 @@ fromPath bizRoot absPath = toPath :: Namespace -> FilePath toPath (Namespace parts ext) = - joinWith "/" parts - <> "." - <> lowercase (show ext) + joinWith "/" parts <> toExt ext + +toExt :: Ext -> String +toExt = + ("." <>) <. \case + C -> "c" + Css -> "css" + Hs -> "hs" + Json -> "json" + Keys -> "pub" + Lisp -> "lisp" + Md -> "md" + Nix -> "nix" + None -> "none" + Py -> "py" + Rs -> "rs" + Scm -> "scm" + Sh -> "sh" fromHaskellContent :: String -> Maybe Namespace fromHaskellContent c = case Regex.findFirstInfix haskellModule c of |