2019-07-08 19:18:09 +02:00
|
|
|
# `dhall text`
|
|
|
|
|
|
|
|
The `dhall-text` executable is now subsumed by the `dhall text` subcommand,
|
|
|
|
which does the same thing. This `README` remains behind as a tutorial.
|
2018-10-29 01:32:51 +01:00
|
|
|
|
2018-12-10 21:28:19 +01:00
|
|
|
For installation or development instructions, see:
|
|
|
|
|
|
|
|
* [`dhall-haskell` - `README`](https://github.com/dhall-lang/dhall-haskell/blob/master/README.md)
|
|
|
|
|
|
|
|
## Introduction
|
|
|
|
|
2019-07-08 19:18:09 +02:00
|
|
|
You can use the `dhall text` subcommand to template text using the Dhall
|
|
|
|
configuration language.
|
2018-10-29 01:32:51 +01:00
|
|
|
|
2018-12-03 17:30:30 +01:00
|
|
|
## Example
|
|
|
|
|
|
|
|
Suppose you save the following files to your current directory:
|
2018-10-29 01:32:51 +01:00
|
|
|
|
|
|
|
```haskell
|
|
|
|
$ cat Person
|
|
|
|
-- Dhall is a typed programming language
|
|
|
|
|
|
|
|
-- This file is the type of an anonymous record
|
|
|
|
{ name : Text, upvotes : Natural }
|
|
|
|
```
|
|
|
|
|
|
|
|
```haskell
|
|
|
|
$ cat people
|
|
|
|
-- Dhall natively supports lists and anonymous records
|
|
|
|
|
|
|
|
[ { name = "Maria" , upvotes = 14 }
|
|
|
|
, { name = "Jordan", upvotes = 2 }
|
|
|
|
, { name = "Pranav", upvotes = 1 }
|
|
|
|
]
|
|
|
|
|
2018-12-03 17:30:30 +01:00
|
|
|
{- This file has type:
|
|
|
|
|
|
|
|
./people : List { name : Text, upvotes : Natural }
|
|
|
|
|
|
|
|
... or just:
|
|
|
|
|
|
|
|
./people : List ./Person
|
|
|
|
-}
|
2018-10-29 01:32:51 +01:00
|
|
|
```
|
|
|
|
|
|
|
|
```haskell
|
|
|
|
$ cat make-item
|
|
|
|
-- You can define anonymous functions in Dhall using a backslash (i.e. `\`)
|
|
|
|
\(person : ./Person) -- You can import any type or expression by its path
|
|
|
|
|
2018-12-03 17:30:30 +01:00
|
|
|
{- Dhall supports multiline strings that strip leading whitespace and Dhall
|
|
|
|
supports string interpolation, too, using `${...}` syntax
|
|
|
|
-}
|
|
|
|
-> ''
|
2018-10-29 01:32:51 +01:00
|
|
|
<li class="list-group-item">
|
|
|
|
<span class="badge">${Natural/show person.upvotes}</span>
|
|
|
|
${person.name}
|
|
|
|
</li>
|
|
|
|
''
|
|
|
|
|
2018-12-03 17:30:30 +01:00
|
|
|
{- This file has type:
|
|
|
|
|
|
|
|
./make-item : ./Person -> Text
|
|
|
|
-}
|
2018-10-29 01:32:51 +01:00
|
|
|
```
|
|
|
|
|
|
|
|
```haskell
|
|
|
|
$ cat make-items
|
2018-12-03 17:30:30 +01:00
|
|
|
-- You can also import any type or expression by its URL
|
|
|
|
let List/map = https://prelude.dhall-lang.org/List/map
|
|
|
|
|
|
|
|
let Text/concat = https://prelude.dhall-lang.org/Text/concat
|
|
|
|
|
|
|
|
in \(people : List ./Person) ->
|
|
|
|
Text/concat (List/map ./Person Text ./make-item people)
|
|
|
|
|
|
|
|
{- This file has type:
|
|
|
|
|
|
|
|
./make-items : List ./Person -> Text
|
|
|
|
-}
|
2018-10-29 01:32:51 +01:00
|
|
|
```
|
|
|
|
|
|
|
|
Templating HTML is just ordinary function application:
|
|
|
|
|
|
|
|
```bash
|
2019-07-08 19:18:09 +02:00
|
|
|
$ dhall text <<< './make-items ./people'
|
2018-10-29 01:32:51 +01:00
|
|
|
<li class="list-group-item">
|
|
|
|
<span class="badge">14</span>
|
|
|
|
Maria
|
|
|
|
</li>
|
|
|
|
|
|
|
|
<li class="list-group-item">
|
|
|
|
<span class="badge">2</span>
|
|
|
|
Jordan
|
|
|
|
</li>
|
|
|
|
|
|
|
|
<li class="list-group-item">
|
|
|
|
<span class="badge">1</span>
|
|
|
|
Pranav
|
|
|
|
</li>
|
|
|
|
|
|
|
|
```
|
|
|
|
|
|
|
|
To learn more about the Dhall configuration language,
|
|
|
|
[read the tutorial](https://hackage.haskell.org/package/dhall/docs/Dhall-Tutorial.html)
|