Added a SiteSetting for whether to load resources in debug mode (use app setting, enabled, disabled)

--HG--
branch : dev
This commit is contained in:
Dave Reed
2010-09-22 14:39:01 -07:00
parent f673579406
commit e9f780a408
12 changed files with 97 additions and 16 deletions

View File

@@ -1,4 +1,5 @@
using Orchard.Data.Migration; using System.Data;
using Orchard.Data.Migration;
namespace Orchard.Core.Settings.DataMigrations { namespace Orchard.Core.Settings.DataMigrations {
public class SettingsDataMigration : DataMigrationImpl { public class SettingsDataMigration : DataMigrationImpl {
@@ -93,5 +94,12 @@ namespace Orchard.Core.Settings.DataMigrations {
return 1; return 1;
} }
public int UpdateFrom1() {
SchemaBuilder.AlterTable("SiteSettingsPartRecord", table => table
.AddColumn("ResourceDebugMode", DbType.String, column => column.WithDefault("FromAppSetting"))
);
return 2;
}
} }
} }

View File

@@ -27,5 +27,9 @@ namespace Orchard.Core.Settings.Models {
get { return Record.SiteCulture; } get { return Record.SiteCulture; }
set { Record.SiteCulture = value; } set { Record.SiteCulture = value; }
} }
public ResourceDebugMode ResourceDebugMode {
get { return Record.ResourceDebugMode; }
set { Record.ResourceDebugMode = value; }
}
} }
} }

View File

@@ -1,4 +1,5 @@
using Orchard.ContentManagement.Records; using Orchard.ContentManagement.Records;
using Orchard.Settings;
namespace Orchard.Core.Settings.Models { namespace Orchard.Core.Settings.Models {
public class SiteSettingsPartRecord : ContentPartRecord { public class SiteSettingsPartRecord : ContentPartRecord {
@@ -8,5 +9,6 @@ namespace Orchard.Core.Settings.Models {
public virtual string PageTitleSeparator { get; set; } public virtual string PageTitleSeparator { get; set; }
public virtual string HomePage { get; set; } public virtual string HomePage { get; set; }
public virtual string SiteCulture { get; set; } public virtual string SiteCulture { get; set; }
public virtual ResourceDebugMode ResourceDebugMode { get; set; }
} }
} }

View File

@@ -2,6 +2,7 @@
using System.Web.Mvc; using System.Web.Mvc;
using Orchard.ContentManagement; using Orchard.ContentManagement;
using Orchard.Core.Settings.Models; using Orchard.Core.Settings.Models;
using Orchard.Settings;
namespace Orchard.Core.Settings.ViewModels { namespace Orchard.Core.Settings.ViewModels {
public class SiteSettingsPartViewModel { public class SiteSettingsPartViewModel {
@@ -34,5 +35,10 @@ namespace Orchard.Core.Settings.ViewModels {
get { return Site.As<SiteSettingsPart>().Record.SuperUser; } get { return Site.As<SiteSettingsPart>().Record.SuperUser; }
set { Site.As<SiteSettingsPart>().Record.SuperUser = value; } set { Site.As<SiteSettingsPart>().Record.SuperUser = value; }
} }
public ResourceDebugMode ResourceDebugMode {
get { return Site.As<SiteSettingsPart>().ResourceDebugMode; }
set { Site.As<SiteSettingsPart>().ResourceDebugMode = value; }
}
} }
} }

View File

@@ -1,4 +1,12 @@
@model Orchard.Core.Settings.ViewModels.SiteSettingsPartViewModel @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> <fieldset>
<legend>@T("Global Settings")</legend> <legend>@T("Global Settings")</legend>
<div> <div>
@@ -22,4 +30,9 @@
@Html.EditorFor(x=>x.SuperUser) @Html.EditorFor(x=>x.SuperUser)
@Html.ValidationMessage("SuperUser", "*") @Html.ValidationMessage("SuperUser", "*")
</div> </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> </fieldset>

View File

@@ -1,4 +1,5 @@
using System.Collections.Generic; using System.Collections.Generic;
using System.Diagnostics;
using System.Globalization; using System.Globalization;
using System.IO; using System.IO;
using System.Linq; using System.Linq;
@@ -9,6 +10,7 @@ using Orchard.DisplayManagement;
using Orchard.DisplayManagement.Descriptors; using Orchard.DisplayManagement.Descriptors;
using Orchard.DisplayManagement.Implementation; using Orchard.DisplayManagement.Implementation;
using Orchard.Mvc.ViewEngines; using Orchard.Mvc.ViewEngines;
using Orchard.Settings;
using Orchard.UI; using Orchard.UI;
using Orchard.UI.Resources; using Orchard.UI.Resources;
using Orchard.UI.Zones; using Orchard.UI.Zones;
@@ -17,6 +19,14 @@ using Orchard.UI.Zones;
namespace Orchard.Core.Shapes { namespace Orchard.Core.Shapes {
public class CoreShapes : IShapeTableProvider { 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) { public void Discover(ShapeTableBuilder builder) {
// the root page shape named 'Layout' is wrapped with 'Document' // the root page shape named 'Layout' is wrapped with 'Document'
// and has an automatic zone creating behavior // and has an automatic zone creating behavior
@@ -88,13 +98,15 @@ namespace Orchard.Core.Shapes {
[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, _workContextAccessor.GetContext(Html.ViewContext).CurrentSite,
ResourceManager, "script", ResourceLocation.Head, null);
WriteLiteralScripts(Html, ResourceManager.GetRegisteredHeadScripts()); WriteLiteralScripts(Html, ResourceManager.GetRegisteredHeadScripts());
} }
[Shape] [Shape]
public void FootScripts(HtmlHelper Html, IResourceManager ResourceManager) { 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()); WriteLiteralScripts(Html, ResourceManager.GetRegisteredFootScripts());
} }
@@ -114,7 +126,8 @@ namespace Orchard.Core.Shapes {
[Shape] [Shape]
public void StylesheetLinks(HtmlHelper Html, IResourceManager ResourceManager) { 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) { 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 { var defaultSettings = new RequireSettings {
DebugMode = html.ViewContext.HttpContext.IsDebuggingEnabled, DebugMode = debugMode,
Culture = CultureInfo.CurrentUICulture.Name, Culture = CultureInfo.CurrentUICulture.Name,
}; };
var requiredResources = rm.BuildRequiredResources(resourceType); var requiredResources = rm.BuildRequiredResources(resourceType);

View File

@@ -86,6 +86,7 @@ namespace Orchard.Setup {
builder.RegisterType<LayoutAwareViewEngine>().As<ILayoutAwareViewEngine>(); builder.RegisterType<LayoutAwareViewEngine>().As<ILayoutAwareViewEngine>();
builder.RegisterType<ConfiguredEnginesCache>().As<IConfiguredEnginesCache>(); builder.RegisterType<ConfiguredEnginesCache>().As<IConfiguredEnginesCache>();
builder.RegisterType<PageWorkContext>().As<IWorkContextStateProvider>(); builder.RegisterType<PageWorkContext>().As<IWorkContextStateProvider>();
builder.RegisterType<SafeModeSiteWorkContextProvider>().As<IWorkContextStateProvider>();
builder.RegisterType<ShapeTemplateBindingStrategy>().As<IShapeTableProvider>(); builder.RegisterType<ShapeTemplateBindingStrategy>().As<IShapeTableProvider>();
builder.RegisterType<BasicShapeTemplateHarvester>().As<IShapeTemplateHarvester>(); builder.RegisterType<BasicShapeTemplateHarvester>().As<IShapeTemplateHarvester>();
@@ -129,6 +130,13 @@ namespace Orchard.Setup {
public void UninstallTheme(string themeName) { } 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 { class SafeModeSiteService : ISiteService {
public ISite GetSiteSettings() { public ISite GetSiteSettings() {
@@ -171,6 +179,11 @@ namespace Orchard.Setup {
get { return ""; } get { return ""; }
set { throw new NotImplementedException(); } set { throw new NotImplementedException(); }
} }
public ResourceDebugMode ResourceDebugMode {
get { return ResourceDebugMode.FromAppSetting; }
set { throw new NotImplementedException(); }
}
} }
} }
} }

View File

@@ -159,6 +159,7 @@
<Compile Include="Mvc\ViewEngines\Razor\RazorViewEngine.cs" /> <Compile Include="Mvc\ViewEngines\Razor\RazorViewEngine.cs" />
<Compile Include="Security\CurrentUserWorkContext.cs" /> <Compile Include="Security\CurrentUserWorkContext.cs" />
<Compile Include="Settings\CurrentSiteWorkContext.cs" /> <Compile Include="Settings\CurrentSiteWorkContext.cs" />
<Compile Include="Settings\ResourceDebugMode.cs" />
<Compile Include="UI\Zones\PageWorkContext.cs" /> <Compile Include="UI\Zones\PageWorkContext.cs" />
<Compile Include="UI\Zones\ZoneHoldingBehavior.cs" /> <Compile Include="UI\Zones\ZoneHoldingBehavior.cs" />
<Compile Include="Mvc\ViewEngines\ThemeAwareness\ConfiguredEnginesCache.cs" /> <Compile Include="Mvc\ViewEngines\ThemeAwareness\ConfiguredEnginesCache.cs" />

View File

@@ -11,5 +11,6 @@ namespace Orchard.Settings {
string SuperUser { get; } string SuperUser { get; }
string HomePage { get; set; } string HomePage { get; set; }
string SiteCulture { get; set; } string SiteCulture { get; set; }
ResourceDebugMode ResourceDebugMode { get; set; }
} }
} }

View File

@@ -0,0 +1,7 @@
namespace Orchard.Settings {
public enum ResourceDebugMode {
FromAppSetting,
Enabled,
Disabled
}
}

View File

@@ -72,13 +72,13 @@ namespace Orchard.UI.Resources {
return (new RequireSettings { return (new RequireSettings {
Name = Name, Name = Name,
Type = Type Type = Type
}).AtLocation(other.Location) }).AtLocation(Location).AtLocation(other.Location)
.WithBasePath(other.BasePath) .WithBasePath(BasePath).WithBasePath(other.BasePath)
.UseCdn(other.CdnMode) .UseCdn(CdnMode).UseCdn(other.CdnMode)
.UseDebugMode(other.DebugMode) .UseDebugMode(DebugMode).UseDebugMode(other.DebugMode)
.UseCulture(other.Culture) .UseCulture(Culture).UseCulture(other.Culture)
.WithMinimumVersion(other.MinimumVersion) .WithMinimumVersion(MinimumVersion).WithMinimumVersion(other.MinimumVersion)
.Define(other.InlineDefinition); .Define(InlineDefinition).Define(other.InlineDefinition);
} }
} }
} }

View File

@@ -6,8 +6,8 @@ x Refactor to take over resource manager name
Better interface pattern for defining resources 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.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. 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. 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.
If you want ot define a debug version in that case, just do a proper registration. 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. 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. 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 Script.Require returns RequireSettings and has fluent api?
// x (no) Add Script.RequireHead <-- or no due to fluent api // x (no) Add Script.RequireHead <-- or no due to fluent api
// x Rename Localization resource manager // 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 // 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 // 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. // Get minified versions of any external scripts that we don't currently have.