Skip to content

Commit e47d2e9

Browse files
authored
flatten the get content logic in templates. (#717)
1 parent 47fe34d commit e47d2e9

File tree

1 file changed

+18
-28
lines changed

1 file changed

+18
-28
lines changed

uSync.Core/Serialization/Serializers/TemplateSerializer.cs

+18-28
Original file line numberDiff line numberDiff line change
@@ -69,8 +69,8 @@ protected override async Task<SyncAttempt<ITemplate>> ProcessDeleteAsync(Guid ke
6969
var item = default(ITemplate);
7070

7171
if (key != Guid.Empty)
72-
item = await FindItemAsync(key);
73-
72+
item = await FindItemAsync(key);
73+
7474
return item ?? await FindItemAsync(alias);
7575

7676
}
@@ -149,35 +149,25 @@ protected override async Task<SyncAttempt<ITemplate>> DeserializeCoreAsync(XElem
149149
logger.LogDebug("Getting content for Template from XML");
150150
return Attempt.Succeed(GetContentFromConfig(node));
151151
}
152-
else
153-
{
154-
logger.LogDebug("Loading template content from disk");
155152

156-
var templatePath = ViewPath(node.GetAlias());
157-
if (templatePath is not null && _viewFileSystem?.FileExists(templatePath) is true)
158-
{
159-
logger.LogDebug("Reading {path} contents", templatePath);
160-
return Attempt.Succeed(GetContentFromFile(templatePath));
161-
}
162-
else
163-
{
164-
if (!ViewsAreCompiled(options))
165-
{
166-
// template is missing
167-
// we can't create
168-
logger.LogWarning("Failed to create template {path} the local file is missing", templatePath);
169-
return Attempt.Fail("", new Exception($"The template {templatePath} file is missing."));
170-
}
171-
else
172-
{
173-
// template is not on disk, we could use the viewEngine to find the view
174-
// if this finds the view it tells us that the view is somewhere else ?
153+
var templatePath = ViewPath(node.GetAlias());
154+
if (templatePath is not null && _viewFileSystem?.FileExists(templatePath) is true)
155+
{
156+
logger.LogDebug("Reading {path} contents", templatePath);
157+
return Attempt.Succeed(GetContentFromFile(templatePath));
158+
}
175159

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

183173
/// <summary>

0 commit comments

Comments
 (0)