@@ -15,24 +15,23 @@ class TemplateFileTests:
15
15
finally tmpFile.delete()
16
16
17
17
18
- private def testTemplates (
19
- props : Map [String , String ],
20
- template : List [(String , String )])(
21
- op : RenderingContext => Unit
22
- ) =
23
- def rec (cxt : RenderingContext , remaining : List [(String , String )]): Unit =
24
- if (remaining.isEmpty) op(cxt)
18
+ private def testContent (
19
+ expected : String ,
20
+ props : Map [String , String ],
21
+ template : List [(String , String )]
22
+ ) =
23
+ def rec (ctx : RenderingContext , remaining : List [(String , String )]): Unit =
24
+ if remaining.isEmpty then
25
+ assertEquals(expected.trim(), ctx.layouts(" content" ).resolveInner(ctx).code.trim())
25
26
else
26
27
val (code, ext) = remaining.head
27
28
testTemplate(code, ext) { template =>
28
- val newCtx = cxt .copy(layouts = cxt .layouts + (template.name() -> template))
29
+ val newCtx = ctx .copy(layouts = ctx .layouts + (template.name() -> template))
29
30
rec(newCtx, remaining.drop(1 ))
30
31
}
31
32
32
33
rec(RenderingContext (props), template)
33
34
34
- private def fullRender (template : TemplateFile , ctx : RenderingContext ): String = template.resolveInner(ctx).code.trim()
35
-
36
35
@ Test
37
36
def testParsingHeaders (): Unit =
38
37
testTemplate(
@@ -65,17 +64,14 @@ class TemplateFileTests:
65
64
|""" .stripMargin
66
65
67
66
68
- val expected = """ <p>Ala ma kota w <strong>paski</strong> from <a href="link/here.md">here</a>. Hej with <a href="link/target.md">link</a>!</p>"""
67
+ val expected =
68
+ """ <p>Ala ma kota w <strong>paski</strong> from <a href="link/here.md">here</a>. Hej with <a href="link/target.md">link</a>!</p>""" .stripMargin
69
69
70
- testTemplates(
70
+ testContent(
71
+ expected,
71
72
Map (" p1" -> " paski" , " p2" -> " Hej" ),
72
- List (base -> " html" , content -> " md" )
73
- ) { it =>
74
- assertEquals(
75
- expected,
76
- fullRender(it.layouts(" content" ), it)
77
- )
78
- }
73
+ List (base -> " md" , content -> " md" )
74
+ )
79
75
80
76
@ Test
81
77
def layout (): Unit =
@@ -96,25 +92,23 @@ class TemplateFileTests:
96
92
|""" .stripMargin
97
93
98
94
99
- val expected = """ <p>Ala ma kota w <strong>paski</strong>. Hej!</p>""" .stripMargin
95
+ val expected =
96
+ """ Ala <p>ma kota w <strong>paski</strong></p>
97
+ |. Hej!""" .stripMargin
100
98
101
- testTemplates(
99
+ testContent(
100
+ expected,
102
101
Map (" p1" -> " paski" , " p2" -> " Hej" ),
103
102
List (base -> " html" , content -> " md" )
104
- ) { it =>
105
- assertEquals(
106
- expected,
107
- fullRender(it.layouts(" content" ), it)
108
- )
109
- }
103
+ )
110
104
111
105
@ Test
112
106
def nestedLayout_htmlMdHtml (): Unit =
113
107
val toplevel =
114
108
""" ---
115
109
|name: toplevel
116
110
|---
117
- |[ div id="root"] {{ content }}[ /div]
111
+ |< div id="root"> {{ content }}< /div>
118
112
|""" .stripMargin
119
113
120
114
val basePage =
@@ -139,19 +133,20 @@ class TemplateFileTests:
139
133
140
134
141
135
val expected =
142
- """ [ div id="root"][h1] Test page[ /h1]
143
- |[p] Hello world!![/p]
144
- |[h2] Test page end[ /h2]
145
- |[ /div] """ .stripMargin
136
+ """ < div id="root"><h1> Test page< /h1>
137
+ |<p> Hello world!!</p>
138
+ |<h2> Test page end< /h2>
139
+ |< /div> """ .stripMargin
146
140
147
- testTemplates(
141
+ testContent(
142
+ expected,
148
143
Map (" pageName" -> " Test page" , " name" -> " world!" ),
149
144
List (
150
145
toplevel -> " html" ,
151
146
basePage -> " md" ,
152
147
content -> " md"
153
148
)
154
- ) (it => fullRender(it.layouts( " content " ), it))
149
+ )
155
150
156
151
@ Test
157
152
def nestedLayout_mdHtmlMd (): Unit =
@@ -187,25 +182,28 @@ class TemplateFileTests:
187
182
val expected =
188
183
""" <h1>The Page</h1>
189
184
|<h2>Test page</h2>
185
+ |
190
186
|<p>Hello world!!</p>
187
+ |
188
+ |
191
189
|<h3>Test page end</h3>""" .stripMargin
192
190
193
- testTemplates(
191
+ testContent(
192
+ expected,
194
193
Map (" pageName" -> " Test page" , " name" -> " world!" ),
195
194
List (
196
195
toplevel -> " html" ,
197
196
basePage -> " html" ,
198
197
content -> " md"
199
198
)
200
- ) { ctx => assertEquals(expected, fullRender(ctx.layouts(" content" ), ctx)) }
201
-
199
+ )
202
200
@ Test
203
201
def markdown (): Unit =
204
202
testTemplate(
205
203
""" # Hello {{ msg }}!""" ,
206
204
ext = " md"
207
205
) { t =>
208
- assertEquals(" # Hello there!" , t.resolveInner(RenderingContext (Map (" msg" -> " there" ))).code.trim())
206
+ assertEquals(" <h1> Hello there!</h1> " , t.resolveInner(RenderingContext (Map (" msg" -> " there" ))).code.trim())
209
207
}
210
208
211
209
@ Test
@@ -214,5 +212,35 @@ class TemplateFileTests:
214
212
""" # Hello {{ msg }}!""" ,
215
213
ext = " md"
216
214
) { t =>
217
- assertEquals(" # Hello there!" , t.resolveInner(RenderingContext (Map (" msg" -> " there" ))).code.trim())
218
- }
215
+ assertEquals(" <h1>Hello there!</h1>" , t.resolveInner(RenderingContext (Map (" msg" -> " there" ))).code.trim())
216
+ }
217
+
218
+ @ Test
219
+ def htmlOnly (): Unit =
220
+ val html =
221
+ """ <div>Ala</ala>
222
+ |
223
+ |<span>Ula</span>
224
+ |""" .stripMargin
225
+
226
+ val base =
227
+ """ ---
228
+ |title: myTitle
229
+ |name: base
230
+ |---
231
+ |{{ content }}
232
+ |""" .stripMargin
233
+
234
+ val content =
235
+ s """ ---
236
+ |layout: base
237
+ |name: content
238
+ |---
239
+ | $html
240
+ | """ .stripMargin
241
+
242
+
243
+ testContent(
244
+ html,
245
+ Map (),
246
+ List (base -> " html" , content -> " html" ))
0 commit comments