-
Notifications
You must be signed in to change notification settings - Fork 0
/
lists.gleam
63 lines (57 loc) · 1.98 KB
/
lists.gleam
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
import html_dsl/types/attribute.{type Attribute, attribute_to_string}
import gleam/option.{type Option}
/// Exists to prevent strings from being passed to ul and ol
pub opaque type List {
UnorderedList(String)
OrderedList(String)
}
/// This creates a string that represents a list element
/// - `@param` li: The list element
/// - `@returns`: A string that represents the HTML element
pub fn li_to_string(li: List) -> String {
case li {
UnorderedList(s) -> s
OrderedList(s) -> s
}
}
/// Closes the element
/// - `@param` li: The list element
/// - `@returns`: A string that represents the HTML element
pub fn end(li: List) -> String {
case li {
UnorderedList(s) -> s <> "</ul>"
OrderedList(s) -> s <> "</ol>"
}
}
/// This creates a string that represents a list item element
/// - `@param` root: The list element
/// - `@param` attributes: The attributes of the element
/// - `@param` inner: The inner content of the element
/// - `@returns`: A ListItem
pub fn add(
root: List,
attributes attributes: Option(Attribute),
inner inner: String,
) -> List {
let att_str = attribute_to_string(attributes)
case root {
UnorderedList(s) ->
UnorderedList(s <> "<li" <> att_str <> ">" <> inner <> "</li>")
OrderedList(s) ->
OrderedList(s <> "<li" <> att_str <> ">" <> inner <> "</li>")
}
}
/// This creates a string that represents an unordered list element
/// - `@param` attributes: The attributes of the element
/// - `@returns`: A string that represents the HTML element
pub fn ul(attributes attributes: Option(Attribute)) -> List {
let att_str = attribute_to_string(attributes)
UnorderedList("<ul" <> att_str <> ">")
}
/// This creates a string that represents an ordered list element
/// - `@param` attributes: The attributes of the element
/// - `@returns`: A string that represents the HTML element
pub fn ol(attributes attributes: Option(Attribute)) -> List {
let att_str = attribute_to_string(attributes)
OrderedList("<ol" <> att_str <> ">")
}