- Changes to ExtensionManager to support features in module.txt.

- Adding the features mapping in module.txt and loading it into extensiondescriptors.
- Tests.

--HG--
branch : dev
This commit is contained in:
Suha Can
2010-04-06 15:46:12 -07:00
parent 7397b7dea3
commit 5a5f83910b
5 changed files with 68 additions and 5 deletions

View File

@@ -64,20 +64,40 @@ namespace Orchard.Tests.Extensions {
}
[Test]
public void ExtensionDescriptorsShouldHaveNameAndDescription() {
public void ExtensionDescriptorsShouldHaveNameAndVersion() {
_folders.Manifests.Add("Sample", @"
name: Sample Extension
description: This is the description
version: 2.x
");
var descriptor = _manager.AvailableExtensions().Single();
Assert.That(descriptor.Name, Is.EqualTo("Sample"));
Assert.That(descriptor.DisplayName, Is.EqualTo("Sample Extension"));
Assert.That(descriptor.Description, Is.EqualTo("This is the description"));
Assert.That(descriptor.Version, Is.EqualTo("2.x"));
}
[Test]
public void ExtensionDescriptorsShouldBeParsedForMinimalModuleTxt() {
_folders.Manifests.Add("SuperWiki", @"
name: SuperWiki
version: 1.0.3
orchardversion: 1
features:
SuperWiki:
Description: My super wiki module for Orchard.
");
var descriptor = _manager.AvailableExtensions().Single();
Assert.That(descriptor.Name, Is.EqualTo("SuperWiki"));
Assert.That(descriptor.Version, Is.EqualTo("1.0.3"));
Assert.That(descriptor.OrchardVersion, Is.EqualTo("1"));
Assert.That(descriptor.Features.Count(), Is.EqualTo(1));
Assert.That(descriptor.Features.First().Name, Is.EqualTo("SuperWiki"));
Assert.That(descriptor.Features.First().ExtensionName, Is.EqualTo("SuperWiki"));
Assert.That(descriptor.Features.First().Description, Is.EqualTo("My super wiki module for Orchard."));
}
}
}

View File

@@ -1,4 +1,6 @@
namespace Orchard.Extensions {
using System.Collections.Generic;
namespace Orchard.Extensions {
public class ExtensionDescriptor {
/// <summary>
/// Virtual path base, "~/Themes", "~/Modules", or "~/Core"
@@ -19,9 +21,12 @@
public string DisplayName { get; set; }
public string Description { get; set; }
public string Version { get; set; }
public string OrchardVersion { get; set; }
public string Author { get; set; }
public string HomePage { get; set; }
public string Tags { get; set; }
public string AntiForgery { get; set; }
public IEnumerable<FeatureDescriptor> Features { get; set; }
}
}

View File

@@ -55,13 +55,43 @@ namespace Orchard.Extensions {
DisplayName = GetValue(fields, "name"),
Description = GetValue(fields, "description"),
Version = GetValue(fields, "version"),
OrchardVersion = GetValue(fields, "orchardversion"),
Author = GetValue(fields, "author"),
HomePage = GetValue(fields, "homepage"),
Tags = GetValue(fields, "tags"),
AntiForgery = GetValue(fields, "antiforgery")
AntiForgery = GetValue(fields, "antiforgery"),
Features = GetFeaturesForExtension(GetMapping(fields, "features"), name),
};
}
private static IEnumerable<FeatureDescriptor> GetFeaturesForExtension(Mapping features, string name) {
List<FeatureDescriptor> featureDescriptors = new List<FeatureDescriptor>();
if (features == null) return featureDescriptors;
foreach (var entity in features.Entities) {
FeatureDescriptor featureDescriptor = new FeatureDescriptor {
ExtensionName = name,
Name = entity.Key.ToString(),
};
Mapping featureMapping = (Mapping) entity.Value;
foreach (var featureEntity in featureMapping.Entities) {
if (String.Equals(featureEntity.Key.ToString(), "description", StringComparison.OrdinalIgnoreCase)) {
featureDescriptor.Description = featureEntity.Value.ToString();
}
}
featureDescriptors.Add(featureDescriptor);
}
return featureDescriptors;
}
private static Mapping GetMapping(
IDictionary<string, DataItem> fields,
string key) {
DataItem value;
return fields.TryGetValue(key, out value) ? (Mapping)value : null;
}
private static string GetValue(
IDictionary<string, DataItem> fields,
string key) {

View File

@@ -0,0 +1,7 @@
namespace Orchard.Extensions {
public class FeatureDescriptor {
public string ExtensionName { get; set; }
public string Name { get; set; }
public string Description { get; set; }
}
}

View File

@@ -161,6 +161,7 @@
<Compile Include="Environment\StandaloneEnvironment.cs" />
<Compile Include="Extensions\AreaFolders.cs" />
<Compile Include="Extensions\ExtensionFolders.cs" />
<Compile Include="Extensions\FeatureDescriptor.cs" />
<Compile Include="Extensions\Loaders\AreaExtensionLoader.cs" />
<Compile Include="Mvc\AntiForgery\ValidateAntiForgeryTokenOrchardAttribute.cs" />
<Compile Include="Mvc\FollowReturnUrl\FollowReturnUrlFilter.cs" />