mirror of
https://github.com/OrchardCMS/Orchard.git
synced 2025-10-15 19:54:57 +08:00
Require() now returns RequireSettings which has a fluent api. Dropped more complex overloads of Require in favor of it.
--HG-- branch : dev
This commit is contained in:
@@ -1,7 +1,7 @@
|
|||||||
@model Orchard.Core.PublishLater.ViewModels.PublishLaterViewModel
|
@model Orchard.Core.PublishLater.ViewModels.PublishLaterViewModel
|
||||||
@{
|
@{
|
||||||
Script.RequireFoot("jQueryUtils_TimePicker");
|
Script.Require("jQueryUtils_TimePicker");
|
||||||
Script.RequireFoot("jQueryUI_DatePicker");
|
Script.Require("jQueryUI_DatePicker");
|
||||||
Style.Require("PublishLater_DatePicker");
|
Style.Require("PublishLater_DatePicker");
|
||||||
Style.Require("jQueryUtils_TimePicker");
|
Style.Require("jQueryUtils_TimePicker");
|
||||||
Style.Require("jQueryUI_DatePicker");
|
Style.Require("jQueryUI_DatePicker");
|
||||||
|
@@ -69,11 +69,6 @@ namespace Orchard.Core.Shapes {
|
|||||||
return tagBuilder;
|
return tagBuilder;
|
||||||
}
|
}
|
||||||
|
|
||||||
//[Shape]
|
|
||||||
//public HtmlString Resource(ResourceRequiredContext Resource, RequireSettings DefaultSettings, string AppPath) {
|
|
||||||
// return new HtmlString(Resource.GetTagBuilder(DefaultSettings, AppPath).ToString());
|
|
||||||
//}
|
|
||||||
|
|
||||||
[Shape]
|
[Shape]
|
||||||
public void HeadScripts(HtmlHelper Html, IResourceManager ResourceManager) {
|
public void HeadScripts(HtmlHelper Html, IResourceManager ResourceManager) {
|
||||||
WriteResources(Html, ResourceManager, "script", ResourceLocation.Head, null);
|
WriteResources(Html, ResourceManager, "script", ResourceLocation.Head, null);
|
||||||
|
@@ -3,8 +3,8 @@
|
|||||||
<%
|
<%
|
||||||
// todo: use Style.Require and Script.Require when this is converted to use a base Orchard view type.
|
// todo: use Style.Require and Script.Require when this is converted to use a base Orchard view type.
|
||||||
var rm = Html.Resolve<IResourceManager>();
|
var rm = Html.Resolve<IResourceManager>();
|
||||||
rm.Require(new RequireSettings { ResourceType = "stylesheet", ResourceName = "Switchable" });
|
rm.Require("stylesheet", "Switchable");
|
||||||
rm.Require(new RequireSettings { ResourceType = "script", ResourceName = "Switchable", Location = ResourceLocation.Foot });
|
rm.Require("script", "Switchable");
|
||||||
var cssClass = string.Format("{0} switchable", Model);
|
var cssClass = string.Format("{0} switchable", Model);
|
||||||
|
|
||||||
%>
|
%>
|
||||||
|
@@ -4,8 +4,8 @@
|
|||||||
Style.Require("jQueryUtils_TimePicker");
|
Style.Require("jQueryUtils_TimePicker");
|
||||||
Style.Require("jQueryUI_DatePicker");
|
Style.Require("jQueryUI_DatePicker");
|
||||||
Style.Require("ArchiveLater_DatePicker");
|
Style.Require("ArchiveLater_DatePicker");
|
||||||
Script.RequireFoot("jQueryUI_DatePicker");
|
Script.Require("jQueryUI_DatePicker");
|
||||||
Script.RequireFoot("jQueryUtils_TimePicker");
|
Script.Require("jQueryUtils_TimePicker");
|
||||||
}
|
}
|
||||||
|
|
||||||
<fieldset>
|
<fieldset>
|
||||||
|
@@ -3,7 +3,7 @@
|
|||||||
@{
|
@{
|
||||||
BlogPostArchiveViewModel model = Model.Archives;
|
BlogPostArchiveViewModel model = Model.Archives;
|
||||||
Style.Require("BlogsArchives");
|
Style.Require("BlogsArchives");
|
||||||
Script.RequireFoot("BlogsArchives");
|
Script.Require("BlogsArchives");
|
||||||
}
|
}
|
||||||
<div class="archives">
|
<div class="archives">
|
||||||
<h3>@T("Archives")</h3>
|
<h3>@T("Archives")</h3>
|
||||||
|
@@ -4,7 +4,7 @@
|
|||||||
<%@ Import Namespace="Orchard.UI.Resources" %>
|
<%@ Import Namespace="Orchard.UI.Resources" %>
|
||||||
<%
|
<%
|
||||||
Style.Require("Green_Archives");
|
Style.Require("Green_Archives");
|
||||||
Script.Require(new RequireSettings {ResourceName = "archives.js", Location = ResourceLocation.Foot});
|
Script.Require("BlogsArchives");
|
||||||
%>
|
%>
|
||||||
<div class="archives">
|
<div class="archives">
|
||||||
<h4 class="collapsible"><%: T("Archives") %></h4><%
|
<h4 class="collapsible"><%: T("Archives") %></h4><%
|
||||||
|
@@ -10,7 +10,7 @@ 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);
|
||||||
void Require(RequireSettings settings);
|
RequireSettings Require(string resourceType, string resourceName);
|
||||||
void RegisterLink(LinkEntry link);
|
void RegisterLink(LinkEntry link);
|
||||||
void SetMeta(MetaEntry meta);
|
void SetMeta(MetaEntry meta);
|
||||||
void AppendMeta(MetaEntry meta, string contentSeparator);
|
void AppendMeta(MetaEntry meta, string contentSeparator);
|
||||||
|
@@ -12,21 +12,73 @@ namespace Orchard.UI.Resources {
|
|||||||
public ResourceLocation Location { get; set; }
|
public ResourceLocation Location { get; set; }
|
||||||
public Action<ResourceDefinition> InlineDefinition { get; set; }
|
public Action<ResourceDefinition> InlineDefinition { get; set; }
|
||||||
|
|
||||||
|
public RequireSettings AtHead() {
|
||||||
|
return AtLocation(ResourceLocation.Head);
|
||||||
|
}
|
||||||
|
|
||||||
|
public RequireSettings AtFoot() {
|
||||||
|
return AtLocation(ResourceLocation.Foot);
|
||||||
|
}
|
||||||
|
|
||||||
|
public RequireSettings AtLocation(ResourceLocation location) {
|
||||||
|
// if head is specified it takes precedence since it's safer than foot
|
||||||
|
Location = (ResourceLocation)Math.Max((int)Location, (int)location);
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public RequireSettings UseCulture(string cultureName) {
|
||||||
|
if (!String.IsNullOrEmpty(cultureName)) {
|
||||||
|
Culture = cultureName;
|
||||||
|
}
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public RequireSettings UseDebugMode() {
|
||||||
|
return UseDebugMode(true);
|
||||||
|
}
|
||||||
|
|
||||||
|
public RequireSettings UseDebugMode(bool debugMode) {
|
||||||
|
DebugMode |= debugMode;
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public RequireSettings UseCdn() {
|
||||||
|
return UseCdn(true);
|
||||||
|
}
|
||||||
|
|
||||||
|
public RequireSettings UseCdn(bool cdn) {
|
||||||
|
CdnMode |= cdn;
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public RequireSettings WithMinimumVersion(string minimumVersion) {
|
||||||
|
MinimumVersion = String.IsNullOrEmpty(MinimumVersion)
|
||||||
|
? minimumVersion
|
||||||
|
: (MinimumVersion.CompareTo(minimumVersion) > 0 ? minimumVersion : MinimumVersion);
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public RequireSettings WithBasePath(string basePath) {
|
||||||
|
BasePath = basePath;
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public RequireSettings Define(Action<ResourceDefinition> resourceDefinition) {
|
||||||
|
InlineDefinition = resourceDefinition ?? InlineDefinition;
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
public RequireSettings Combine(RequireSettings other) {
|
public RequireSettings Combine(RequireSettings other) {
|
||||||
return new RequireSettings {
|
return (new RequireSettings {
|
||||||
Name = Name,
|
Name = Name,
|
||||||
Type = Type,
|
Type = Type
|
||||||
InlineDefinition = other.InlineDefinition ?? InlineDefinition,
|
}).AtLocation(other.Location)
|
||||||
BasePath = String.IsNullOrEmpty(other.BasePath) ? BasePath : other.BasePath,
|
.WithBasePath(other.BasePath)
|
||||||
CdnMode = CdnMode || other.CdnMode,
|
.UseCdn(other.CdnMode)
|
||||||
DebugMode = DebugMode || other.DebugMode,
|
.UseDebugMode(other.DebugMode)
|
||||||
Culture = String.IsNullOrEmpty(other.Culture) ? Culture : other.Culture,
|
.UseCulture(other.Culture)
|
||||||
MinimumVersion = String.IsNullOrEmpty(MinimumVersion)
|
.WithMinimumVersion(other.MinimumVersion)
|
||||||
? other.MinimumVersion
|
.Define(other.InlineDefinition);
|
||||||
: MinimumVersion.CompareTo(other.MinimumVersion) > 0 ? other.MinimumVersion : MinimumVersion,
|
|
||||||
// if head is specified it takes precedence since it's safer than foot
|
|
||||||
Location = (ResourceLocation) Math.Max((int)Location, (int)other.Location),
|
|
||||||
};
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -4,6 +4,7 @@ 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 JetBrains.Annotations;
|
||||||
|
|
||||||
namespace Orchard.UI.Resources {
|
namespace Orchard.UI.Resources {
|
||||||
public class ResourceManager : IResourceManager {
|
public class ResourceManager : IResourceManager {
|
||||||
@@ -26,17 +27,30 @@ namespace Orchard.UI.Resources {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public virtual void Require(RequireSettings settings) {
|
public virtual RequireSettings Require(string resourceType, [NotNull] string resourceName) {
|
||||||
RequireSettings existingSettings;
|
if (resourceType == null) {
|
||||||
var key = new Tuple<string, string>(settings.Type, settings.Name);
|
throw new ArgumentNullException("resourceType");
|
||||||
if (_required.TryGetValue(key, out existingSettings)) {
|
|
||||||
settings = settings.Combine(existingSettings);
|
|
||||||
}
|
}
|
||||||
_builtResources[settings.Type] = null;
|
if (resourceName == null) {
|
||||||
_required[key] = settings;
|
throw new ArgumentNullException("resourceName");
|
||||||
|
}
|
||||||
|
RequireSettings settings;
|
||||||
|
var key = new Tuple<string, string>(resourceType, resourceName);
|
||||||
|
if (!_required.TryGetValue(key, out settings)) {
|
||||||
|
settings = new RequireSettings {Type = resourceType, Name = resourceName};
|
||||||
|
_required[key] = settings;
|
||||||
|
}
|
||||||
|
_builtResources[resourceType] = null;
|
||||||
|
return settings;
|
||||||
}
|
}
|
||||||
|
|
||||||
public virtual void NotRequired(string resourceType, string resourceName) {
|
public virtual void NotRequired(string resourceType, string resourceName) {
|
||||||
|
if (resourceType == null) {
|
||||||
|
throw new ArgumentNullException("resourceType");
|
||||||
|
}
|
||||||
|
if (resourceName == null) {
|
||||||
|
throw new ArgumentNullException("resourceName");
|
||||||
|
}
|
||||||
var key = new Tuple<string, string>(resourceType, resourceName);
|
var key = new Tuple<string, string>(resourceType, resourceName);
|
||||||
_builtResources[resourceType] = null;
|
_builtResources[resourceType] = null;
|
||||||
_required.Remove(key);
|
_required.Remove(key);
|
||||||
|
@@ -4,6 +4,7 @@ using System.Linq;
|
|||||||
using System.Text;
|
using System.Text;
|
||||||
using System.Web.Mvc;
|
using System.Web.Mvc;
|
||||||
using System.Web.UI;
|
using System.Web.UI;
|
||||||
|
using JetBrains.Annotations;
|
||||||
|
|
||||||
namespace Orchard.UI.Resources {
|
namespace Orchard.UI.Resources {
|
||||||
public class ResourceRegister {
|
public class ResourceRegister {
|
||||||
@@ -17,70 +18,23 @@ namespace Orchard.UI.Resources {
|
|||||||
_resourceType = resourceType;
|
_resourceType = resourceType;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void Require(string resourceName) {
|
public RequireSettings Require(string resourceName) {
|
||||||
Require(resourceName, null, null);
|
return Require(resourceName, (string)null);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void Require(string resourceName, string minimumVersion) {
|
public virtual RequireSettings Require(string resourceName, string minimumVersion) {
|
||||||
Require(resourceName, minimumVersion, null);
|
var settings = _resourceManager.Require(_resourceType, resourceName)
|
||||||
}
|
.WithMinimumVersion(minimumVersion);
|
||||||
|
|
||||||
public void Require(string resourceName, Action<ResourceDefinition> inlineDefinition) {
|
|
||||||
Require(resourceName, null, inlineDefinition);
|
|
||||||
}
|
|
||||||
|
|
||||||
public void Require(string resourceName, string minimumVersion, Action<ResourceDefinition> inlineDefinition) {
|
|
||||||
Require(resourceName, new RequireSettings {
|
|
||||||
MinimumVersion = minimumVersion,
|
|
||||||
InlineDefinition = inlineDefinition,
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
public void Require(RequireSettings settings) {
|
|
||||||
Require(settings.Name, settings);
|
|
||||||
}
|
|
||||||
|
|
||||||
protected void Require(string resourceName, RequireSettings settings) {
|
|
||||||
if (settings == null) {
|
|
||||||
throw new ArgumentNullException("settings");
|
|
||||||
}
|
|
||||||
settings.Type = String.IsNullOrEmpty(settings.Type) ? _resourceType : settings.Type;
|
|
||||||
settings.Name = String.IsNullOrEmpty(settings.Name) ? resourceName : settings.Name;
|
|
||||||
if (_templateContainer != null) {
|
if (_templateContainer != null) {
|
||||||
settings.BasePath = ResourceDefinition.GetBasePathFromViewPath(_resourceType, _templateContainer.AppRelativeVirtualPath);
|
settings.WithBasePath(ResourceDefinition.GetBasePathFromViewPath(_resourceType, _templateContainer.AppRelativeVirtualPath));
|
||||||
}
|
}
|
||||||
_resourceManager.Require(settings);
|
return settings;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public class ScriptRegister : ResourceRegister {
|
public class ScriptRegister : ResourceRegister {
|
||||||
public ScriptRegister(IViewDataContainer container, IResourceManager resourceManager) : base(container, resourceManager, "script") {
|
public ScriptRegister(IViewDataContainer container, IResourceManager resourceManager) : base(container, resourceManager, "script") {
|
||||||
}
|
}
|
||||||
|
// todo: Head/Tail registration
|
||||||
public void RequireFoot(string scriptName) {
|
|
||||||
RequireFoot(scriptName, null, null);
|
|
||||||
}
|
|
||||||
|
|
||||||
public void RequireFoot(string scriptName, string minimumVersion) {
|
|
||||||
RequireFoot(scriptName, minimumVersion, null);
|
|
||||||
}
|
|
||||||
|
|
||||||
public void RequireFoot(string scriptName, Action<ResourceDefinition> inlineDefinition) {
|
|
||||||
RequireFoot(scriptName, null, inlineDefinition);
|
|
||||||
}
|
|
||||||
|
|
||||||
public void RequireFoot(string scriptName, string minimumVersion, Action<ResourceDefinition> inlineDefinition) {
|
|
||||||
Require(scriptName, new RequireSettings {
|
|
||||||
MinimumVersion = minimumVersion,
|
|
||||||
InlineDefinition = inlineDefinition,
|
|
||||||
Location = ResourceLocation.Foot
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
public void RequireFoot(RequireSettings settings) {
|
|
||||||
settings.Location = ResourceLocation.Foot;
|
|
||||||
Require(settings.Name, settings);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user