packages feed

app-settings 0.2.0.4 → 0.2.0.5

raw patch · 4 files changed

+25/−27 lines, 4 filesPVP ok

version bump matches the API change (PVP)

API changes (from Hackage documentation)

Files

Data/AppSettings.hs view
@@ -233,14 +233,15 @@ -- --  There is also another technique that you can use if you have too long --  lines: you can put line breaks in the setting values if you start the---  following lines with spaces, like so:+--  following lines with a leading space, like so: -- --  > testList=["list1",---  >   "list2", "list3"]+--  >  "list2", "list3"] -----   In that case don't use the ListSetting option. Also keep the leading---   spaces consistent in the continuing lines. Note that the library will---   automatically wrap settings longer than 80 characters when saving.+--  In that case don't use the ListSetting option. Any character after the+--  the leading space in the next lines will go in the setting value. Note+--  that the library will automatically wrap setting values longer than 80+--  characters when saving. -- -- Once we declared the settings, we can read the configuration -- from disk (and your settings module should export your wrapper
Data/Serialization.hs view
@@ -17,6 +17,7 @@ import Data.Typeable (Typeable) import System.Directory (doesFileExist, copyFile) import Control.Applicative ((<$>))+import Data.Maybe  data SettingInfo = SettingInfo { value :: String, userSet :: Bool } deriving (Show, Eq) @@ -62,16 +63,18 @@ 	-- key=value, however we support a little bit more, 	-- you can do something like that: 	-- key=[1,2,-	--      3,4,-	--      5, 6]-	--  In that case the value will be+	--  3,4,+	--  5, 6]+	-- In that case the value will be 	--  "[1,2,3,4,5, 6]"-	blanks <- many $ oneOf " \t"-	fullVal <- if null blanks+	--  => we can continue a setting on the next+	--  line if that lines starts with a leading space.+	blank <- optionMaybe $ string " "+	fullVal <- if isNothing blank 		then return val 		else do 			firstExtraLine <- finishLine-			rest <- concat <$> many (lineSkipSpaces $ length blanks)+			rest <- concat <$> many (string " " >> finishLine) 			return $ val ++ firstExtraLine ++ rest 	return $ ConfigEntry key fullVal @@ -81,15 +84,8 @@ 	many1 $ oneOf "\r\n" 	return result -lineSkipSpaces :: Int -> T.GenParser st String-lineSkipSpaces spaceCount = do-	count spaceCount (oneOf "\t ")-	result <- finishLine-	return result- emptyLine :: T.GenParser st ConfigElement emptyLine = do-	many $ oneOf " \t" 	many1 $ oneOf "\r\n" 	return Comment @@ -110,5 +106,5 @@ wrap :: String -> String wrap str = if null rest 		then str-		else first ++ "\n  " ++ wrap rest+		else first ++ "\n " ++ wrap rest 	where (first, rest) = splitAt 80 str
app-settings.cabal view
@@ -2,7 +2,7 @@ -- documentation, see http://haskell.org/cabal/users-guide/  name:                app-settings-version:             0.2.0.4+version:             0.2.0.5 synopsis:            A library to manage application settings (INI file-like) description:            A library to deal with application settings.@@ -69,14 +69,15 @@   .   There is also another technique that you can use if you have too long   lines: you can put line breaks in the setting values if you start the-  following lines with spaces, like so:+  following lines with a leading space, like so:   .   > testList=["list1",-  >   "list2", "list3"]+  >  "list2", "list3"]   .-  In that case don't use the ListSetting option. Also keep the leading-  spaces consistent in the continuing lines. Note that the library will-  automatically wrap setting values longer than 80 characters when saving.+  In that case don't use the ListSetting option. Any character after the+  the leading space in the next lines will go in the setting value. Note+  that the library will automatically wrap setting values longer than 80+  characters when saving.   .   Once we declared the settings, we can read the configuration   from disk (and your settings module should export your wrapper
tests/Tests.hs view
@@ -128,7 +128,7 @@ 	readResult <- try $ readSettings (Path "tests/longsetting.conf")  	case readResult of  		Right (_, GetSetting getVal) -> do-			let expected = replicate 20 "longstring"+			let expected = replicate 20 "long      string" 			let actual = getVal testInlineList 			assertEqual "doesn't match" expected actual 		Left (x :: SomeException) -> assertBool (show x) False@@ -170,7 +170,7 @@ 	readResult <- try $ readSettings (Path "tests/partial.config")  	case readResult of  		Right (conf, _) -> do-			let conf1 = setSetting conf testInlineList $ replicate 20 "longstring"+			let conf1 = setSetting conf testInlineList $ replicate 20 "long      string" 			saveSettings defaultConfig (Path "xx.config") conf1 			expected <- readFile "tests/longsetting.conf" 			actual <- readFile "xx.config"