From fe3f8a913d94becc6e8d861b43c951d54f5b7728 Mon Sep 17 00:00:00 2001 From: "William R. Arellano" Date: Fri, 19 Sep 2025 14:36:30 -0500 Subject: [PATCH 1/3] WIP of possible solution --- .DS_Store | Bin 0 -> 8196 bytes Text/Mustache/Render.hs | 4 +++- cabal.project | 1 + example/CHANGELOG.md | 5 +++++ example/LICENSE | 29 +++++++++++++++++++++++++++ example/app/Main.hs | 17 ++++++++++++++++ example/example.cabal | 29 +++++++++++++++++++++++++++ example/templates/main.mustache | 2 ++ example/templates/myPartial.mustache | 4 ++++ 9 files changed, 90 insertions(+), 1 deletion(-) create mode 100644 .DS_Store create mode 100644 example/CHANGELOG.md create mode 100644 example/LICENSE create mode 100644 example/app/Main.hs create mode 100644 example/example.cabal create mode 100644 example/templates/main.mustache create mode 100644 example/templates/myPartial.mustache diff --git a/.DS_Store b/.DS_Store new file mode 100644 index 0000000000000000000000000000000000000000..f6248f9e1dca4608b83fa1f8e7a90724b7b6895d GIT binary patch literal 8196 zcmeI1ziSjh6vy9~yWD9KJrFc0)NMshJh8Iz3>OQ*#smwi+%Iznce#b+Fm?-8+GsE6 zzaR*LU}0ly{R;%OQbBDj0v3Mf$L+q^UtSf&%)rju?0awDXTHqt>|BUQERQ=iqD3Mq zTr@(b@09(Li)o@;sC$OHebz=i<;XxBR6;`JTv&9fP z9oIb*S2s4$R;QCNn-5_s3$sHJsygoPsc;f?ZC&paa0(<9kbCz6ou>`z)3&vLFShr% zZ#Zf+T7yvw*UBsN57u6ues|UOcXIuHkNq}KQcr1VQkQx(rj}Km3cqmoSOjO7eS7Te z&u_buArTdkWJg&%`eidiP4daNIgY+U1>@oMPyG(-hu)}e(redK<1bQ+y0l4c>cwix zQ86#Cd*ftfGHxp(s+}H@QvXO)pQ_Zs=(nk9lg!@+NopKtdU8Bu%7~5V{uXOF5q5oF)-TW+G}(!*M|A%o_wm}hpTc)>n9D1t`R%%IWZi?-tlEylhW{|cxrb1hQ#Ury r7FW>r{f7YdwZPYq=~i>Ts!W$*uQP7_S6|%h3&GaMt^eww*oW>9RmmlW literal 0 HcmV?d00001 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..76194d4 --- /dev/null +++ b/example/app/Main.hs @@ -0,0 +1,17 @@ +{-# LANGUAGE OverloadedStrings #-} + +module Main (main) where + +import Data.Aeson +import Data.Text +import Text.Megaparsec +import Text.Mustache +import qualified Data.Text.Lazy.IO as TIO + +main :: IO () +main = do + template <- compileMustacheDir "main" "templates" + print template + TIO.putStr $ renderMustache template $ object + [ "subnets" .= ["pen" :: Text, "candle", "egg"] + ] \ No newline at end of file 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 From 7cd95bd4fad727e42177a2239942e619eb85316b Mon Sep 17 00:00:00 2001 From: "William R. Arellano" Date: Fri, 19 Sep 2025 14:59:33 -0500 Subject: [PATCH 2/3] Remove print from example --- example/app/Main.hs | 2 -- 1 file changed, 2 deletions(-) diff --git a/example/app/Main.hs b/example/app/Main.hs index 76194d4..f784d05 100644 --- a/example/app/Main.hs +++ b/example/app/Main.hs @@ -4,14 +4,12 @@ module Main (main) where import Data.Aeson import Data.Text -import Text.Megaparsec import Text.Mustache import qualified Data.Text.Lazy.IO as TIO main :: IO () main = do template <- compileMustacheDir "main" "templates" - print template TIO.putStr $ renderMustache template $ object [ "subnets" .= ["pen" :: Text, "candle", "egg"] ] \ No newline at end of file From 2033a6c3957ed8d962c52f8c31d156d8ead7feab Mon Sep 17 00:00:00 2001 From: "William R. Arellano" Date: Fri, 19 Sep 2025 15:19:43 -0500 Subject: [PATCH 3/3] Apply ormolu formatting --- example/app/Main.hs | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/example/app/Main.hs b/example/app/Main.hs index f784d05..df00788 100644 --- a/example/app/Main.hs +++ b/example/app/Main.hs @@ -4,12 +4,14 @@ module Main (main) where import Data.Aeson import Data.Text -import Text.Mustache 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"] - ] \ No newline at end of file + TIO.putStr $ + renderMustache template $ + object + [ "subnets" .= ["pen" :: Text, "candle", "egg"] + ]