Finishing implementation of Settings in recipes.

Moving some settings from setup into recipe files.
Updating recipe files.

--HG--
branch : recipe
This commit is contained in:
Suha Can
2011-02-18 12:03:43 -08:00
parent 3f327f1b3e
commit 148e1b988f
6 changed files with 81 additions and 31 deletions

View File

@@ -2,5 +2,24 @@
namespace Orchard.Comments.Models { namespace Orchard.Comments.Models {
public class CommentSettingsPart : ContentPart<CommentSettingsPartRecord> { public class CommentSettingsPart : ContentPart<CommentSettingsPartRecord> {
public bool ModerateComments {
get { return Record.ModerateComments; }
set { Record.ModerateComments = value; }
}
public bool EnableSpamProtection {
get { return Record.EnableSpamProtection; }
set { Record.EnableSpamProtection = value; }
}
public string AkismetKey {
get { return Record.AkismetKey; }
set { Record.AkismetKey = value; }
}
public string AkismetUrl {
get { return Record.AkismetUrl; }
set { Record.AkismetUrl = value; }
}
} }
} }

View File

@@ -1,19 +1,19 @@
using System; using System;
using System.Xml; using System.Xml;
using Orchard.ContentManagement.MetaData; using System.Xml.Linq;
using Orchard.ContentManagement;
using Orchard.Localization; using Orchard.Localization;
using Orchard.Logging; using Orchard.Logging;
using Orchard.Recipes.Models; using Orchard.Recipes.Models;
using Orchard.Recipes.Services; using Orchard.Recipes.Services;
using Orchard.Settings;
namespace Orchard.Recipes.RecipeHandlers { namespace Orchard.Recipes.RecipeHandlers {
public class SettingsRecipeHandler : IRecipeHandler { public class SettingsRecipeHandler : IRecipeHandler {
private readonly IContentDefinitionManager _contentDefinitionManager; private readonly ISiteService _siteService;
private readonly IContentDefinitionReader _contentDefinitionReader;
public SettingsRecipeHandler(IContentDefinitionManager contentDefinitionManager, IContentDefinitionReader contentDefinitionReader) { public SettingsRecipeHandler(ISiteService siteService) {
_contentDefinitionManager = contentDefinitionManager; _siteService = siteService;
_contentDefinitionReader = contentDefinitionReader;
Logger = NullLogger.Instance; Logger = NullLogger.Instance;
T = NullLocalizer.Instance; T = NullLocalizer.Instance;
} }
@@ -24,7 +24,7 @@ namespace Orchard.Recipes.RecipeHandlers {
/* /*
<Settings> <Settings>
<SiteSettingsPart PageSize="30" /> <SiteSettingsPart PageSize="30" />
<CommentSettingsPart enableSpamProtection="true" /> <CommentSettingsPart ModerateComments="true" />
</Settings> </Settings>
*/ */
// Set site and part settings. // Set site and part settings.
@@ -33,13 +33,42 @@ namespace Orchard.Recipes.RecipeHandlers {
return; return;
} }
var site = _siteService.GetSiteSettings();
foreach (var element in recipeContext.RecipeStep.Step.Elements()) { foreach (var element in recipeContext.RecipeStep.Step.Elements()) {
var partElement = element;
var partName = XmlConvert.DecodeName(element.Name.LocalName); var partName = XmlConvert.DecodeName(element.Name.LocalName);
_contentDefinitionManager.AlterPartDefinition(partName, alteration => _contentDefinitionReader.Merge(partElement, alteration)); foreach (var contentPart in site.ContentItem.Parts) {
if (!String.Equals(contentPart.PartDefinition.Name, partName, StringComparison.OrdinalIgnoreCase)) {
continue;
}
foreach (var attribute in element.Attributes()) {
SetSetting(attribute, contentPart);
}
}
} }
recipeContext.Executed = true; recipeContext.Executed = true;
} }
private static void SetSetting(XAttribute attribute, ContentPart contentPart) {
var attributeName = attribute.Name.LocalName;
var attributeValue = attribute.Value;
var property = contentPart.GetType().GetProperty(attributeName);
if (property == null) {
throw new InvalidOperationException(string.Format("Could set setting {0} for part {1} because it was not found.", attributeName, contentPart.PartDefinition.Name));
}
var propertyType = property.PropertyType;
if (propertyType == typeof(string)) {
property.SetValue(contentPart, attributeValue, null);
}
else if (propertyType == typeof(bool)) {
property.SetValue(contentPart, Boolean.Parse(attributeValue), null);
}
else if (propertyType == typeof(int)) {
property.SetValue(contentPart, Int32.Parse(attributeValue), null);
}
else {
throw new InvalidOperationException(string.Format("Could set setting {0} for part {1} because its type is not supported. Settings should be integer,boolean or string.", attributeName, contentPart.PartDefinition.Name));
}
}
} }
} }

View File

@@ -15,26 +15,27 @@
TinyMce,PackagingServices,Orchard.Packaging,Gallery,TheThemeMachine,Orchard.Experimental" /> TinyMce,PackagingServices,Orchard.Packaging,Gallery,TheThemeMachine,Orchard.Experimental" />
<Metadata> <Metadata>
<Types> <Types>
<Page ContentTypeSettings.Draftable="True" TypeIndexing.Included="true"> <Page ContentTypeSettings.Draftable="True" TypeIndexing.Included="true">
<TagsPart /> <TagsPart />
<LocalizationPart /> <LocalizationPart />
</Page> </Page>
<BlogPost ContentTypeSettings.Draftable="True" TypeIndexing.Included="true"> <BlogPost ContentTypeSettings.Draftable="True" TypeIndexing.Included="true">
<CommentsPart /> <CommentsPart />
<TagsPart /> <TagsPart />
<LocalizationPart /> <LocalizationPart />
</BlogPost> </BlogPost>
</Types> </Types>
<Parts> <Parts>
<!-- Dynamic part --> <BodyPart BodyPartSettings.FlavorDefault="html" />
<Product ContentTypeSettings.Draftable="True" /> <!-- Dynamic part -->
</Parts> <Product ContentTypeSettings.Draftable="True" />
</Parts>
</Metadata> </Metadata>
<Settings> <Settings>
<!-- Part settings --> <SiteSettingsPart PageSize="20" PageTitleSeparator = " - " />
<BodyPart BodyPartSettings.FlavorDefault="html" /> <CommentSettingsPart ModerateComments="true" />
</Settings> </Settings>
<Command> <Command>

View File

@@ -27,14 +27,15 @@
</BlogPost> </BlogPost>
</Types> </Types>
<Parts> <Parts>
<BodyPart BodyPartSettings.FlavorDefault="html" />
<!-- Dynamic part --> <!-- Dynamic part -->
<Product ContentTypeSettings.Draftable="True" /> <Product ContentTypeSettings.Draftable="True" />
</Parts> </Parts>
</Metadata> </Metadata>
<Settings> <Settings>
<!-- Part settings --> <SiteSettingsPart PageSize="20" PageTitleSeparator = " - " />
<BodyPart BodyPartSettings.FlavorDefault="html" /> <CommentSettingsPart ModerateComments="true" />
</Settings> </Settings>
<Command> <Command>

View File

@@ -27,14 +27,15 @@
</BlogPost> </BlogPost>
</Types> </Types>
<Parts> <Parts>
<BodyPart BodyPartSettings.FlavorDefault="html" />
<!-- Dynamic part --> <!-- Dynamic part -->
<Product ContentTypeSettings.Draftable="True" /> <Product ContentTypeSettings.Draftable="True" />
</Parts> </Parts>
</Metadata> </Metadata>
<Settings> <Settings>
<!-- Part settings --> <SiteSettingsPart PageSize="20" PageTitleSeparator = " - " />
<BodyPart BodyPartSettings.FlavorDefault="html" /> <CommentSettingsPart ModerateComments="true" />
</Settings> </Settings>
<Command> <Command>

View File

@@ -213,7 +213,6 @@ namespace Orchard.Setup.Services {
siteSettings.Record.SiteSalt = Guid.NewGuid().ToString("N"); siteSettings.Record.SiteSalt = Guid.NewGuid().ToString("N");
siteSettings.Record.SiteName = context.SiteName; siteSettings.Record.SiteName = context.SiteName;
siteSettings.Record.SuperUser = context.AdminUsername; siteSettings.Record.SuperUser = context.AdminUsername;
siteSettings.Record.PageTitleSeparator = " - ";
siteSettings.Record.SiteCulture = "en-US"; siteSettings.Record.SiteCulture = "en-US";
// set site theme // set site theme