File tree 2 files changed +30
-0
lines changed
Sources/LeafKit/LeafSyntax
2 files changed +30
-0
lines changed Original file line number Diff line number Diff line change @@ -85,6 +85,7 @@ extension Syntax: BodiedSyntax {
85
85
. custom( let bS as BodiedSyntax ) ,
86
86
. export( let bS as BodiedSyntax ) ,
87
87
. extend( let bS as BodiedSyntax ) ,
88
+ . with( let bS as BodiedSyntax ) ,
88
89
. loop( let bS as BodiedSyntax ) : return bS. externals ( )
89
90
default : return . init( )
90
91
}
@@ -125,6 +126,7 @@ extension Syntax: BodiedSyntax {
125
126
. custom( let bS as BodiedSyntax ) ,
126
127
. export( let bS as BodiedSyntax ) ,
127
128
. extend( let bS as BodiedSyntax ) ,
129
+ . with( let bS as BodiedSyntax ) ,
128
130
. loop( let bS as BodiedSyntax ) : result += bS. inlineRefs ( externals, imports)
129
131
case . expression( let pDA) : result. append ( . expression( pDA. inlineImports ( imports) ) )
130
132
// .variable, .raw
Original file line number Diff line number Diff line change @@ -224,6 +224,34 @@ final class LeafTests: XCTestCase {
224
224
try XCTAssertEqual ( render ( template, [ " parent " : [ " child " : " Elizabeth " ] ] ) , expected)
225
225
}
226
226
227
+ func testWithWrappingExtend( ) throws {
228
+ let header = """
229
+ <h1>#(child)</h1>
230
+ """
231
+
232
+ let base = """
233
+ <body>#with(parent):<main>#extend( " header " )</main>#endwith</body>
234
+ """
235
+
236
+ let expected = """
237
+ <body><main><h1>Elizabeth</h1></main></body>
238
+ """
239
+
240
+ let headerAST = try LeafAST ( name: " header " , ast: parse ( header) )
241
+ let baseAST = try LeafAST ( name: " base " , ast: parse ( base) )
242
+
243
+ let baseResolved = LeafAST ( from: baseAST, referencing: [ " header " : headerAST] )
244
+
245
+ var serializer = LeafSerializer (
246
+ ast: baseResolved. ast,
247
+ ignoreUnfoundImports: false
248
+ )
249
+ let view = try serializer. serialize ( context: [ " parent " : [ " child " : " Elizabeth " ] ] )
250
+ let str = view. getString ( at: view. readerIndex, length: view. readableBytes) ?? " "
251
+
252
+ XCTAssertEqual ( str, expected)
253
+ }
254
+
227
255
func testExtendWithSugar( ) throws {
228
256
let header = """
229
257
<h1>#(child)</h1>
You can’t perform that action at this time.
0 commit comments