mirror of
https://github.com/OrchardCMS/Orchard.git
synced 2025-10-15 19:54:57 +08:00
Added a SiteSetting for whether to load resources in debug mode (use app setting, enabled, disabled)
--HG-- branch : dev
This commit is contained in:
@@ -1,4 +1,5 @@
|
||||
using Orchard.Data.Migration;
|
||||
using System.Data;
|
||||
using Orchard.Data.Migration;
|
||||
|
||||
namespace Orchard.Core.Settings.DataMigrations {
|
||||
public class SettingsDataMigration : DataMigrationImpl {
|
||||
@@ -93,5 +94,12 @@ namespace Orchard.Core.Settings.DataMigrations {
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
public int UpdateFrom1() {
|
||||
SchemaBuilder.AlterTable("SiteSettingsPartRecord", table => table
|
||||
.AddColumn("ResourceDebugMode", DbType.String, column => column.WithDefault("FromAppSetting"))
|
||||
);
|
||||
return 2;
|
||||
}
|
||||
}
|
||||
}
|
@@ -27,5 +27,9 @@ namespace Orchard.Core.Settings.Models {
|
||||
get { return Record.SiteCulture; }
|
||||
set { Record.SiteCulture = value; }
|
||||
}
|
||||
public ResourceDebugMode ResourceDebugMode {
|
||||
get { return Record.ResourceDebugMode; }
|
||||
set { Record.ResourceDebugMode = value; }
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@@ -1,4 +1,5 @@
|
||||
using Orchard.ContentManagement.Records;
|
||||
using Orchard.Settings;
|
||||
|
||||
namespace Orchard.Core.Settings.Models {
|
||||
public class SiteSettingsPartRecord : ContentPartRecord {
|
||||
@@ -8,5 +9,6 @@ namespace Orchard.Core.Settings.Models {
|
||||
public virtual string PageTitleSeparator { get; set; }
|
||||
public virtual string HomePage { get; set; }
|
||||
public virtual string SiteCulture { get; set; }
|
||||
public virtual ResourceDebugMode ResourceDebugMode { get; set; }
|
||||
}
|
||||
}
|
@@ -2,6 +2,7 @@
|
||||
using System.Web.Mvc;
|
||||
using Orchard.ContentManagement;
|
||||
using Orchard.Core.Settings.Models;
|
||||
using Orchard.Settings;
|
||||
|
||||
namespace Orchard.Core.Settings.ViewModels {
|
||||
public class SiteSettingsPartViewModel {
|
||||
@@ -34,5 +35,10 @@ namespace Orchard.Core.Settings.ViewModels {
|
||||
get { return Site.As<SiteSettingsPart>().Record.SuperUser; }
|
||||
set { Site.As<SiteSettingsPart>().Record.SuperUser = value; }
|
||||
}
|
||||
|
||||
public ResourceDebugMode ResourceDebugMode {
|
||||
get { return Site.As<SiteSettingsPart>().ResourceDebugMode; }
|
||||
set { Site.As<SiteSettingsPart>().ResourceDebugMode = value; }
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@@ -1,4 +1,12 @@
|
||||
@model Orchard.Core.Settings.ViewModels.SiteSettingsPartViewModel
|
||||
@using Orchard.Settings
|
||||
@{
|
||||
var resourceDebugMode = new SelectList(new object[] {
|
||||
new { Id = (int)ResourceDebugMode.FromAppSetting, Text = "Use web.config setting" },
|
||||
new { Id = (int)ResourceDebugMode.Enabled, Text = "Enabled" },
|
||||
new { Id = (int)ResourceDebugMode.Disabled, Text = "Disabled" },
|
||||
}, "Id", "Text", (int)Model.ResourceDebugMode);
|
||||
}
|
||||
<fieldset>
|
||||
<legend>@T("Global Settings")</legend>
|
||||
<div>
|
||||
@@ -22,4 +30,9 @@
|
||||
@Html.EditorFor(x=>x.SuperUser)
|
||||
@Html.ValidationMessage("SuperUser", "*")
|
||||
</div>
|
||||
<div>
|
||||
<label for="SiteDebugMode">@T("Resource Debug Mode")</label>
|
||||
@Html.DropDownList("ResourceDebugMode", resourceDebugMode)
|
||||
<p>@T("Determines whether scripts and stylesheets load in their debuggable or minified form.")</p>
|
||||
</div>
|
||||
</fieldset>
|
||||
|
@@ -1,4 +1,5 @@
|
||||
using System.Collections.Generic;
|
||||
using System.Diagnostics;
|
||||
using System.Globalization;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
@@ -9,6 +10,7 @@ using Orchard.DisplayManagement;
|
||||
using Orchard.DisplayManagement.Descriptors;
|
||||
using Orchard.DisplayManagement.Implementation;
|
||||
using Orchard.Mvc.ViewEngines;
|
||||
using Orchard.Settings;
|
||||
using Orchard.UI;
|
||||
using Orchard.UI.Resources;
|
||||
using Orchard.UI.Zones;
|
||||
@@ -17,6 +19,14 @@ using Orchard.UI.Zones;
|
||||
|
||||
namespace Orchard.Core.Shapes {
|
||||
public class CoreShapes : IShapeTableProvider {
|
||||
private readonly IWorkContextAccessor _workContextAccessor;
|
||||
|
||||
public CoreShapes(IWorkContextAccessor workContextAccessor) {
|
||||
// needed to get CurrentSite.
|
||||
// note that injecting ISiteService here causes a stack overflow in AutoFac!
|
||||
_workContextAccessor = workContextAccessor;
|
||||
}
|
||||
|
||||
public void Discover(ShapeTableBuilder builder) {
|
||||
// the root page shape named 'Layout' is wrapped with 'Document'
|
||||
// and has an automatic zone creating behavior
|
||||
@@ -88,13 +98,15 @@ namespace Orchard.Core.Shapes {
|
||||
|
||||
[Shape]
|
||||
public void HeadScripts(HtmlHelper Html, IResourceManager ResourceManager) {
|
||||
WriteResources(Html, ResourceManager, "script", ResourceLocation.Head, null);
|
||||
WriteResources(Html, _workContextAccessor.GetContext(Html.ViewContext).CurrentSite,
|
||||
ResourceManager, "script", ResourceLocation.Head, null);
|
||||
WriteLiteralScripts(Html, ResourceManager.GetRegisteredHeadScripts());
|
||||
}
|
||||
|
||||
[Shape]
|
||||
public void FootScripts(HtmlHelper Html, IResourceManager ResourceManager) {
|
||||
WriteResources(Html, ResourceManager, "script", null, ResourceLocation.Head);
|
||||
WriteResources(Html, _workContextAccessor.GetContext(Html.ViewContext).CurrentSite,
|
||||
ResourceManager, "script", null, ResourceLocation.Head);
|
||||
WriteLiteralScripts(Html, ResourceManager.GetRegisteredFootScripts());
|
||||
}
|
||||
|
||||
@@ -114,7 +126,8 @@ namespace Orchard.Core.Shapes {
|
||||
|
||||
[Shape]
|
||||
public void StylesheetLinks(HtmlHelper Html, IResourceManager ResourceManager) {
|
||||
WriteResources(Html, ResourceManager, "stylesheet", null, null);
|
||||
WriteResources(Html, _workContextAccessor.GetContext(Html.ViewContext).CurrentSite,
|
||||
ResourceManager, "stylesheet", null, null);
|
||||
}
|
||||
|
||||
private static void WriteLiteralScripts(HtmlHelper html, IEnumerable<string> scripts) {
|
||||
@@ -127,9 +140,22 @@ namespace Orchard.Core.Shapes {
|
||||
}
|
||||
}
|
||||
|
||||
private static void WriteResources(HtmlHelper html, IResourceManager rm, string resourceType, ResourceLocation? includeLocation, ResourceLocation? excludeLocation) {
|
||||
private static void WriteResources(HtmlHelper html, ISite site, IResourceManager rm, string resourceType, ResourceLocation? includeLocation, ResourceLocation? excludeLocation) {
|
||||
bool debugMode;
|
||||
switch(site.ResourceDebugMode) {
|
||||
case ResourceDebugMode.Enabled:
|
||||
debugMode = true;
|
||||
break;
|
||||
case ResourceDebugMode.Disabled:
|
||||
debugMode = false;
|
||||
break;
|
||||
default:
|
||||
Debug.Assert(site.ResourceDebugMode == ResourceDebugMode.FromAppSetting, "Unknown ResourceDebugMode value.");
|
||||
debugMode = html.ViewContext.HttpContext.IsDebuggingEnabled;
|
||||
break;
|
||||
}
|
||||
var defaultSettings = new RequireSettings {
|
||||
DebugMode = html.ViewContext.HttpContext.IsDebuggingEnabled,
|
||||
DebugMode = debugMode,
|
||||
Culture = CultureInfo.CurrentUICulture.Name,
|
||||
};
|
||||
var requiredResources = rm.BuildRequiredResources(resourceType);
|
||||
|
@@ -86,6 +86,7 @@ namespace Orchard.Setup {
|
||||
builder.RegisterType<LayoutAwareViewEngine>().As<ILayoutAwareViewEngine>();
|
||||
builder.RegisterType<ConfiguredEnginesCache>().As<IConfiguredEnginesCache>();
|
||||
builder.RegisterType<PageWorkContext>().As<IWorkContextStateProvider>();
|
||||
builder.RegisterType<SafeModeSiteWorkContextProvider>().As<IWorkContextStateProvider>();
|
||||
|
||||
builder.RegisterType<ShapeTemplateBindingStrategy>().As<IShapeTableProvider>();
|
||||
builder.RegisterType<BasicShapeTemplateHarvester>().As<IShapeTemplateHarvester>();
|
||||
@@ -129,6 +130,13 @@ namespace Orchard.Setup {
|
||||
public void UninstallTheme(string themeName) { }
|
||||
}
|
||||
|
||||
class SafeModeSiteWorkContextProvider : IWorkContextStateProvider {
|
||||
public T Get<T>(string name) {
|
||||
if (name == "CurrentSite")
|
||||
return (T)(ISite) new SafeModeSite();
|
||||
return default(T);
|
||||
}
|
||||
}
|
||||
|
||||
class SafeModeSiteService : ISiteService {
|
||||
public ISite GetSiteSettings() {
|
||||
@@ -171,6 +179,11 @@ namespace Orchard.Setup {
|
||||
get { return ""; }
|
||||
set { throw new NotImplementedException(); }
|
||||
}
|
||||
|
||||
public ResourceDebugMode ResourceDebugMode {
|
||||
get { return ResourceDebugMode.FromAppSetting; }
|
||||
set { throw new NotImplementedException(); }
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@@ -159,6 +159,7 @@
|
||||
<Compile Include="Mvc\ViewEngines\Razor\RazorViewEngine.cs" />
|
||||
<Compile Include="Security\CurrentUserWorkContext.cs" />
|
||||
<Compile Include="Settings\CurrentSiteWorkContext.cs" />
|
||||
<Compile Include="Settings\ResourceDebugMode.cs" />
|
||||
<Compile Include="UI\Zones\PageWorkContext.cs" />
|
||||
<Compile Include="UI\Zones\ZoneHoldingBehavior.cs" />
|
||||
<Compile Include="Mvc\ViewEngines\ThemeAwareness\ConfiguredEnginesCache.cs" />
|
||||
|
@@ -11,5 +11,6 @@ namespace Orchard.Settings {
|
||||
string SuperUser { get; }
|
||||
string HomePage { get; set; }
|
||||
string SiteCulture { get; set; }
|
||||
ResourceDebugMode ResourceDebugMode { get; set; }
|
||||
}
|
||||
}
|
||||
|
7
src/Orchard/Settings/ResourceDebugMode.cs
Normal file
7
src/Orchard/Settings/ResourceDebugMode.cs
Normal file
@@ -0,0 +1,7 @@
|
||||
namespace Orchard.Settings {
|
||||
public enum ResourceDebugMode {
|
||||
FromAppSetting,
|
||||
Enabled,
|
||||
Disabled
|
||||
}
|
||||
}
|
@@ -72,13 +72,13 @@ namespace Orchard.UI.Resources {
|
||||
return (new RequireSettings {
|
||||
Name = Name,
|
||||
Type = Type
|
||||
}).AtLocation(other.Location)
|
||||
.WithBasePath(other.BasePath)
|
||||
.UseCdn(other.CdnMode)
|
||||
.UseDebugMode(other.DebugMode)
|
||||
.UseCulture(other.Culture)
|
||||
.WithMinimumVersion(other.MinimumVersion)
|
||||
.Define(other.InlineDefinition);
|
||||
}).AtLocation(Location).AtLocation(other.Location)
|
||||
.WithBasePath(BasePath).WithBasePath(other.BasePath)
|
||||
.UseCdn(CdnMode).UseCdn(other.CdnMode)
|
||||
.UseDebugMode(DebugMode).UseDebugMode(other.DebugMode)
|
||||
.UseCulture(Culture).UseCulture(other.Culture)
|
||||
.WithMinimumVersion(MinimumVersion).WithMinimumVersion(other.MinimumVersion)
|
||||
.Define(InlineDefinition).Define(other.InlineDefinition);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@@ -6,8 +6,8 @@ x Refactor to take over resource manager name
|
||||
Better interface pattern for defining resources
|
||||
x Script.Load API that is a view engine specific helper and that directs rendering within the using (using Idisposable pattern) to a buffer that can be rendered later.
|
||||
x Script.Require returns RequireSettings and has fluent api to add stuff later.
|
||||
When using the shortcut registration+require Script.Require("../script/foo.js") we resolve the url to an app-relative path and use that as the id.
|
||||
If you want ot define a debug version in that case, just do a proper registration.
|
||||
x (.Include) When using the shortcut registration+require Script.Require("../script/foo.js") we resolve the url to an app-relative path and use that as the id.
|
||||
x If you want ot define a debug version in that case, just do a proper registration.
|
||||
To decide if the app is in debug mode, we look at a setting on the require, then at site setting mode and as a last resort on the compilation mode of the app.
|
||||
x Merge asap, then debug, then refactor.
|
||||
|
||||
@@ -29,7 +29,7 @@ Raw notes from Dave during meeting:
|
||||
// x Script.Require returns RequireSettings and has fluent api?
|
||||
// x (no) Add Script.RequireHead <-- or no due to fluent api
|
||||
// x Rename Localization resource manager
|
||||
// Require w/ app relative url means inline definitin of url only, resolved url is resource name
|
||||
// x (.Include) Require w/ app relative url means inline definitin of url only, resolved url is resource name
|
||||
// Site setting for debug mode true false or from web.config setting
|
||||
// x Moved all copies of jquery and jquery related scripts to a single location
|
||||
// Get minified versions of any external scripts that we don't currently have.
|
||||
|
Reference in New Issue
Block a user