packages feed

hastache-aeson 0.1.0.0 → 0.1.1.0

raw patch · 3 files changed

+44/−55 lines, 3 filesdep +scientificdep −attoparsecdep ~aesondep ~basedep ~bytestringPVP ok

version bump matches the API change (PVP)

Dependencies added: scientific

Dependencies removed: attoparsec

Dependency ranges changed: aeson, base, bytestring, containers, hastache, text, unordered-containers, vector

API changes (from Hackage documentation)

Files

README.md view
@@ -1,6 +1,8 @@ hastache-aeson ============== +[![Build Status](https://travis-ci.org/proger/hastache-aeson.svg?branch=master)](https://travis-ci.org/proger/hastache-aeson)+ * Lets you pass [aeson](http://hackage.haskell.org/package/aeson) `Value` as `MuContext` to [hastache](http://hackage.haskell.org/package/hastache) * Since [yaml](http://hackage.haskell.org/package/yaml) is API-compatible to `aeson`, you can also render `yaml` `Value`s. @@ -31,38 +33,9 @@     render template' value >>= LBS.putStrLn ``` -BSD3 License------------- -```-Copyright (c) 2013 Vladimir Kirillov--All rights reserved.--Redistribution and use in source and binary forms, with or without-modification, are permitted provided that the following conditions-are met:--1. Redistributions of source code must retain the above copyright-   notice, this list of conditions and the following disclaimer.--2. Redistributions in binary form must reproduce the above copyright-   notice, this list of conditions and the following disclaimer in the-   documentation and/or other materials provided with the distribution.--3. Neither the name of the author nor the names of his contributors-   may be used to endorse or promote products derived from this software-   without specific prior written permission.+Contributors+------------ -THIS SOFTWARE IS PROVIDED BY THE CONTRIBUTORS ``AS IS'' AND ANY EXPRESS-OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED-WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE-DISCLAIMED.  IN NO EVENT SHALL THE AUTHORS OR CONTRIBUTORS BE LIABLE FOR-ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL-DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS-OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)-HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,-STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN-ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE-POSSIBILITY OF SUCH DAMAGE.-```+- Viktar Basharymau+- Vladimir Kirillov
Text/Hastache/Aeson.hs view
@@ -21,18 +21,25 @@ import qualified Data.Map as Map import qualified Data.Vector as V import qualified Data.HashMap.Strict as HM-import Data.Attoparsec.Number (Number(I, D))+import Data.Scientific  import Data.Aeson.Types -import Text.Hastache -import Text.Hastache.Context +import Text.Hastache+import Text.Hastache.Context  jsonValueContext :: Monad m => Value -> MuContext m-jsonValueContext v = buildMapContext $ valueMap v+jsonValueContext = buildMapContext . valueMap +valueMap :: Monad m => Value -> Map.Map T.Text (MuType m) valueMap v = buildMap "" Map.empty v +buildMap+  :: Monad m =>+     String+     -> Map.Map T.Text (MuType m)+     -> Value+     -> Map.Map T.Text (MuType m) buildMap name m (Object obj) =     Map.insert (encodeStr name)       (MuList [buildMapContext $ HM.foldlWithKey' (foldObject "") Map.empty obj])@@ -41,19 +48,28 @@     where         muValue = case value of                       Array arr -> MuList . V.toList $ fmap jsonValueContext arr-                      Number (D float) -> MuVariable float-                      Number (I int) -> MuVariable int+                      Number n -> case floatingOrInteger n of+                                    Left d  -> MuVariable (d :: Double)+                                    Right i -> MuVariable (i :: Integer)                       String s -> MuVariable s                       Bool b -> MuBool b                       Null -> MuNothing                       t -> MuVariable $ show t -buildName name newName-    | not (null name) = concat [name, ".", newName]-    | otherwise = newName+buildName :: String -> String -> String+buildName   "" newName = newName+buildName name newName = name ++ "." ++ newName +foldObject ::+  Monad m =>+     String+     -> Map.Map T.Text (MuType m)+     -> T.Text+     -> Value+     -> Map.Map T.Text (MuType m) foldObject name m k v = buildMap (buildName name (T.unpack k)) m v +buildMapContext :: Monad m => Map.Map T.Text (MuType m) -> MuContext m buildMapContext m a = return $ fromMaybe-    (if a == BS.pack "." then maybe MuNothing id $ Map.lookup BS.empty m else MuNothing)+    (if a == T.pack "." then maybe MuNothing id $ Map.lookup T.empty m else MuNothing)     (Map.lookup a m)
hastache-aeson.cabal view
@@ -1,5 +1,5 @@ name:                hastache-aeson-version:             0.1.0.0+version:             0.1.1.0 license:             BSD3 license-file:        README.md homepage:            https://github.com/proger/hastache-aeson@@ -10,7 +10,7 @@ maintainer:          Vladimir Kirillov <proger@hackndev.com>  synopsis:            render hastache templates using aeson values-description:         +description:     The Module lets you render Hastache templates from aeson values. See the GitHub page for examples.  category:            Text@@ -19,16 +19,16 @@  library   exposed-modules:     Text.Hastache.Aeson-  -- other-modules:       -  build-depends:       base ==4.6.*-                     , hastache ==0.5.*-                     , aeson ==0.6.*-                     , attoparsec ==0.10.*-                     , unordered-containers ==0.2.*-                     , vector ==0.10.*-                     , containers ==0.5.*-                     , text ==0.11.*-                     , bytestring ==0.10.*+  -- other-modules:+  build-depends:       base >= 4.6 && < 5+                     , hastache >= 0.5+                     , aeson >= 0.7.0.4+                     , scientific >= 0.2+                     , unordered-containers >= 0.2+                     , vector >= 0.10+                     , containers >= 0.5+                     , text >= 0.11+                     , bytestring >= 0.10  source-repository head   type:     git