Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file added .DS_Store
Binary file not shown.
4 changes: 3 additions & 1 deletion Text/Mustache/Render.hs
Original file line number Diff line number Diff line change
Expand Up @@ -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 #-}

Expand Down
1 change: 1 addition & 0 deletions cabal.project
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
packages: .
example/
tests: True
benchmarks: True
constraints: stache +dev
5 changes: 5 additions & 0 deletions example/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# Revision history for example

## 0.1.0.0 -- YYYY-mm-dd

* First version. Released on an unsuspecting world.
29 changes: 29 additions & 0 deletions example/LICENSE
Original file line number Diff line number Diff line change
@@ -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.
17 changes: 17 additions & 0 deletions example/app/Main.hs
Original file line number Diff line number Diff line change
@@ -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"]
]
29 changes: 29 additions & 0 deletions example/example.cabal
Original file line number Diff line number Diff line change
@@ -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: [email protected]
-- 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
2 changes: 2 additions & 0 deletions example/templates/main.mustache
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
Subnets:
{{> myPartial}}
4 changes: 4 additions & 0 deletions example/templates/myPartial.mustache
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{{#subnets}}
- {{ . }}
"Test string"
{{/subnets}}
Loading