mirror of
https://github.com/OrchardCMS/Orchard.git
synced 2025-10-15 19:54:57 +08:00
Added ability to Script/Style/ResourceManager.Include() with just a plain url.
--HG-- branch : dev
This commit is contained in:
@@ -2,7 +2,7 @@
|
|||||||
@{
|
@{
|
||||||
Script.Require("jQuery", "1.4.2");
|
Script.Require("jQuery", "1.4.2");
|
||||||
Script.Require("ShapesBase");
|
Script.Require("ShapesBase");
|
||||||
Style.Require("SafeMode").Define(d => d.SetUrl("site.css"));
|
Style.Include("site.css");
|
||||||
RegisterLink(new LinkEntry { Condition = "lte IE 6", Rel = "stylesheet", Type="text/css", Href = Href("../Styles/ie6.css")}.AddAttribute("media", "screen, projection"));
|
RegisterLink(new LinkEntry { Condition = "lte IE 6", Rel = "stylesheet", Type="text/css", Href = Href("../Styles/ie6.css")}.AddAttribute("media", "screen, projection"));
|
||||||
}
|
}
|
||||||
<div id="header">
|
<div id="header">
|
||||||
|
@@ -13,6 +13,8 @@ namespace Orchard.UI.Resources {
|
|||||||
ResourceManifest DynamicResources { get; }
|
ResourceManifest DynamicResources { get; }
|
||||||
ResourceDefinition FindResource(RequireSettings settings);
|
ResourceDefinition FindResource(RequireSettings settings);
|
||||||
void NotRequired(string resourceType, string resourceName);
|
void NotRequired(string resourceType, string resourceName);
|
||||||
|
RequireSettings Include(string resourceType, string resourcePath);
|
||||||
|
RequireSettings Include(string resourceType, string resourcePath, string relativeFromPath);
|
||||||
RequireSettings Require(string resourceType, string resourceName);
|
RequireSettings Require(string resourceType, string resourceName);
|
||||||
void RegisterHeadScript(string script);
|
void RegisterHeadScript(string script);
|
||||||
void RegisterFootScript(string script);
|
void RegisterFootScript(string script);
|
||||||
|
@@ -4,6 +4,8 @@ using System.Collections.Generic;
|
|||||||
using System.Collections.Specialized;
|
using System.Collections.Specialized;
|
||||||
using System.Globalization;
|
using System.Globalization;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
|
using System.Web;
|
||||||
|
using System.Web.Hosting;
|
||||||
using JetBrains.Annotations;
|
using JetBrains.Annotations;
|
||||||
|
|
||||||
namespace Orchard.UI.Resources {
|
namespace Orchard.UI.Resources {
|
||||||
@@ -29,7 +31,7 @@ namespace Orchard.UI.Resources {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public virtual RequireSettings Require(string resourceType, [NotNull] string resourceName) {
|
public virtual RequireSettings Require(string resourceType, string resourceName) {
|
||||||
if (resourceType == null) {
|
if (resourceType == null) {
|
||||||
throw new ArgumentNullException("resourceType");
|
throw new ArgumentNullException("resourceType");
|
||||||
}
|
}
|
||||||
@@ -46,6 +48,32 @@ namespace Orchard.UI.Resources {
|
|||||||
return settings;
|
return settings;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public virtual RequireSettings Include(string resourceType, string resourcePath) {
|
||||||
|
return Include(resourceType, resourcePath, null);
|
||||||
|
}
|
||||||
|
|
||||||
|
public virtual RequireSettings Include(string resourceType, string resourcePath, string relativeFromPath) {
|
||||||
|
if (resourceType == null) {
|
||||||
|
throw new ArgumentNullException("resourceType");
|
||||||
|
}
|
||||||
|
if (resourcePath == null) {
|
||||||
|
throw new ArgumentNullException("resourcePath");
|
||||||
|
}
|
||||||
|
|
||||||
|
if (VirtualPathUtility.IsAppRelative(resourcePath)) {
|
||||||
|
// ~/ ==> convert to absolute path (e.g. /orchard/..)
|
||||||
|
resourcePath = VirtualPathUtility.ToAbsolute(resourcePath);
|
||||||
|
}
|
||||||
|
else if (!VirtualPathUtility.IsAbsolute(resourcePath) && !Uri.IsWellFormedUriString(resourcePath, UriKind.Absolute)) {
|
||||||
|
// appears to be a relative path (e.g. 'foo.js' or '../foo.js', not "/foo.js" or "http://..")
|
||||||
|
if (String.IsNullOrEmpty(relativeFromPath)) {
|
||||||
|
throw new InvalidOperationException("ResourcePath cannot be relative unless a base relative path is also provided.");
|
||||||
|
}
|
||||||
|
resourcePath = VirtualPathUtility.ToAbsolute(VirtualPathUtility.Combine(relativeFromPath, resourcePath));
|
||||||
|
}
|
||||||
|
return Require(resourceType, resourcePath).Define(d => d.SetUrl(resourcePath));
|
||||||
|
}
|
||||||
|
|
||||||
public virtual void RegisterHeadScript(string script) {
|
public virtual void RegisterHeadScript(string script) {
|
||||||
if (_headScripts == null) {
|
if (_headScripts == null) {
|
||||||
_headScripts = new List<string>();
|
_headScripts = new List<string>();
|
||||||
|
@@ -9,17 +9,17 @@ using Microsoft.WebPages;
|
|||||||
|
|
||||||
namespace Orchard.UI.Resources {
|
namespace Orchard.UI.Resources {
|
||||||
public class ResourceRegister {
|
public class ResourceRegister {
|
||||||
private string _baseVirtualPath;
|
private string _viewVirtualPath;
|
||||||
|
|
||||||
public ResourceRegister(IViewDataContainer container, IResourceManager resourceManager, string resourceType) {
|
public ResourceRegister(IViewDataContainer container, IResourceManager resourceManager, string resourceType) {
|
||||||
var templateControl = container as TemplateControl;
|
var templateControl = container as TemplateControl;
|
||||||
if (templateControl != null) {
|
if (templateControl != null) {
|
||||||
_baseVirtualPath = templateControl.AppRelativeVirtualPath;
|
_viewVirtualPath = templateControl.AppRelativeVirtualPath;
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
var webPage = container as WebPageBase;
|
var webPage = container as WebPageBase;
|
||||||
if (webPage != null) {
|
if (webPage != null) {
|
||||||
_baseVirtualPath = webPage.VirtualPath;
|
_viewVirtualPath = webPage.VirtualPath;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
ResourceManager = resourceManager;
|
ResourceManager = resourceManager;
|
||||||
@@ -33,11 +33,21 @@ namespace Orchard.UI.Resources {
|
|||||||
return Require(resourceName, (string)null);
|
return Require(resourceName, (string)null);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public RequireSettings Include(string resourcePath) {
|
||||||
|
if (resourcePath == null) {
|
||||||
|
throw new ArgumentNullException("resourcePath");
|
||||||
|
}
|
||||||
|
return ResourceManager.Include(ResourceType, resourcePath, ResourceDefinition.GetBasePathFromViewPath(ResourceType, _viewVirtualPath));
|
||||||
|
}
|
||||||
|
|
||||||
public virtual RequireSettings Require(string resourceName, string minimumVersion) {
|
public virtual RequireSettings Require(string resourceName, string minimumVersion) {
|
||||||
|
if (resourceName == null) {
|
||||||
|
throw new ArgumentNullException("resourceName");
|
||||||
|
}
|
||||||
var settings = ResourceManager.Require(ResourceType, resourceName)
|
var settings = ResourceManager.Require(ResourceType, resourceName)
|
||||||
.WithMinimumVersion(minimumVersion);
|
.WithMinimumVersion(minimumVersion);
|
||||||
if (_baseVirtualPath != null) {
|
if (_viewVirtualPath != null) {
|
||||||
settings.WithBasePath(ResourceDefinition.GetBasePathFromViewPath(ResourceType, _baseVirtualPath));
|
settings.WithBasePath(ResourceDefinition.GetBasePathFromViewPath(ResourceType, _viewVirtualPath));
|
||||||
}
|
}
|
||||||
return settings;
|
return settings;
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user