diff --git a/.DS_Store b/.DS_Store new file mode 100644 index 0000000..f6248f9 Binary files /dev/null and b/.DS_Store differ diff --git a/Text/Mustache/Render.hs b/Text/Mustache/Render.hs index 14dd606..0a37b34 100644 --- a/Text/Mustache/Render.hs +++ b/Text/Mustache/Render.hs @@ -131,13 +131,15 @@ outputIndent = asks rcIndent >>= outputRaw . buildIndent {-# INLINE outputIndent #-} -- | Output piece of strict 'Text' with added indentation. +-- TODO: Maybe we need to rework the outputIndented implementation +-- to add the indentation without the use of \n outputIndented :: Text -> Render () outputIndented txt = do level <- asks rcIndent lnode <- asks rcLastNode let f x = outputRaw (T.replace "\n" ("\n" <> buildIndent level) x) if lnode && T.isSuffixOf "\n" txt - then f (T.init txt) >> outputRaw "\n" + then f (T.init txt) >> outputRaw "\n" >> outputIndent -- TODO: This solves the issue with the indentation. However, now the programs output does not end with newline else f txt {-# INLINE outputIndented #-} diff --git a/cabal.project b/cabal.project index 5d98f9c..729c849 100644 --- a/cabal.project +++ b/cabal.project @@ -1,4 +1,5 @@ packages: . + example/ tests: True benchmarks: True constraints: stache +dev diff --git a/example/CHANGELOG.md b/example/CHANGELOG.md new file mode 100644 index 0000000..cf96ff5 --- /dev/null +++ b/example/CHANGELOG.md @@ -0,0 +1,5 @@ +# Revision history for example + +## 0.1.0.0 -- YYYY-mm-dd + +* First version. Released on an unsuspecting world. diff --git a/example/LICENSE b/example/LICENSE new file mode 100644 index 0000000..8577d6a --- /dev/null +++ b/example/LICENSE @@ -0,0 +1,29 @@ +Copyright (c) 2025, William R. Arellano + + +Redistribution and use in source and binary forms, with or without +modification, are permitted provided that the following conditions are met: + + * Redistributions of source code must retain the above copyright + notice, this list of conditions and the following disclaimer. + + * 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. + + * Neither the name of the copyright holder nor the names of its + contributors may be used to endorse or promote products derived + from this software without specific prior written permission. + +THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND 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 COPYRIGHT +HOLDER 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. diff --git a/example/app/Main.hs b/example/app/Main.hs new file mode 100644 index 0000000..df00788 --- /dev/null +++ b/example/app/Main.hs @@ -0,0 +1,17 @@ +{-# LANGUAGE OverloadedStrings #-} + +module Main (main) where + +import Data.Aeson +import Data.Text +import qualified Data.Text.Lazy.IO as TIO +import Text.Mustache + +main :: IO () +main = do + template <- compileMustacheDir "main" "templates" + TIO.putStr $ + renderMustache template $ + object + [ "subnets" .= ["pen" :: Text, "candle", "egg"] + ] diff --git a/example/example.cabal b/example/example.cabal new file mode 100644 index 0000000..b114c3b --- /dev/null +++ b/example/example.cabal @@ -0,0 +1,29 @@ +cabal-version: 3.0 +name: example +version: 0.1.0.0 +-- synopsis: +-- description: +license: BSD-3-Clause +license-file: LICENSE +author: William R. Arellano +maintainer: arellanowr@gmail.com +-- copyright: +build-type: Simple +extra-doc-files: CHANGELOG.md +-- extra-source-files: + +common warnings + ghc-options: -Wall + +executable example + import: warnings + main-is: Main.hs + -- other-modules: + -- other-extensions: + build-depends: base >=4.15 && <5 + , aeson + , text + , megaparsec + , stache + hs-source-dirs: app + default-language: Haskell2010 diff --git a/example/templates/main.mustache b/example/templates/main.mustache new file mode 100644 index 0000000..924e14c --- /dev/null +++ b/example/templates/main.mustache @@ -0,0 +1,2 @@ +Subnets: + {{> myPartial}} \ No newline at end of file diff --git a/example/templates/myPartial.mustache b/example/templates/myPartial.mustache new file mode 100644 index 0000000..586100f --- /dev/null +++ b/example/templates/myPartial.mustache @@ -0,0 +1,4 @@ +{{#subnets}} +- {{ . }} +"Test string" +{{/subnets}} \ No newline at end of file