removes CssInitialization and JsInitialization and merges/simplifies code
This commit is contained in:
@@ -1,20 +1,15 @@
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Text.RegularExpressions;
|
||||
using System.Threading.Tasks;
|
||||
using Newtonsoft.Json;
|
||||
using Newtonsoft.Json.Linq;
|
||||
using Umbraco.Core.Configuration;
|
||||
using Umbraco.Core.Hosting;
|
||||
using Umbraco.Core.IO;
|
||||
using Umbraco.Core.WebAssets;
|
||||
using Umbraco.Infrastructure.WebAssets;
|
||||
|
||||
namespace Umbraco.Web.JavaScript
|
||||
namespace Umbraco.Web.WebAssets
|
||||
{
|
||||
// TODO: Rename this
|
||||
public class JavaScriptHelper
|
||||
/// <summary>
|
||||
/// Creates a JavaScript block to initialize the back office
|
||||
/// </summary>
|
||||
public class BackOfficeJavaScriptInitializer
|
||||
{
|
||||
// deal with javascript functions inside of json (not a supported json syntax)
|
||||
private const string PrefixJavaScriptObject = "@@@@";
|
||||
@@ -83,7 +83,7 @@ namespace Umbraco.Web.WebAssets
|
||||
/// <returns></returns>
|
||||
private string[] GetScriptsForBackoffice(IEnumerable<string> propertyEditorScripts)
|
||||
{
|
||||
var umbracoInit = JsInitialization.GetDefaultInitialization();
|
||||
var umbracoInit = GetInitBackOfficeScripts();
|
||||
var scripts = new HashSet<string>();
|
||||
foreach (var script in umbracoInit)
|
||||
scripts.Add(script);
|
||||
@@ -95,6 +95,16 @@ namespace Umbraco.Web.WebAssets
|
||||
return new HashSet<string>(FormatPaths(scripts)).ToArray();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Returns the list of scripts for back office initialization
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
private IEnumerable<string> GetInitBackOfficeScripts()
|
||||
{
|
||||
var resources = JsonConvert.DeserializeObject<JArray>(Resources.JsInitialize);
|
||||
return resources.Where(x => x.Type == JTokenType.String).Select(x => x.ToString());
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Returns stylesheets used to load the back office
|
||||
/// </summary>
|
||||
|
||||
@@ -1,36 +0,0 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using Umbraco.Core.WebAssets;
|
||||
|
||||
namespace Umbraco.Web.JavaScript
|
||||
{
|
||||
public class CssInitialization
|
||||
{
|
||||
private readonly IRuntimeMinifier _runtimeMinifier;
|
||||
|
||||
public CssInitialization(IRuntimeMinifier runtimeMinifier)
|
||||
{
|
||||
_runtimeMinifier = runtimeMinifier;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Processes all found manifest files, and outputs css inject calls for all css files found in all manifests.
|
||||
/// </summary>
|
||||
public async Task<string> GetStylesheetInitializationAsync()
|
||||
{
|
||||
var files = await _runtimeMinifier.GetAssetPathsAsync(BackOfficeWebAssets.UmbracoCssBundleName);
|
||||
return WriteScript(files);
|
||||
}
|
||||
|
||||
internal static string WriteScript(IEnumerable<string> files)
|
||||
{
|
||||
var sb = new StringBuilder();
|
||||
foreach (var file in files)
|
||||
sb.AppendFormat("{0}LazyLoad.css('{1}');", Environment.NewLine, file);
|
||||
return sb.ToString();
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
@@ -1,32 +0,0 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
using Newtonsoft.Json;
|
||||
using Newtonsoft.Json.Linq;
|
||||
using Umbraco.Core.Hosting;
|
||||
using Umbraco.Core.Manifest;
|
||||
using Umbraco.Core.PropertyEditors;
|
||||
using Umbraco.Core.WebAssets;
|
||||
using Umbraco.Infrastructure.WebAssets;
|
||||
|
||||
namespace Umbraco.Web.JavaScript
|
||||
{
|
||||
/// <summary>
|
||||
/// Reads from all defined manifests and ensures that any of their initialization is output with the
|
||||
/// main Umbraco initialization output.
|
||||
/// </summary>
|
||||
public class JsInitialization
|
||||
{
|
||||
|
||||
/// <summary>
|
||||
/// Returns the default config as a JArray
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
public static IEnumerable<string> GetDefaultInitialization()
|
||||
{
|
||||
var resources = JsonConvert.DeserializeObject<JArray>(Resources.JsInitialize);
|
||||
return resources.Where(x => x.Type == JTokenType.String).Select(x => x.ToString());
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,4 +1,7 @@
|
||||
using System.Threading.Tasks;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using Umbraco.Core.Configuration;
|
||||
using Umbraco.Core.IO;
|
||||
using Umbraco.Core.WebAssets;
|
||||
@@ -13,12 +16,24 @@ namespace Umbraco.Web.WebAssets
|
||||
/// <returns></returns>
|
||||
public static async Task<string> GetScriptForLoadingBackOfficeAsync(this IRuntimeMinifier minifier, IGlobalSettings globalSettings, IIOHelper ioHelper)
|
||||
{
|
||||
var initCss = new CssInitialization(minifier);
|
||||
var files = await minifier.GetAssetPathsAsync(BackOfficeWebAssets.UmbracoJsBundleName);
|
||||
var result = JavaScriptHelper.GetJavascriptInitialization(files, "umbraco", globalSettings, ioHelper);
|
||||
result += await initCss.GetStylesheetInitializationAsync();
|
||||
var result = BackOfficeJavaScriptInitializer.GetJavascriptInitialization(files, "umbraco", globalSettings, ioHelper);
|
||||
result += await GetStylesheetInitializationAsync(minifier);
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets the back office css bundle paths and formats a JS call to lazy load them
|
||||
/// </summary>
|
||||
private static async Task<string> GetStylesheetInitializationAsync(IRuntimeMinifier minifier)
|
||||
{
|
||||
var files = await minifier.GetAssetPathsAsync(BackOfficeWebAssets.UmbracoCssBundleName);
|
||||
var sb = new StringBuilder();
|
||||
foreach (var file in files)
|
||||
sb.AppendFormat("{0}LazyLoad.css('{1}');", Environment.NewLine, file);
|
||||
return sb.ToString();
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -9,17 +9,10 @@ namespace Umbraco.Tests.Web.AngularIntegration
|
||||
public class JsInitializationTests
|
||||
{
|
||||
|
||||
[Test]
|
||||
public void Get_Default_Init()
|
||||
{
|
||||
var init = JsInitialization.GetDefaultInitialization();
|
||||
Assert.IsTrue(init.Any());
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void Parse_Main()
|
||||
{
|
||||
var result = JavaScriptHelper.WriteScript("[World]", "Hello", "Blah");
|
||||
var result = BackOfficeJavaScriptInitializer.WriteScript("[World]", "Hello", "Blah");
|
||||
|
||||
Assert.AreEqual(@"LazyLoad.js([World], function () {
|
||||
//we need to set the legacy UmbClientMgr path
|
||||
|
||||
@@ -104,7 +104,7 @@ namespace Umbraco.Web.Editors
|
||||
public async Task<JavaScriptResult> Application()
|
||||
{
|
||||
var files = await _runtimeMinifier.GetAssetPathsAsync(BackOfficeWebAssets.UmbracoPreviewJsBundleName);
|
||||
var result = JavaScriptHelper.GetJavascriptInitialization(files, "umbraco.preview", _globalSettings, _ioHelper);
|
||||
var result = BackOfficeJavaScriptInitializer.GetJavascriptInitialization(files, "umbraco.preview", _globalSettings, _ioHelper);
|
||||
|
||||
return JavaScript(result);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user