settings 0.2.0.0 → 0.2.1.0
raw patch · 3 files changed
+57/−4 lines, 3 files
Files
- NEWS +23/−0
- settings.cabal +1/−1
- src/Data/Settings/Section.hs +33/−3
NEWS view
@@ -3,6 +3,29 @@ +settings 0.2.1.0 -- 2015-10-17+==============================++General, build and documentation changes:++* (None)++New APIs, features and enhancements:++* Add insertSub and insertOpt functions for section editing++Bug fixes:++* (None)++Dependency changes:++* (None)+++++ settings 0.2.0.0 -- 2015-09-17 ==============================
settings.cabal view
@@ -1,5 +1,5 @@ name: settings-version: 0.2.0.0+version: 0.2.1.0 synopsis: Runtime-editable program settings. description: This library aims to be a tool for constructing a settings management UI on
src/Data/Settings/Section.hs view
@@ -34,6 +34,8 @@ , lookupSub -- * Modification , insert+ , insertOpt+ , insertSub , deleteOpt , deleteSub , delete@@ -118,11 +120,19 @@ Just (Left s) -> Just s _ -> Nothing ++-- | Alias for 'insertOpt'.+insert :: [String] -> Option m -> Section m -> Section m+insert = insertOpt+ -- | Add the specified option at the specified path under this section. If the -- section previously contained an option for this path, the old value is -- replaced.-insert :: [String] -> Option m -> Section m -> Section m-insert path opt s@(Section opts subs) =+insertOpt :: [String] -- ^ Path at which to place the option+ -> Option m -- ^ Option to insert+ -> Section m -- ^ Root section under which to insert+ -> Section m+insertOpt path opt s@(Section opts subs) = case path of [] -> s [name] -> Section (M.insert name opt opts) subs@@ -130,7 +140,27 @@ -- Find the section or make a new one let sub = M.lookupDefault empty n subs -- Insert the option there, applying recursively- sub' = insert ns opt sub+ sub' = insertOpt ns opt sub+ -- Put the result back into the subsection map+ subs' = M.insert n sub' subs+ in Section opts subs'++-- | Add the specified subsection at the specified path under this section. If+-- the section previously contained a subsection for this path, the old value+-- is replaced.+insertSub :: [String] -- ^ Path at which to place the subsection+ -> Section m -- ^ Subsection to insert+ -> Section m -- ^ Root section under which to insert+ -> Section m+insertSub path sec s@(Section opts subs) =+ case path of+ [] -> s+ [name] -> Section opts (M.insert name sec subs)+ (n:ns) ->+ -- Find the section or make a new one+ let sub = M.lookupDefault empty n subs+ -- Insert the subsection there, applying recursively+ sub' = insertSub ns sec sub -- Put the result back into the subsection map subs' = M.insert n sub' subs in Section opts subs'