Type: !Rain::Module This handles the Rain Module directive, not the Modules section
(ctx *directiveContext)
| 512 | // Type: !Rain::Module |
| 513 | // This handles the Rain Module directive, not the Modules section |
| 514 | func module(ctx *directiveContext) (bool, error) { |
| 515 | |
| 516 | n := ctx.n |
| 517 | t := ctx.t |
| 518 | parent := ctx.parent |
| 519 | |
| 520 | if !Experimental { |
| 521 | panic("You must add the --experimental arg to use the !Rain::Module directive") |
| 522 | } |
| 523 | |
| 524 | if len(n.Content) != 2 { |
| 525 | return false, errors.New("expected !Rain::Module <URI>") |
| 526 | } |
| 527 | |
| 528 | HasModules = true |
| 529 | |
| 530 | uri := n.Content[1].Value |
| 531 | |
| 532 | moduleContent, err := getModuleContent(ctx.rootDir, |
| 533 | ctx.t, ctx.fs, ctx.baseUri, uri) |
| 534 | if err != nil { |
| 535 | return false, err |
| 536 | } |
| 537 | |
| 538 | content := moduleContent.Content |
| 539 | baseUri := moduleContent.BaseUri |
| 540 | |
| 541 | parsed, err := parseModule(content, ctx.rootDir, ctx.fs) |
| 542 | if err != nil { |
| 543 | return false, err |
| 544 | } |
| 545 | moduleNode := parsed.Node |
| 546 | moduleAsTemplate := parsed.AsTemplate |
| 547 | |
| 548 | // Figure out parent nodes to handle nested modules |
| 549 | var newParent node.NodePair |
| 550 | if parent.Parent != nil && parent.Parent.Value != nil { |
| 551 | newParent = node.GetParent(n, parent.Parent.Value, nil) |
| 552 | newParent.Parent = &parent |
| 553 | } |
| 554 | |
| 555 | // This needs to happen before recursing, since sub-modules need resolved constants in the parent |
| 556 | err = processRainSection(moduleAsTemplate) |
| 557 | if err != nil { |
| 558 | return false, err |
| 559 | } |
| 560 | |
| 561 | _, err = transform(&transformContext{ |
| 562 | nodeToTransform: moduleNode, |
| 563 | rootDir: moduleContent.NewRootDir, |
| 564 | t: moduleAsTemplate, |
| 565 | parent: &newParent, |
| 566 | fs: ctx.fs, |
| 567 | baseUri: baseUri, |
| 568 | }) |
| 569 | if err != nil { |
| 570 | return false, err |
| 571 | } |
nothing calls this directly
no test coverage detected