mirror of
https://github.com/OrchardCMS/Orchard.git
synced 2025-10-21 19:34:40 +08:00
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:
@@ -83,6 +83,10 @@
|
||||
<Project>{DFD137A2-DDB5-4D22-BE0D-FA9AD4C8B059}</Project>
|
||||
<Name>Orchard.Packaging</Name>
|
||||
</ProjectReference>
|
||||
<ProjectReference Include="..\Orchard.Themes\Orchard.Themes.csproj">
|
||||
<Project>{CDE24A24-01D3-403C-84B9-37722E18DFB7}</Project>
|
||||
<Name>Orchard.Themes</Name>
|
||||
</ProjectReference>
|
||||
</ItemGroup>
|
||||
<ItemGroup />
|
||||
<Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" />
|
||||
|
@@ -37,7 +37,7 @@ namespace Orchard.Recipes.RecipeHandlers {
|
||||
source = attribute.Value;
|
||||
}
|
||||
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)) {
|
||||
name = attribute.Value;
|
||||
@@ -74,6 +74,7 @@ namespace Orchard.Recipes.RecipeHandlers {
|
||||
}
|
||||
// install.
|
||||
installed = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
|
@@ -1,12 +1,22 @@
|
||||
using System;
|
||||
using Orchard.Localization;
|
||||
using Orchard.Logging;
|
||||
using Orchard.Packaging.Models;
|
||||
using Orchard.Packaging.Services;
|
||||
using Orchard.Recipes.Models;
|
||||
using Orchard.Recipes.Services;
|
||||
using Orchard.Themes.Services;
|
||||
|
||||
namespace Orchard.Recipes.RecipeHandlers {
|
||||
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;
|
||||
T = NullLocalizer.Instance;
|
||||
}
|
||||
@@ -14,7 +24,7 @@ namespace Orchard.Recipes.RecipeHandlers {
|
||||
public Localizer T { 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" />
|
||||
// install themes from url or feed.
|
||||
public void ExecuteRecipeStep(RecipeContext recipeContext) {
|
||||
@@ -22,21 +32,21 @@ namespace Orchard.Recipes.RecipeHandlers {
|
||||
return;
|
||||
}
|
||||
|
||||
bool replace, enabled, current;
|
||||
string source, name, version, repository;
|
||||
bool replace, enable, current;
|
||||
string source = null, name = null, version = null, repository = null;
|
||||
|
||||
foreach (var attribute in recipeContext.RecipeStep.Step.Attributes()) {
|
||||
if (String.Equals(attribute.Name.LocalName, "src", StringComparison.OrdinalIgnoreCase)) {
|
||||
source = attribute.Value;
|
||||
}
|
||||
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)) {
|
||||
enabled = attribute.Value == "true";
|
||||
else if (String.Equals(attribute.Name.LocalName, "enable", StringComparison.OrdinalIgnoreCase)) {
|
||||
enable = Boolean.Parse(attribute.Value);
|
||||
}
|
||||
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)) {
|
||||
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;
|
||||
}
|
||||
|
@@ -10,6 +10,8 @@
|
||||
</Recipe>
|
||||
|
||||
<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,
|
||||
Orchard.jQuery,Orchard.Lists,Orchard.Media,
|
||||
|
Reference in New Issue
Block a user