lib: add jsonPrettyText helper, depend on aeson-pretty
This commit is contained in:
		
							parent
							
								
									00e9e844ac
								
							
						
					
					
						commit
						d963944c99
					
				| @ -26,6 +26,7 @@ module Hledger.Utils.Text | |||||||
|   stripquotes, |   stripquotes, | ||||||
|  -- isSingleQuoted, |  -- isSingleQuoted, | ||||||
|  -- isDoubleQuoted, |  -- isDoubleQuoted, | ||||||
|  |   jsonPrettyText, | ||||||
|  -- -- * single-line layout |  -- -- * single-line layout | ||||||
|   textstrip, |   textstrip, | ||||||
|   textlstrip, |   textlstrip, | ||||||
| @ -59,6 +60,8 @@ module Hledger.Utils.Text | |||||||
|   ) |   ) | ||||||
| where | where | ||||||
| 
 | 
 | ||||||
|  | import Data.Aeson (Value) | ||||||
|  | import Data.Aeson.Encode.Pretty (encodePrettyToTextBuilder) | ||||||
| -- import Data.Char | -- import Data.Char | ||||||
| import Data.List | import Data.List | ||||||
| #if !(MIN_VERSION_base(4,11,0)) | #if !(MIN_VERSION_base(4,11,0)) | ||||||
| @ -66,6 +69,8 @@ import Data.Monoid | |||||||
| #endif | #endif | ||||||
| import Data.Text (Text) | import Data.Text (Text) | ||||||
| import qualified Data.Text as T | import qualified Data.Text as T | ||||||
|  | import qualified Data.Text.Lazy as TL | ||||||
|  | import Data.Text.Lazy.Builder (toLazyText) | ||||||
| -- import Text.Parsec | -- import Text.Parsec | ||||||
| -- import Text.Printf (printf) | -- import Text.Printf (printf) | ||||||
| 
 | 
 | ||||||
| @ -78,6 +83,10 @@ import Hledger.Utils.Test | |||||||
| -- lowercase = map toLower | -- lowercase = map toLower | ||||||
| -- uppercase = map toUpper | -- uppercase = map toUpper | ||||||
| 
 | 
 | ||||||
|  | -- | Pretty-print a JSON value. | ||||||
|  | jsonPrettyText :: Value -> TL.Text | ||||||
|  | jsonPrettyText = toLazyText . encodePrettyToTextBuilder | ||||||
|  | 
 | ||||||
| -- | Remove leading and trailing whitespace. | -- | Remove leading and trailing whitespace. | ||||||
| textstrip :: Text -> Text | textstrip :: Text -> Text | ||||||
| textstrip = textlstrip . textrstrip | textstrip = textlstrip . textrstrip | ||||||
|  | |||||||
| @ -4,7 +4,7 @@ cabal-version: 1.12 | |||||||
| -- | -- | ||||||
| -- see: https://github.com/sol/hpack | -- see: https://github.com/sol/hpack | ||||||
| -- | -- | ||||||
| -- hash: f5d891a2f435cece44dd66f1ca32e8e55fde986a4129a443d3de60ab6f65b5e3 | -- hash: d8c943c6b632e6b0cf34a564809ef96869541c54de93613e7103ec87fadb4e33 | ||||||
| 
 | 
 | ||||||
| name:           hledger-lib | name:           hledger-lib | ||||||
| version:        1.17.99 | version:        1.17.99 | ||||||
| @ -111,6 +111,7 @@ library | |||||||
|       Decimal >=0.5.1 |       Decimal >=0.5.1 | ||||||
|     , Glob >=0.9 |     , Glob >=0.9 | ||||||
|     , aeson |     , aeson | ||||||
|  |     , aeson-pretty | ||||||
|     , ansi-terminal >=0.6.2.3 |     , ansi-terminal >=0.6.2.3 | ||||||
|     , array |     , array | ||||||
|     , base >=4.9 && <4.15 |     , base >=4.9 && <4.15 | ||||||
| @ -162,6 +163,7 @@ test-suite doctest | |||||||
|       Decimal >=0.5.1 |       Decimal >=0.5.1 | ||||||
|     , Glob >=0.7 |     , Glob >=0.7 | ||||||
|     , aeson |     , aeson | ||||||
|  |     , aeson-pretty | ||||||
|     , ansi-terminal >=0.6.2.3 |     , ansi-terminal >=0.6.2.3 | ||||||
|     , array |     , array | ||||||
|     , base >=4.9 && <4.15 |     , base >=4.9 && <4.15 | ||||||
| @ -216,6 +218,7 @@ test-suite unittest | |||||||
|       Decimal >=0.5.1 |       Decimal >=0.5.1 | ||||||
|     , Glob >=0.9 |     , Glob >=0.9 | ||||||
|     , aeson |     , aeson | ||||||
|  |     , aeson-pretty | ||||||
|     , ansi-terminal >=0.6.2.3 |     , ansi-terminal >=0.6.2.3 | ||||||
|     , array |     , array | ||||||
|     , base >=4.9 && <4.15 |     , base >=4.9 && <4.15 | ||||||
|  | |||||||
| @ -47,6 +47,7 @@ dependencies: | |||||||
| - base >=4.9 && <4.15 | - base >=4.9 && <4.15 | ||||||
| - base-compat-batteries >=0.10.1 && <0.12 | - base-compat-batteries >=0.10.1 && <0.12 | ||||||
| - aeson | - aeson | ||||||
|  | - aeson-pretty | ||||||
| - ansi-terminal >=0.6.2.3 | - ansi-terminal >=0.6.2.3 | ||||||
| - array | - array | ||||||
| - blaze-markup >=0.5.1 | - blaze-markup >=0.5.1 | ||||||
|  | |||||||
		Loading…
	
		Reference in New Issue
	
	Block a user