Last active
March 21, 2018 08:01
-
-
Save naoto-ogawa/d7851f5bf45410d6d7ecd757515729a0 to your computer and use it in GitHub Desktop.
Custom function Example of EDE
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
:set -XOverloadedStrings | |
-- EDEをつかうため | |
import Text.EDE | |
-- カスタムの関数を作るため | |
import Text.EDE.Filters | |
-- parseがかぶるのでObjectだけインポート | |
import Data.Aeson.Types (Object) | |
-- カスタムの関数を定義を格納するマップ | |
import qualified Data.HashMap.Strict as Map | |
-- EDEはTextベースなので | |
import Data.Text.Lazy | |
-- カスタムの関数を定義 | |
let mylib = Map.fromList ["f" @: (\x -> x + 2)] | |
-- テンプレートを作成 | |
let tmpl = parse "{{1 | f }}" :: Result Template | |
-- バインドするデータをつくる、ただしここではデータなし | |
let env = fromPairs [] :: Object | |
-- レンダリング実行 | |
tmpl >>= \x -> renderWith mylib x env :: Result Text | |
-- 結果 | |
Success "3" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment