diff --git a/src/Nirum/Package/Metadata.hs b/src/Nirum/Package/Metadata.hs index 5c91a4a..1676b9d 100644 --- a/src/Nirum/Package/Metadata.hs +++ b/src/Nirum/Package/Metadata.hs @@ -78,6 +78,7 @@ import Text.Toml.Types (Node ( VArray ) , Table , VTArray + , VArray ) import Text.URI (URI, parseURI) @@ -104,7 +105,7 @@ data Metadata t = Metadata { version :: SV.Version , description :: Maybe Text , license :: Maybe Text - , keywords :: Maybe Text + , keywords :: [Text] , authors :: [Author] , target :: (Eq t, Ord t, Show t, Target t) => t } @@ -186,7 +187,7 @@ parseMetadata metadataPath' tomlText = do authors' <- authorsField "authors" table description' <- optional $ stringField "description" table license' <- optional $ stringField "license" table - keywords' <- optional $ stringField "keywords" table + keywords' <- textArrayField "keywords" table targets <- case tableField "targets" table of Left (FieldError _) -> Right HM.empty otherwise' -> otherwise' @@ -269,6 +270,20 @@ stringField = typedField "string" $ \ n -> case n of VString s -> Just s _ -> Nothing +arrayField :: MetadataField -> Table -> Either MetadataError VArray +arrayField f t = + case arrayF f t of + Right vector -> Right vector + Left (FieldError _) -> Right $ fromList [] + Left error' -> Left error' + where + arrayF :: MetadataField -> Table -> Either MetadataError VArray + arrayF = typedField "array" $ \ node -> + case node of + VArray array -> Just array + _ -> Nothing + + tableArrayField :: MetadataField -> Table -> Either MetadataError VTArray tableArrayField f t = case arrayF f t of @@ -306,6 +321,16 @@ versionField field' table = do Left _ -> Left $ FieldValueError field' $ "expected a semver string (e.g. \"1.2.3\"), not " ++ show s +textArrayField :: MetadataField -> Table -> Either MetadataError [Text] +textArrayField field' table = do + array <- arrayField field' table + textArray' <- mapM parseText array + return $ toList textArray' + where + parseText :: Node -> Either MetadataError Text + parseText (VString s) = Right s + parseText a = Left $ FieldTypeError field' "array" $ fieldType a + authorsField :: MetadataField -> Table -> Either MetadataError [Author] authorsField field' table = do array <- tableArrayField field' table diff --git a/src/Nirum/Targets/Python.hs b/src/Nirum/Targets/Python.hs index f9a3040..38bbbd8 100644 --- a/src/Nirum/Targets/Python.hs +++ b/src/Nirum/Targets/Python.hs @@ -1209,9 +1209,9 @@ setup( where target' :: Python target' = target metadata' - csStrings :: [T.Text] -> T.Text - csStrings [] = "None" - csStrings s = stringLiteral $ T.intercalate ", " s + csStrings :: T.Text -> [T.Text] -> T.Text + csStrings _ [] = "None" + csStrings d s = stringLiteral $ T.intercalate d s pName :: Code pName = packageName $ target metadata' pVersion :: Code @@ -1225,13 +1225,15 @@ setup( pLicense :: Code pLicense = fromMaybeToMeta $ license metadata' pKeywords :: Code - pKeywords = fromMaybeToMeta $ MD.keywords metadata' + pKeywords = csStrings " " $ MD.keywords metadata' strings :: [Code] -> Code strings values = T.intercalate ", " $ map stringLiteral (L.sort values) author :: Code - author = csStrings [aName | Author { name = aName } <- authors metadata'] + author = csStrings ", " [aName + | Author { name = aName } <- authors metadata' + ] authorEmail :: Code - authorEmail = csStrings [ decodeUtf8 (E.toByteString e) + authorEmail = csStrings ", " [ decodeUtf8 (E.toByteString e) | Author { email = Just e } <- authors metadata' ] pPackages :: Code diff --git a/test/Nirum/CodeBuilderSpec.hs b/test/Nirum/CodeBuilderSpec.hs index a0357b0..4c4bfae 100644 --- a/test/Nirum/CodeBuilderSpec.hs +++ b/test/Nirum/CodeBuilderSpec.hs @@ -40,7 +40,7 @@ package = Package { metadata = Metadata { version = SV.version 0 0 1 [] [] , authors = [] , description = Nothing , license = Nothing - , keywords = Nothing + , keywords = [] , target = DummyTarget } , modules = modules' diff --git a/test/Nirum/Package/MetadataSpec.hs b/test/Nirum/Package/MetadataSpec.hs index e455c0b..2accc9f 100644 --- a/test/Nirum/Package/MetadataSpec.hs +++ b/test/Nirum/Package/MetadataSpec.hs @@ -136,11 +136,11 @@ spec = , "integer (123)" ) , ( [q|version = "1.2.3" - keywords = 789 + keywords = "sample example nirum" |] , "keywords" - , "string" - , "integer (789)" + , "array" + , "string (sample example nirum)" ) ] $ \ (toml, field, expected, actual) -> do let Left e = parse toml diff --git a/test/Nirum/PackageSpec.hs b/test/Nirum/PackageSpec.hs index 97a56d8..8f8717c 100644 --- a/test/Nirum/PackageSpec.hs +++ b/test/Nirum/PackageSpec.hs @@ -65,7 +65,7 @@ createValidPackage t = createPackage Metadata { version = SV.initial , authors = [] , description = Nothing , license = Nothing - , keywords = Nothing + , keywords = [] , target = t } validModules @@ -115,7 +115,7 @@ testPackage target' = do , authors = [] , description = Nothing , license = Nothing - , keywords = Nothing + , keywords = [] , target = target' } metadata package `shouldBe` metadata' diff --git a/test/Nirum/Targets/PythonSpec.hs b/test/Nirum/Targets/PythonSpec.hs index fe73cf0..daeef5c 100644 --- a/test/Nirum/Targets/PythonSpec.hs +++ b/test/Nirum/Targets/PythonSpec.hs @@ -104,7 +104,7 @@ makeDummySource' pathPrefix m renames = ] , description = Just "Package description" , license = Just "MIT" - , keywords = Just "test example examples" + , keywords = ["sample", "example", "nirum"] , target = Python "sample-package" minimumRuntime renames } pkg :: Package Python diff --git a/test/nirum_fixture/package.toml b/test/nirum_fixture/package.toml index 1bf5214..79b9a3e 100644 --- a/test/nirum_fixture/package.toml +++ b/test/nirum_fixture/package.toml @@ -1,7 +1,7 @@ version = "0.3.0" description = "Package description" license = "MIT" -keywords = "test example examples" +keywords = ["sample", "example", "nirum"] [[authors]] name = "nirum"