Merge pull request #714 from sbwalker/master
added support for dynamic inclusion of global resources in _host.cshtml ( ie. global stylesheets and scripts such as those required by UI component suites )
This commit is contained in:
commit
eb9acc770c
11
Oqtane.Server/Infrastructure/Interfaces/IHostResources.cs
Normal file
11
Oqtane.Server/Infrastructure/Interfaces/IHostResources.cs
Normal file
|
@ -0,0 +1,11 @@
|
|||
using Oqtane.Models;
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace Oqtane.Infrastructure
|
||||
{
|
||||
public interface IHostResources
|
||||
{
|
||||
List<Resource> Resources { get; } // identifies global resources for an application
|
||||
}
|
||||
}
|
||||
|
|
@ -3,6 +3,7 @@
|
|||
@addTagHelper *, Microsoft.AspNetCore.Mvc.TagHelpers
|
||||
@using Microsoft.Extensions.Configuration
|
||||
@inject IConfiguration Configuration
|
||||
@model Oqtane.Pages.HostModel
|
||||
|
||||
<!DOCTYPE html>
|
||||
<html>
|
||||
|
@ -16,6 +17,7 @@
|
|||
<link id="app-manifest" rel="manifest" />
|
||||
<link rel="stylesheet" href="css/app.css" />
|
||||
<script src="js/loadjs.min.js"></script>
|
||||
@Html.Raw(@Model.Resources)
|
||||
</head>
|
||||
<body>
|
||||
@(Html.AntiForgeryToken())
|
||||
|
|
62
Oqtane.Server/Pages/_Host.cshtml.cs
Normal file
62
Oqtane.Server/Pages/_Host.cshtml.cs
Normal file
|
@ -0,0 +1,62 @@
|
|||
using Microsoft.AspNetCore.Mvc.RazorPages;
|
||||
using Oqtane.Infrastructure;
|
||||
using Oqtane.Shared;
|
||||
using System;
|
||||
using System.Linq;
|
||||
using System.Reflection;
|
||||
|
||||
namespace Oqtane.Pages
|
||||
{
|
||||
public class HostModel : PageModel
|
||||
{
|
||||
public string Resources = "";
|
||||
|
||||
public void OnGet()
|
||||
{
|
||||
var assemblies = AppDomain.CurrentDomain.GetOqtaneAssemblies();
|
||||
foreach (Assembly assembly in assemblies)
|
||||
{
|
||||
var types = assembly.GetTypes().Where(item => item.GetInterfaces().Contains(typeof(IHostResources)));
|
||||
foreach (var type in types)
|
||||
{
|
||||
var obj = Activator.CreateInstance(type) as IHostResources;
|
||||
foreach (var resource in obj.Resources)
|
||||
{
|
||||
switch (resource.ResourceType)
|
||||
{
|
||||
case ResourceType.Stylesheet:
|
||||
Resources += "<link rel=\"stylesheet\" href=\"" + resource.Url + "\"" + CrossOrigin(resource.CrossOrigin) + Integrity(resource.Integrity) + " />" + Environment.NewLine;
|
||||
break;
|
||||
case ResourceType.Script:
|
||||
Resources += "<script src=\"" + resource.Url + "\"" + CrossOrigin(resource.CrossOrigin) + Integrity(resource.Integrity) + "></script>" + Environment.NewLine;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private string CrossOrigin(string crossorigin)
|
||||
{
|
||||
if (!string.IsNullOrEmpty(crossorigin))
|
||||
{
|
||||
return " crossorigin=\"" + crossorigin + "\"";
|
||||
}
|
||||
else
|
||||
{
|
||||
return "";
|
||||
}
|
||||
}
|
||||
private string Integrity(string integrity)
|
||||
{
|
||||
if (!string.IsNullOrEmpty(integrity))
|
||||
{
|
||||
return " integrity=\"" + integrity + "\"";
|
||||
}
|
||||
else
|
||||
{
|
||||
return "";
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user