Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

flatten the get content logic in templates. #717

Merged
merged 1 commit into from
Feb 14, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
46 changes: 18 additions & 28 deletions uSync.Core/Serialization/Serializers/TemplateSerializer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -69,8 +69,8 @@ protected override async Task<SyncAttempt<ITemplate>> ProcessDeleteAsync(Guid ke
var item = default(ITemplate);

if (key != Guid.Empty)
item = await FindItemAsync(key);
item = await FindItemAsync(key);

return item ?? await FindItemAsync(alias);

}
Expand Down Expand Up @@ -149,35 +149,25 @@ protected override async Task<SyncAttempt<ITemplate>> DeserializeCoreAsync(XElem
logger.LogDebug("Getting content for Template from XML");
return Attempt.Succeed(GetContentFromConfig(node));
}
else
{
logger.LogDebug("Loading template content from disk");

var templatePath = ViewPath(node.GetAlias());
if (templatePath is not null && _viewFileSystem?.FileExists(templatePath) is true)
{
logger.LogDebug("Reading {path} contents", templatePath);
return Attempt.Succeed(GetContentFromFile(templatePath));
}
else
{
if (!ViewsAreCompiled(options))
{
// template is missing
// we can't create
logger.LogWarning("Failed to create template {path} the local file is missing", templatePath);
return Attempt.Fail("", new Exception($"The template {templatePath} file is missing."));
}
else
{
// template is not on disk, we could use the viewEngine to find the view
// if this finds the view it tells us that the view is somewhere else ?
var templatePath = ViewPath(node.GetAlias());
if (templatePath is not null && _viewFileSystem?.FileExists(templatePath) is true)
{
logger.LogDebug("Reading {path} contents", templatePath);
return Attempt.Succeed(GetContentFromFile(templatePath));
}

logger.LogDebug("Failed to find content, but UsingRazorViews so will create anyway, then delete the file");
return Attempt.Succeed($"<!-- [uSyncMarker:{this.Id}] template content - will be removed -->");
}
}
if (!ViewsAreCompiled(options))
{
// template is missing and the views are not compiled , then we can't create.
logger.LogWarning("Failed to create template {path} the local file is missing", templatePath);
return Attempt.Fail("", new Exception($"The template {templatePath} file is missing."));
}
// template is not on disk, we could use the viewEngine to find the view
// if this finds the view it tells us that the view is somewhere else ?

logger.LogDebug("Failed to find content, but UsingRazorViews so will create anyway, then delete the file");
return Attempt.Succeed($"<!-- [uSyncMarker:{this.Id}] template content - will be removed -->");
}

/// <summary>
Expand Down