Skip to content

Commit bb57930

Browse files
authored
Merge pull request #6812 from donker/cdf-remove-fromsrc
Remove FromSrc in the new CDF solution in favor of CreateX method.
2 parents 558e967 + 2b8d308 commit bb57930

File tree

14 files changed

+131
-205
lines changed

14 files changed

+131
-205
lines changed

DNN Platform/DotNetNuke.Abstractions/ClientResources/IClientResourceController.cs

Lines changed: 39 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,20 +27,56 @@ public interface IClientResourceController
2727
/// <summary>
2828
/// Create a new font resource.
2929
/// </summary>
30+
/// <param name="sourcePath">The source URL to set.</param>
3031
/// <returns>An <see cref="IFontResource"/> instance representing the created font resource.</returns>
31-
IFontResource CreateFont();
32+
IFontResource CreateFont(string sourcePath);
33+
34+
/// <summary>
35+
/// Create a new font resource.
36+
/// </summary>
37+
/// <param name="sourcePath">The source URL to set.</param>
38+
/// <param name="pathNameAlias">The path alias to set.</param>
39+
/// <returns>An <see cref="IFontResource"/> instance representing the created font resource.</returns>
40+
IFontResource CreateFont(string sourcePath, string pathNameAlias);
41+
42+
/// <summary>
43+
/// Create a new font resource.
44+
/// </summary>
45+
/// <param name="sourcePath">The source URL to set.</param>
46+
/// <param name="pathNameAlias">The path alias to set.</param>
47+
/// <param name="mimeType">The MIME type of the resource.</param>
48+
/// <returns>An <see cref="IFontResource"/> instance representing the created font resource.</returns>
49+
IFontResource CreateFont(string sourcePath, string pathNameAlias, string mimeType);
3250

3351
/// <summary>
3452
/// Create a new script resource.
3553
/// </summary>
54+
/// <param name="sourcePath">The source URL to set.</param>
3655
/// <returns>An <see cref="IScriptResource"/> instance representing the created script resource.</returns>
37-
IScriptResource CreateScript();
56+
IScriptResource CreateScript(string sourcePath);
57+
58+
/// <summary>
59+
/// Create a new script resource.
60+
/// </summary>
61+
/// <param name="sourcePath">The source URL to set.</param>
62+
/// <param name="pathNameAlias">The path alias to set.</param>
63+
/// <returns>An <see cref="IScriptResource"/> instance representing the created script resource.</returns>
64+
IScriptResource CreateScript(string sourcePath, string pathNameAlias);
65+
66+
/// <summary>
67+
/// Creates a new stylesheet resource.
68+
/// </summary>
69+
/// <param name="sourcePath">The source URL to set.</param>
70+
/// <returns>An <see cref="IStylesheetResource"/> instance representing the created stylesheet resource.</returns>
71+
IStylesheetResource CreateStylesheet(string sourcePath);
3872

3973
/// <summary>
4074
/// Creates a new stylesheet resource.
4175
/// </summary>
76+
/// <param name="sourcePath">The source URL to set.</param>
77+
/// <param name="pathNameAlias">The path alias to set.</param>
4278
/// <returns>An <see cref="IStylesheetResource"/> instance representing the created stylesheet resource.</returns>
43-
IStylesheetResource CreateStylesheet();
79+
IStylesheetResource CreateStylesheet(string sourcePath, string pathNameAlias);
4480

4581
/// <summary>
4682
/// Registers a path name alias for resolving resource paths.

DNN Platform/DotNetNuke.Web.Client.ResourceManager/ClientResourceController.cs

Lines changed: 70 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -59,21 +59,85 @@ public void AddStylesheet(IStylesheetResource stylesheet)
5959
}
6060

6161
/// <inheritdoc />
62-
public IFontResource CreateFont()
62+
public IFontResource CreateFont(string sourcePath)
6363
{
64-
return new Models.FontResource(this);
64+
var font = new Models.FontResource(this);
65+
font.FilePath = sourcePath;
66+
67+
switch (font.FilePath?.Substring(font.FilePath.LastIndexOf('.')).ToLowerInvariant())
68+
{
69+
case ".eot":
70+
font.Type = "application/vnd.ms-fontobject";
71+
break;
72+
case ".woff":
73+
font.Type = "font/woff";
74+
break;
75+
case ".woff2":
76+
font.Type = "font/woff2";
77+
break;
78+
case ".ttf":
79+
font.Type = "font/ttf";
80+
break;
81+
case ".svg":
82+
font.Type = "image/svg+xml";
83+
break;
84+
case ".otf":
85+
font.Type = "font/otf";
86+
break;
87+
default:
88+
font.Type = "application/octet-stream";
89+
break;
90+
}
91+
92+
return font;
93+
}
94+
95+
/// <inheritdoc />
96+
public IFontResource CreateFont(string sourcePath, string pathNameAlias)
97+
{
98+
var font = this.CreateFont(sourcePath);
99+
font.PathNameAlias = pathNameAlias;
100+
return font;
101+
}
102+
103+
/// <inheritdoc />
104+
public IFontResource CreateFont(string sourcePath, string pathNameAlias, string mimeType)
105+
{
106+
var font = this.CreateFont(sourcePath, pathNameAlias);
107+
font.Type = mimeType;
108+
return font;
109+
}
110+
111+
/// <inheritdoc />
112+
public IScriptResource CreateScript(string sourcePath)
113+
{
114+
var script = new Models.ScriptResource(this);
115+
script.FilePath = sourcePath;
116+
return script;
117+
}
118+
119+
/// <inheritdoc />
120+
public IScriptResource CreateScript(string sourcePath, string pathNameAlias)
121+
{
122+
var script = this.CreateScript(sourcePath);
123+
script.PathNameAlias = pathNameAlias;
124+
return script;
65125
}
66126

67127
/// <inheritdoc />
68-
public IScriptResource CreateScript()
128+
public IStylesheetResource CreateStylesheet(string sourcePath)
69129
{
70-
return new Models.ScriptResource(this);
130+
var stylesheet = new Models.StylesheetResource(this);
131+
stylesheet.FilePath = sourcePath;
132+
return stylesheet;
71133
}
72134

73135
/// <inheritdoc />
74-
public IStylesheetResource CreateStylesheet()
136+
public IStylesheetResource CreateStylesheet(string sourcePath, string pathNameAlias)
75137
{
76-
return new Models.StylesheetResource(this);
138+
var stylesheet = this.CreateStylesheet(sourcePath);
139+
stylesheet.PathNameAlias = pathNameAlias;
140+
return stylesheet;
77141
}
78142

79143
/// <inheritdoc />

DNN Platform/DotNetNuke.Web.Client.ResourceManager/FontResourceExtensions.cs

Lines changed: 0 additions & 83 deletions
This file was deleted.

DNN Platform/DotNetNuke.Web.Client.ResourceManager/ScriptResourceExtensions.cs

Lines changed: 0 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -13,46 +13,6 @@ namespace DotNetNuke.Web.Client.ResourceManager
1313
/// </summary>
1414
public static class ScriptResourceExtensions
1515
{
16-
/// <summary>
17-
/// Sets the source URL of the resource.
18-
/// </summary>
19-
/// <param name="input">The resource to set the source URL for.</param>
20-
/// <param name="sourcePath">The source URL to set.</param>
21-
/// <returns>The resource with the source URL set.</returns>
22-
/// <typeparam name="T">The type of resource, which must implement <see cref="IScriptResource"/>.</typeparam>
23-
public static T FromSrc<T>(this T input, string sourcePath)
24-
where T : IScriptResource
25-
{
26-
if (input == null)
27-
{
28-
throw new ArgumentNullException(nameof(input));
29-
}
30-
31-
input.FilePath = sourcePath;
32-
return input;
33-
}
34-
35-
/// <summary>
36-
/// Sets the source URL and path alias of the resource.
37-
/// </summary>
38-
/// <param name="input">The resource to set the source URL and path alias for.</param>
39-
/// <param name="sourcePath">The source URL to set.</param>
40-
/// <param name="pathNameAlias">The path alias to set.</param>
41-
/// <returns>The resource with the source URL and path alias set.</returns>
42-
/// <typeparam name="T">The type of resource, which must implement <see cref="IScriptResource"/>.</typeparam>
43-
public static T FromSrc<T>(this T input, string sourcePath, string pathNameAlias)
44-
where T : IScriptResource
45-
{
46-
if (input == null)
47-
{
48-
throw new ArgumentNullException(nameof(input));
49-
}
50-
51-
input.FilePath = sourcePath;
52-
input.PathNameAlias = pathNameAlias;
53-
return input;
54-
}
55-
5616
/// <summary>
5717
/// Sets the priority of the resource.
5818
/// </summary>

DNN Platform/DotNetNuke.Web.Client.ResourceManager/StylesheetResourceExtensions.cs

Lines changed: 0 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -13,46 +13,6 @@ namespace DotNetNuke.Web.Client.ResourceManager
1313
/// </summary>
1414
public static class StylesheetResourceExtensions
1515
{
16-
/// <summary>
17-
/// Sets the source URL of the resource.
18-
/// </summary>
19-
/// <param name="input">The resource to set the source URL for.</param>
20-
/// <param name="sourcePath">The source URL to set.</param>
21-
/// <returns>The resource with the source URL set.</returns>
22-
/// <typeparam name="T">The type of resource, which must implement <see cref="IStylesheetResource"/>.</typeparam>
23-
public static T FromSrc<T>(this T input, string sourcePath)
24-
where T : IStylesheetResource
25-
{
26-
if (input == null)
27-
{
28-
throw new ArgumentNullException(nameof(input));
29-
}
30-
31-
input.FilePath = sourcePath;
32-
return input;
33-
}
34-
35-
/// <summary>
36-
/// Sets the source URL and path alias of the resource.
37-
/// </summary>
38-
/// <param name="input">The resource to set the source URL and path alias for.</param>
39-
/// <param name="sourcePath">The source URL to set.</param>
40-
/// <param name="pathNameAlias">The path alias to set.</param>
41-
/// <returns>The resource with the source URL and path alias set.</returns>
42-
/// <typeparam name="T">The type of resource, which must implement <see cref="IStylesheetResource"/>.</typeparam>
43-
public static T FromSrc<T>(this T input, string sourcePath, string pathNameAlias)
44-
where T : IStylesheetResource
45-
{
46-
if (input == null)
47-
{
48-
throw new ArgumentNullException(nameof(input));
49-
}
50-
51-
input.FilePath = sourcePath;
52-
input.PathNameAlias = pathNameAlias;
53-
return input;
54-
}
55-
5616
/// <summary>
5717
/// Sets the priority of the resource.
5818
/// </summary>

DNN Platform/DotNetNuke.Web.Client/ClientResourceManager.cs

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -360,8 +360,7 @@ public static void RegisterScript(
360360
IDictionary<string, string> htmlAttributes)
361361
{
362362
var controller = GetClientResourcesController(page);
363-
var script = controller.CreateScript()
364-
.FromSrc(filePath)
363+
var script = controller.CreateScript(filePath)
365364
.SetPriority(priority)
366365
.SetProvider(provider)
367366
.SetNameAndVersion(name, version, false);
@@ -499,8 +498,7 @@ public static void RegisterStyleSheet(Page page, string filePath, int priority,
499498
}
500499

501500
var controller = GetClientResourcesController(page);
502-
var stylesheet = controller.CreateStylesheet()
503-
.FromSrc(filePath)
501+
var stylesheet = controller.CreateStylesheet(filePath)
504502
.SetPriority(priority)
505503
.SetProvider(provider)
506504
.SetNameAndVersion(name, version, false);

DNN Platform/DotNetNuke.Web.Client/Controls/DnnCssInclude.cs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,8 +33,7 @@ public DnnCssInclude(IClientResourceController clientResourceController)
3333
/// <inheritdoc/>
3434
protected override void OnInit(EventArgs e)
3535
{
36-
this.clientResourceController.CreateStylesheet()
37-
.FromSrc(this.FilePath, this.PathNameAlias)
36+
this.clientResourceController.CreateStylesheet(this.FilePath, this.PathNameAlias)
3837
.SetNameAndVersion(this.Name, this.Version, this.ForceVersion)
3938
.SetProvider(this.ForceProvider)
4039
.SetPriority(this.Priority)

DNN Platform/DotNetNuke.Web.Client/Controls/DnnHtmlInclude.cs

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -67,8 +67,7 @@ private void RegisterIncludes(IEnumerable<BasicFile> files, ClientDependencyType
6767
switch (dependencyType)
6868
{
6969
case ClientDependencyType.Css:
70-
var styleSheet = this.clientResourceController.CreateStylesheet()
71-
.FromSrc(file.FilePath)
70+
var styleSheet = this.clientResourceController.CreateStylesheet(file.FilePath)
7271
.SetProvider(file.ForceProvider)
7372
.SetPriority(file.Priority);
7473
foreach (var a in file.HtmlAttributes)
@@ -79,8 +78,7 @@ private void RegisterIncludes(IEnumerable<BasicFile> files, ClientDependencyType
7978
styleSheet.Register();
8079
break;
8180
case ClientDependencyType.Javascript:
82-
var script = this.clientResourceController.CreateScript()
83-
.FromSrc(file.FilePath)
81+
var script = this.clientResourceController.CreateScript(file.FilePath)
8482
.SetProvider(file.ForceProvider)
8583
.SetPriority(file.Priority);
8684
foreach (var a in file.HtmlAttributes)

DNN Platform/DotNetNuke.Web.Client/Controls/DnnJsInclude.cs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,7 @@ public DnnJsInclude(IClientResourceController clientResourceController)
3131

3232
protected override void OnInit(EventArgs e)
3333
{
34-
this.clientResourceController.CreateScript()
35-
.FromSrc(this.FilePath, this.PathNameAlias)
34+
this.clientResourceController.CreateScript(this.FilePath, this.PathNameAlias)
3635
.SetNameAndVersion(this.Name, this.Version, this.ForceVersion)
3736
.SetProvider(this.ForceProvider)
3837
.SetPriority(this.Priority)

0 commit comments

Comments
 (0)