Skip to content

Commit

Permalink
0.4.0
Browse files Browse the repository at this point in the history
Closes #11
  • Loading branch information
icidasset committed Dec 28, 2021
1 parent ed0c031 commit 121f34a
Show file tree
Hide file tree
Showing 11 changed files with 63 additions and 43 deletions.
13 changes: 10 additions & 3 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,16 +1,21 @@
# Changelog

### v0.4.0

Update dependencies, in particular, aeson v2.


### v0.3.11

- Add CHANGELOG and README to the stack tarball
Add CHANGELOG and README to the stack tarball.

### v0.3.10

- Added missing test files to the stack tarball
Added missing test files to the stack tarball.

### v0.3.9

- Adjusted version ranges for test dependencies
Adjusted version ranges for test dependencies.

### v0.3.8

Expand Down Expand Up @@ -52,6 +57,7 @@
- Added `listRelative` and it's flipped relative
- Updated dependencies


### v0.2.1

- Fix order of the `list` function parameters
Expand All @@ -62,6 +68,7 @@
- Add more `Utilities` (sequence utils, metadata helpers, etc.)
- Clean up code


### v0.1.3

- Fix `Contrib.prefixDirname` which didn't change `pathToRoot` and `parentPath` like it should
Expand Down
6 changes: 3 additions & 3 deletions package.yaml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
name: shikensu
version: 0.3.11
version: 0.4.0
maintainer: Steven Vandevelde <[email protected]>
category: Filesystem

Expand All @@ -17,9 +17,9 @@ default-extensions:


dependencies:
- aeson == 1.*
- aeson == 2.*
- base >= 4.9 && < 5
- bytestring == 0.10.*
- bytestring >= 0.10 && < 0.12
- directory == 1.*
- filepath == 1.*
- flow == 1.*
Expand Down
6 changes: 3 additions & 3 deletions src/Shikensu.hs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ import Shikensu.Internal.Types
import Shikensu.Internal.Utilities
import System.FilePath

import qualified Data.HashMap.Strict as HashMap (empty)
import qualified Data.Aeson.KeyMap as KeyMap (empty)
import qualified Data.List as List (concatMap, map, zip)
import qualified System.Directory as Dir (canonicalizePath)
import qualified System.FilePath.Glob as Glob (compile, globDir1)
Expand Down Expand Up @@ -115,7 +115,7 @@ Example definition, given:
> , workingDirname = "example"
>
> , content = Nothing
> , metadata = HashMap.empty
> , metadata = KeyMap.empty
> , parentPath = "../"
> , pathToRoot = "../../"
> }
Expand All @@ -140,7 +140,7 @@ makeDefinition rootDirname pattern absolutePath =

-- Additional properties
, content = Nothing
, metadata = HashMap.empty
, metadata = KeyMap.empty
, parentPath = compileParentPath $ takeDirName theLocalPath
, pathToRoot = compilePathToRoot $ takeDirName theLocalPath
}
Expand Down
8 changes: 4 additions & 4 deletions src/Shikensu/Contrib.hs
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ import Shikensu.Internal.Utilities (compileParentPath, compilePathToRoot)
import Shikensu.Metadata (transposeToMetadata)
import System.FilePath (FilePath, combine)

import qualified Data.HashMap.Strict as HashMap (empty, union)
import qualified Data.Aeson.KeyMap as KeyMap (empty, union)


{-| Clear metadata.
Expand All @@ -50,7 +50,7 @@ clearMetadata =

clearMetadataDef :: Definition -> Definition
clearMetadataDef def =
def { metadata = HashMap.empty }
def { metadata = KeyMap.empty }



Expand Down Expand Up @@ -87,7 +87,7 @@ copyPropsToMetadata =
copyPropsToMetadataDef :: Definition -> Definition
copyPropsToMetadataDef def =
def
{ metadata = HashMap.union (transposeToMetadata def) (metadata def) }
{ metadata = KeyMap.union (transposeToMetadata def) (metadata def) }



Expand All @@ -112,7 +112,7 @@ insertMetadata a =

insertMetadataDef :: Metadata -> Definition -> Definition
insertMetadataDef given def =
def { metadata = HashMap.union given (metadata def) }
def { metadata = KeyMap.union given (metadata def) }



Expand Down
5 changes: 3 additions & 2 deletions src/Shikensu/Internal/Types.hs
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,12 @@
module Shikensu.Internal.Types where

import Data.Aeson ((.=), toJSON)
import Data.Aeson.KeyMap (KeyMap)
import Data.ByteString (ByteString)
import Data.Monoid ((<>))
import System.FilePath (joinPath)

import qualified Data.Aeson as Aeson (Object, ToJSON, object)
import qualified Data.Aeson as Aeson (ToJSON, Value, object)


{-| A file definition, along with some additional properties.
Expand Down Expand Up @@ -49,7 +50,7 @@ instance Aeson.ToJSON Definition where


type Dictionary = [Definition]
type Metadata = Aeson.Object
type Metadata = KeyMap Aeson.Value



Expand Down
12 changes: 6 additions & 6 deletions src/Shikensu/Metadata.hs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import Flow
import Shikensu.Internal.Types

import qualified Data.Aeson as Aeson (FromJSON, Result(..), ToJSON, fromJSON, toJSON)
import qualified Data.HashMap.Strict as HashMap (empty)
import qualified Data.Aeson.KeyMap as KeyMap (empty, fromList)


{-| Transpose metadata.
Expand All @@ -22,15 +22,15 @@ which implements the Aeson.FromJSON instance.
> Example { some :: Text }
> deriving (Generic, FromJSON)
>
> hashMap = HashMap.fromList [ ("some", "metadata") ]
> keyMap = KeyMap.fromList [ ("some", "metadata") ]
> defaultEx = Example { some = "default" }
> example = transposeMetadata hashMap defaultEx :: Example
> example = transposeMetadata keyMap defaultEx :: Example
-}
transposeMetadata :: Aeson.FromJSON a => Metadata -> a -> a
transposeMetadata hashMap fallback =
transposeMetadata keyMap fallback =
let
result = hashMap
result = keyMap
|> Aeson.toJSON
|> Aeson.fromJSON :: Aeson.FromJSON b => Aeson.Result b
in
Expand All @@ -50,4 +50,4 @@ transposeToMetadata generic =
in
case result of
Aeson.Success x -> x
Aeson.Error _ -> HashMap.empty
Aeson.Error _ -> KeyMap.empty
6 changes: 4 additions & 2 deletions src/Shikensu/Utilities.hs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@ import Flow
import Shikensu.Internal.Types

import qualified Data.Aeson as Json (Object, Result(..), encode)
import qualified Data.HashMap.Strict as HashMap (lookup)
import qualified Data.Aeson.KeyMap as KeyMap (lookup)
import qualified Data.Aeson.Key as Key (fromText)
import qualified Data.List as List (unzip, zip)
import qualified Data.Text as Text (unpack)
import qualified Data.Text.Lazy as Lazy.Text (unpack)
Expand Down Expand Up @@ -72,7 +73,8 @@ lsequence list =
-}
(~>) :: (FromJSON a, ToJSON a) => Metadata -> Text -> Maybe a
(~>) obj key =
HashMap.lookup key obj
obj
|> KeyMap.lookup (Key.fromText key)
|> fmap fromJSON
|> fmap fromJSONResult

Expand Down
4 changes: 3 additions & 1 deletion stack.yaml
Original file line number Diff line number Diff line change
@@ -1 +1,3 @@
resolver: nightly-2020-09-19
resolver: nightly-2021-12-26
extra-deps:
- aeson-2.0.2.0
17 changes: 12 additions & 5 deletions stack.yaml.lock
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,17 @@
# For more information, please see the documentation at:
# https://docs.haskellstack.org/en/stable/lock_files

packages: []
packages:
- completed:
hackage: aeson-2.0.2.0@sha256:bb41f39762d6f755431097ce0fa88d817108036e7f1c1ec06fd5990230860c76,6343
pantry-tree:
size: 37910
sha256: 5303edc2f9516c7999c21fbfb218ad180dd91c2ceea570f8bc54818ea9ec1692
original:
hackage: aeson-2.0.2.0
snapshots:
- completed:
size: 531498
url: https://raw.githubusercontent.com/commercialhaskell/stackage-snapshots/master/nightly/2020/9/19.yaml
sha256: e39020cba3f67726df5d467ee7ddda6887f4be3a07fe3ece0eb2bdef801138c3
original: nightly-2020-09-19
size: 621066
url: https://raw.githubusercontent.com/commercialhaskell/stackage-snapshots/master/nightly/2021/12/26.yaml
sha256: b0ce4f7d53851f1e875b52df2a8a20d77c65883d8350b997580ded88eec0a4b2
original: nightly-2021-12-26
25 changes: 13 additions & 12 deletions tests/Test/Contrib.hs
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,10 @@ import Test.Tasty
import Test.Tasty.HUnit

import qualified Data.Aeson.Types as Aeson (Value(..))
import qualified Data.Aeson.Key as Key (fromText)
import qualified Data.ByteString as B (empty)
import qualified Data.ByteString.Char8 as BS (intercalate, pack)
import qualified Data.HashMap.Strict as HashMap (fromList, lookup)
import qualified Data.Aeson.KeyMap as KeyMap (fromList, lookup)
import qualified Data.List as List (head, reverse)
import qualified Data.Text as Text (pack, unpack)
import qualified Data.Text.Encoding as Text (decodeUtf8, encodeUtf8)
Expand Down Expand Up @@ -100,36 +101,36 @@ testExclude =
testMetadata :: TestTree
testMetadata =
let
keyA = Text.pack "title"
keyA = Key.fromText (Text.pack "title")
valueA = Aeson.String (Text.pack "Hello world!")

keyB = Text.pack "hello"
keyB = Key.fromText (Text.pack "hello")
valueB = Aeson.String (Text.pack "Guardian.")

keyC = Text.pack "removed"
keyC = Key.fromText (Text.pack "removed")
valueC = Aeson.String (Text.pack "Me.")

keyBase = Text.pack "basename"
keyBase = Key.fromText (Text.pack "basename")
valueBase = Aeson.String (Text.pack "example")

-- 1. Insert C
-- 2. Replace with A
-- 3. Insert B
dictionary = fmap
( id
.> Contrib.insertMetadata (HashMap.fromList [ (keyC, valueC) ])
.> Contrib.replaceMetadata (HashMap.fromList [ (keyA, valueA) ])
.> Contrib.insertMetadata (KeyMap.fromList [ (keyC, valueC) ])
.> Contrib.replaceMetadata (KeyMap.fromList [ (keyA, valueA) ])
.> Contrib.copyPropsToMetadata
.> Contrib.insertMetadata (HashMap.fromList [ (keyB, valueB) ])
.> Contrib.insertMetadata (KeyMap.fromList [ (keyB, valueB) ])
)
example_md

definition = fmap (List.reverse .> List.head) dictionary

lookupTitle def = HashMap.lookup keyA (Shikensu.metadata def)
lookupHello def = HashMap.lookup keyB (Shikensu.metadata def)
lookupRemoved def = HashMap.lookup keyC (Shikensu.metadata def)
lookupBasename def = HashMap.lookup keyBase (Shikensu.metadata def)
lookupTitle def = KeyMap.lookup keyA (Shikensu.metadata def)
lookupHello def = KeyMap.lookup keyB (Shikensu.metadata def)
lookupRemoved def = KeyMap.lookup keyC (Shikensu.metadata def)
lookupBasename def = KeyMap.lookup keyBase (Shikensu.metadata def)
in
testGroup
"Metadata"
Expand Down
4 changes: 2 additions & 2 deletions tests/Test/Utilities.hs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import Test.Helpers
import Test.Tasty
import Test.Tasty.HUnit

import qualified Data.HashMap.Strict as HashMap (singleton)
import qualified Data.Aeson.KeyMap as KeyMap (singleton)
import qualified Data.List as List (head)
import qualified Data.Tuple as Tuple (fst)
import qualified Shikensu.Contrib as Contrib
Expand Down Expand Up @@ -54,7 +54,7 @@ testMetadataAccessors =
definition =
"."
|> define thePattern
|> fmap (Contrib.insertMetadataDef $ HashMap.singleton "a" "Hi!")
|> fmap (Contrib.insertMetadataDef $ KeyMap.singleton "a" "Hi!")

resultExisting =
fmap (\d -> metadata d ~> "a" :: Maybe String) definition
Expand Down

0 comments on commit 121f34a

Please sign in to comment.