A recipe handler for theme installation: discover and find theme to install from orchard or custom feed.

Updating recipe file with a gallery theme.
Rename enabled attribute to enable in the recipe section for themes.

--HG--
branch : recipe
This commit is contained in:
Suha Can
2011-02-18 13:48:56 -08:00
parent 2afa3cd9bf
commit 893833aa8e
5 changed files with 57 additions and 11 deletions

View File

@@ -38,7 +38,7 @@
<Migration features="f2,f4"/> <Migration features="f2,f4"/>
<Theme src="source dir" enabled="true" current="true" /> <Theme src="http://" enable="true" current="true" />
<Theme name="theme1" repository="somerepo" replace="true" /> <Theme name="theme1" repository="somerepo" replace="true" />
<CleanUpInactive /> <CleanUpInactive />

View File

@@ -83,6 +83,10 @@
<Project>{DFD137A2-DDB5-4D22-BE0D-FA9AD4C8B059}</Project> <Project>{DFD137A2-DDB5-4D22-BE0D-FA9AD4C8B059}</Project>
<Name>Orchard.Packaging</Name> <Name>Orchard.Packaging</Name>
</ProjectReference> </ProjectReference>
<ProjectReference Include="..\Orchard.Themes\Orchard.Themes.csproj">
<Project>{CDE24A24-01D3-403C-84B9-37722E18DFB7}</Project>
<Name>Orchard.Themes</Name>
</ProjectReference>
</ItemGroup> </ItemGroup>
<ItemGroup /> <ItemGroup />
<Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" /> <Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" />

View File

@@ -37,7 +37,7 @@ namespace Orchard.Recipes.RecipeHandlers {
source = attribute.Value; source = attribute.Value;
} }
else if (String.Equals(attribute.Name.LocalName, "replace", StringComparison.OrdinalIgnoreCase)) { else if (String.Equals(attribute.Name.LocalName, "replace", StringComparison.OrdinalIgnoreCase)) {
replace = attribute.Value == "true"; replace = Boolean.Parse(attribute.Value);
} }
else if (String.Equals(attribute.Name.LocalName, "name", StringComparison.OrdinalIgnoreCase)) { else if (String.Equals(attribute.Name.LocalName, "name", StringComparison.OrdinalIgnoreCase)) {
name = attribute.Value; name = attribute.Value;
@@ -74,6 +74,7 @@ namespace Orchard.Recipes.RecipeHandlers {
} }
// install. // install.
installed = true; installed = true;
break;
} }
} }

View File

@@ -1,12 +1,22 @@
using System; using System;
using Orchard.Localization; using Orchard.Localization;
using Orchard.Logging; using Orchard.Logging;
using Orchard.Packaging.Models;
using Orchard.Packaging.Services;
using Orchard.Recipes.Models; using Orchard.Recipes.Models;
using Orchard.Recipes.Services; using Orchard.Recipes.Services;
using Orchard.Themes.Services;
namespace Orchard.Recipes.RecipeHandlers { namespace Orchard.Recipes.RecipeHandlers {
public class ThemeRecipeHandler : IRecipeHandler { public class ThemeRecipeHandler : IRecipeHandler {
public ThemeRecipeHandler() { private readonly IPackagingSourceManager _packagingSourceManager;
private readonly IThemeService _themeService;
private readonly ISiteThemeService _siteThemeService;
public ThemeRecipeHandler(IPackagingSourceManager packagingSourceManager, IThemeService themeService, ISiteThemeService siteThemeService) {
_packagingSourceManager = packagingSourceManager;
_themeService = themeService;
_siteThemeService = siteThemeService;
Logger = NullLogger.Instance; Logger = NullLogger.Instance;
T = NullLocalizer.Instance; T = NullLocalizer.Instance;
} }
@@ -14,7 +24,7 @@ namespace Orchard.Recipes.RecipeHandlers {
public Localizer T { get; set; } public Localizer T { get; set; }
ILogger Logger { get; set; } ILogger Logger { get; set; }
// <Theme src="http://" enabled="true" current="true /> // <Theme src="http://" enable="true" current="true />
// <Theme name="theme1" repository="somethemerepo" version="1.1" replace="true" /> // <Theme name="theme1" repository="somethemerepo" version="1.1" replace="true" />
// install themes from url or feed. // install themes from url or feed.
public void ExecuteRecipeStep(RecipeContext recipeContext) { public void ExecuteRecipeStep(RecipeContext recipeContext) {
@@ -22,21 +32,21 @@ namespace Orchard.Recipes.RecipeHandlers {
return; return;
} }
bool replace, enabled, current; bool replace, enable, current;
string source, name, version, repository; string source = null, name = null, version = null, repository = null;
foreach (var attribute in recipeContext.RecipeStep.Step.Attributes()) { foreach (var attribute in recipeContext.RecipeStep.Step.Attributes()) {
if (String.Equals(attribute.Name.LocalName, "src", StringComparison.OrdinalIgnoreCase)) { if (String.Equals(attribute.Name.LocalName, "src", StringComparison.OrdinalIgnoreCase)) {
source = attribute.Value; source = attribute.Value;
} }
else if (String.Equals(attribute.Name.LocalName, "replace", StringComparison.OrdinalIgnoreCase)) { else if (String.Equals(attribute.Name.LocalName, "replace", StringComparison.OrdinalIgnoreCase)) {
replace = attribute.Value == "true"; replace = Boolean.Parse(attribute.Value);
} }
else if (String.Equals(attribute.Name.LocalName, "enabled", StringComparison.OrdinalIgnoreCase)) { else if (String.Equals(attribute.Name.LocalName, "enable", StringComparison.OrdinalIgnoreCase)) {
enabled = attribute.Value == "true"; enable = Boolean.Parse(attribute.Value);
} }
else if (String.Equals(attribute.Name.LocalName, "current", StringComparison.OrdinalIgnoreCase)) { else if (String.Equals(attribute.Name.LocalName, "current", StringComparison.OrdinalIgnoreCase)) {
current = attribute.Value == "true"; current = Boolean.Parse(attribute.Value);
} }
else if (String.Equals(attribute.Name.LocalName, "name", StringComparison.OrdinalIgnoreCase)) { else if (String.Equals(attribute.Name.LocalName, "name", StringComparison.OrdinalIgnoreCase)) {
name = attribute.Value; name = attribute.Value;
@@ -52,7 +62,36 @@ namespace Orchard.Recipes.RecipeHandlers {
} }
} }
// download and install theme. if (source != null) {
}
else {
if (name == null) {
throw new InvalidOperationException("Either name or source is required in a Theme declaration in a recipe file.");
}
// download and install theme from the orchard feed or a custom feed if repository is specified.
bool enforceVersion = version != null;
bool installed = false;
PackagingSource packagingSource = null;
if (repository != null) {
enforceVersion = false;
packagingSource = new PackagingSource { FeedTitle = repository, FeedUrl = repository };
}
foreach (var packagingEntry in _packagingSourceManager.GetExtensionList(packagingSource)) {
if (String.Equals(packagingEntry.Title, name, StringComparison.OrdinalIgnoreCase)) {
if (enforceVersion && !String.Equals(packagingEntry.Version, version, StringComparison.OrdinalIgnoreCase)) {
continue;
}
// install.
installed = true;
break;
}
}
if (!installed) {
throw new InvalidOperationException(string.Format("Theme {0} was not found in the specified location.", name));
}
}
recipeContext.Executed = true; recipeContext.Executed = true;
} }

View File

@@ -10,6 +10,8 @@
</Recipe> </Recipe>
<Module name="Bing.Maps" version="0.5.0" replace="false" /> <Module name="Bing.Maps" version="0.5.0" replace="false" />
<Theme name="People Person" version="1.0" enable="true" current="true" />
<Feature enable="Orchard.PublishLater,Orchard.Blogs,Orchard.Comments,Orchard.ContentTypes, <Feature enable="Orchard.PublishLater,Orchard.Blogs,Orchard.Comments,Orchard.ContentTypes,
Orchard.jQuery,Orchard.Lists,Orchard.Media, Orchard.jQuery,Orchard.Lists,Orchard.Media,