Skip to content

Commit

Permalink
feat: Serve.Module - Framing Results ( Fixes #1034 )
Browse files Browse the repository at this point in the history
  • Loading branch information
James Brundage committed Apr 18, 2024
1 parent c3c8f9b commit 974bff8
Showing 1 changed file with 59 additions and 34 deletions.
93 changes: 59 additions & 34 deletions Commands/Services/Serve-Module.ps.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -27,48 +27,73 @@ Serve function Module {
)

process {
$nowServingModule = $Module
$nowServingModule = $Module

$NowServingModuleRoutes = $NowServingModule.Route
$UrlSegments = @($Request.Url.Segments -replace '/$' -ne '')
$MyParameters = [Ordered]@{} + $PSBoundParameters

$ServedARoute = $false
:ServicingRoutes foreach ($nowServingRoute in $NowServingModuleRoutes) {
$ShouldServeThisUrl = $nowServingRoute.ForUrl($request.Url)
if ($ShouldServeThisUrl) {
$ServedARoute = $true
}
if ($ShouldServeThisUrl -is [ScriptBlock]) {
. $ShouldServeThisUrl
} elseif ($ShouldServeThisUrl -is [Management.Automation.CommandInfo]) {
. $ShouldServeThisUrl
} elseif ($ShouldServeThisUrl.pstypenames -contains 'PipeScript.Module.Service') {
foreach ($serviceParameterSet in $ShouldServeThisUrl.GetServiceParameters()) {
$serviceCommand = $serviceParameterSet.Command
if ($serviceCommand) {
$serviceParameterCopy = [Ordered]@{} + $serviceParameterSet
foreach ($parameterName in $MyParameters.Keys) {
if ($serviceCommand.Parameters[$parameterName] -and
-not $serviceParameterCopy[$parameterName]
) {
$serviceParameterCopy[$parameterName] = $MyParameters[$parameterName]
}
}
. $serviceCommand @serviceParameterCopy
$AdditionalContext = @()

$NowServingModuleOutput = . {
$ServedARoute = $false
:ServicingRoutes foreach ($nowServingRoute in $NowServingModuleRoutes) {
$ShouldServeThisUrl = $nowServingRoute.ForUrl($request.Url)
if ($ShouldServeThisUrl) {
$ServedARoute = $true
}
if ($ShouldServeThisUrl -is [ScriptBlock]) {
. $ShouldServeThisUrl
} elseif ($ShouldServeThisUrl -is [Management.Automation.CommandInfo]) {
. $ShouldServeThisUrl
} elseif ($ShouldServeThisUrl.pstypenames -contains 'PipeScript.Module.Service') {
foreach ($serviceParameterSet in $ShouldServeThisUrl.GetServiceParameters()) {
$serviceCommand = $serviceParameterSet.Command
if ($serviceCommand) {
$AdditionalContext += $serviceParameterSet
$serviceParameterCopy = [Ordered]@{} + $serviceParameterSet
foreach ($parameterName in $MyParameters.Keys) {
if ($serviceCommand.Parameters[$parameterName] -and
-not $serviceParameterCopy[$parameterName]
) {
$serviceParameterCopy[$parameterName] = $MyParameters[$parameterName]
}
}
. $serviceCommand @serviceParameterCopy
}
}
}
}
}

return if $ServedARoute

return if $ServedARoute

$potentialTopicName = $Request.Url.Segments -replace '^/' -ne '' -join ' '
if ($potentialTopicName) {
$module.Topics.Get($potentialTopicName)
} else {
$module.Topics.Get($module.Name)
}
}

$nowServingSiteInfo = $nowServingModule.Site

$potentialTopicName = $Request.Url.Segments -replace '^/' -ne '' -join ' '
if ($potentialTopicName) {
$module.Topics.Get($potentialTopicName)
if ($nowServingSiteInfo) {
$nowServingSite = foreach ($siteInfo in $nowServingSiteInfo) {
if ($request.Url -match "^$([Regex]::Escape($siteInfo.Url))") {
$siteInfo
break
}
}
if (-not $nowServingSite) {
$nowServingModuleOutput
}
else {
$nowServingSite.UseLayout(
$nowServingSite.GetDefaultLayout(),
(@($NowServingSite) + $AdditionalContext)
)
}
} else {
$module.Topics.Get($module.Name)
}

$NowServingModuleOutput
}
}
}

0 comments on commit 974bff8

Please sign in to comment.