-
-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
153 additions
and
0 deletions.
There are no files selected for viewing
24 changes: 24 additions & 0 deletions
24
src/Simplify.Web/PageComposition/Stages/ContextVariablesSetter.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
using Simplify.Web.Modules.Context; | ||
|
||
namespace Simplify.Web.PageComposition.Stages; | ||
|
||
public class ContextVariablesSetter(IWebContextProvider webContextProvider) : IPageCompositionStage | ||
{ | ||
/// <summary> | ||
/// The site variable name site URL. | ||
/// </summary> | ||
public const string VariableNameSiteUrl = "SV:SiteUrl"; | ||
|
||
/// <summary> | ||
/// The site variable name site virtual path (returns '/yoursite' if your site is placed in virtual directory like http://yourdomain.com/yoursite/). | ||
/// </summary> | ||
public const string VariableNameSiteVirtualPath = "~"; | ||
|
||
public void Execute(Modules.Data.IDataCollector dataCollector) | ||
{ | ||
var context = webContextProvider.Get(); | ||
|
||
dataCollector.Add(VariableNameSiteUrl, context.SiteUrl); | ||
dataCollector.Add(VariableNameSiteVirtualPath, context.VirtualPath); | ||
} | ||
} |
23 changes: 23 additions & 0 deletions
23
src/Simplify.Web/PageComposition/Stages/EnvironmentVariablesInjectionStage.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
using Simplify.Web.Modules.ApplicationEnvironment; | ||
using Simplify.Web.Modules.Data; | ||
|
||
namespace Simplify.Web.PageComposition.Stages; | ||
|
||
public class EnvironmentVariablesInjectionStage(IDynamicEnvironment dynamicEnvironment) : IPageCompositionStage | ||
{ | ||
/// <summary> | ||
/// The site variable name templates directory. | ||
/// </summary> | ||
public const string VariableNameTemplatesPath = "SV:TemplatesDir"; | ||
|
||
/// <summary> | ||
/// The site variable name current style. | ||
/// </summary> | ||
public const string VariableNameSiteStyle = "SV:Style"; | ||
|
||
public void Execute(IDataCollector dataCollector) | ||
{ | ||
dataCollector.Add(VariableNameTemplatesPath, dynamicEnvironment.TemplatesPath); | ||
dataCollector.Add(VariableNameSiteStyle, dynamicEnvironment.SiteStyle); | ||
} | ||
} |
48 changes: 48 additions & 0 deletions
48
src/Simplify.Web/PageComposition/Stages/LanguageInjectionStage.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
using System.Threading; | ||
using Simplify.Web.Modules.Data; | ||
using Simplify.Web.Modules.Localization; | ||
|
||
namespace Simplify.Web.PageComposition.Stages; | ||
|
||
public class LanguageInjectionStage(ILanguageManagerProvider languageManagerProvider) : IPageCompositionStage | ||
{ | ||
/// <summary> | ||
/// The site variable name current language. | ||
/// </summary> | ||
public const string VariableNameCurrentLanguage = "SV:Language"; | ||
|
||
/// <summary> | ||
/// The site variable name current language extension. | ||
/// </summary> | ||
public const string VariableNameCurrentLanguageExtension = "SV:LanguageExt"; | ||
|
||
/// <summary> | ||
/// The site variable name current language culture name. | ||
/// </summary> | ||
public const string VariableNameCurrentLanguageCultureName = "SV:LanguageCultureName"; | ||
|
||
/// <summary> | ||
/// The site variable name current language culture name extension. | ||
/// </summary> | ||
public const string VariableNameCurrentLanguageCultureNameExtension = "SV:LanguageCultureNameExt"; | ||
|
||
public void Execute(IDataCollector dataCollector) | ||
{ | ||
var languageManager = languageManagerProvider.Get(); | ||
|
||
if (!string.IsNullOrEmpty(languageManager.Language)) | ||
{ | ||
dataCollector.Add(VariableNameCurrentLanguage, languageManager.Language); | ||
dataCollector.Add(VariableNameCurrentLanguageExtension, "." + languageManager.Language); | ||
dataCollector.Add(VariableNameCurrentLanguageCultureName, Thread.CurrentThread.CurrentCulture.TextInfo.CultureName); | ||
dataCollector.Add(VariableNameCurrentLanguageCultureNameExtension, "." + Thread.CurrentThread.CurrentCulture.TextInfo.CultureName); | ||
} | ||
else | ||
{ | ||
dataCollector.Add(VariableNameCurrentLanguage, (string?)null); | ||
dataCollector.Add(VariableNameCurrentLanguageExtension, (string?)null); | ||
dataCollector.Add(VariableNameCurrentLanguageCultureName, (string?)null); | ||
dataCollector.Add(VariableNameCurrentLanguageCultureNameExtension, (string?)null); | ||
} | ||
} | ||
} |
30 changes: 30 additions & 0 deletions
30
src/Simplify.Web/PageComposition/Stages/SiteTitleInjectionStage.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
using Simplify.Web.Modules.Context; | ||
using Simplify.Web.Modules.Data; | ||
|
||
namespace Simplify.Web.PageComposition.Stages; | ||
|
||
public class SiteTitleInjectionStage(IWebContextProvider webContextProvider, IStringTable stringTable) : IPageCompositionStage | ||
{ | ||
/// <summary> | ||
/// The site title string table variable name. | ||
/// </summary> | ||
public const string SiteTitleStringTableVariableName = "SiteTitle"; | ||
|
||
public void Execute(IDataCollector dataCollector) | ||
{ | ||
var context = webContextProvider.Get(); | ||
var currentPath = context.Request.Path.Value; | ||
var siteTitle = stringTable.GetItem(SiteTitleStringTableVariableName); | ||
|
||
if (string.IsNullOrEmpty(siteTitle)) | ||
return; | ||
|
||
if (string.IsNullOrEmpty(currentPath) || | ||
currentPath == "/" || | ||
currentPath!.StartsWith("/?") || | ||
!dataCollector.IsDataExist(dataCollector.TitleVariableName)) | ||
dataCollector.Add(dataCollector.TitleVariableName, siteTitle); | ||
else | ||
dataCollector.Add(dataCollector.TitleVariableName, " - " + siteTitle); | ||
} | ||
} |
11 changes: 11 additions & 0 deletions
11
src/Simplify.Web/PageComposition/Stages/StopwatchDataInjectionStage.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
using Simplify.Web.Diagnostics.Measurement; | ||
|
||
namespace Simplify.Web.PageComposition.Stages; | ||
|
||
public class StopwatchDataInjectionStage(IStopwatchProvider stopwatchProvider) : IPageCompositionStage | ||
{ | ||
public const string VariableNameExecutionTime = "SV:SiteExecutionTime"; | ||
|
||
public void Execute(Modules.Data.IDataCollector dataCollector) => | ||
dataCollector.Add(VariableNameExecutionTime, stopwatchProvider.StopAndGetMeasurement().ToString("mm\\:ss\\:fff")); | ||
} |
17 changes: 17 additions & 0 deletions
17
src/Simplify.Web/PageComposition/Stages/StringTableItemsInjectionStage.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
using System.Collections.Generic; | ||
using Simplify.Web.Modules.Data; | ||
|
||
namespace Simplify.Web.PageComposition.Stages; | ||
|
||
public class StringTableItemsInjectionStage(IStringTable stringTable) : IPageCompositionStage | ||
{ | ||
private const string StringTablePrefix = "StringTable."; | ||
|
||
private readonly IStringTable _stringTable = stringTable; | ||
|
||
public void Execute(IDataCollector dataCollector) | ||
{ | ||
foreach (var item in (IDictionary<string, object>)_stringTable.Items) | ||
dataCollector.Add(StringTablePrefix + item.Key, item.Value.ToString()); | ||
} | ||
} |