- Themes: Theme discovery and related infrastructure work. Theme content item and metadata (Theme.txt). Some initial Theme Admin and a couple skeleton themes.

- Extensions: Theme and Package extensions are now automatically discovered, their metadata parsed and their types loaded by the ExtensionManager. The ExtensionDescriptor now contains an ExtensionType property which will help distinguish extension types.

--HG--
extra : convert_revision : svn%3A5ff7c347-ad56-4c35-b696-ccb81de16e03/trunk%4043750
This commit is contained in:
suhacan
2009-12-10 22:21:57 +00:00
parent 8188b70d01
commit a728a5ee92
23 changed files with 261 additions and 65 deletions

View File

@@ -49,7 +49,7 @@ namespace Orchard.Tests.Extensions {
[Test]
public void NamesFromFoldersWithPackageTxtShouldBeListed() {
var folders = new ExtensionFolders(new[] { _tempFolderName });
var folders = new PackageFolders(new[] { _tempFolderName });
var names = folders.ListNames();
Assert.That(names.Count(), Is.EqualTo(2));
Assert.That(names, Has.Some.EqualTo("Sample1"));
@@ -58,7 +58,7 @@ namespace Orchard.Tests.Extensions {
[Test]
public void PackageTxtShouldBeParsedAndReturnedAsYamlDocument() {
var folders = new ExtensionFolders(new[] { _tempFolderName });
var folders = new PackageFolders(new[] { _tempFolderName });
var sample1 = folders.ParseManifest("Sample1");
var mapping = (Mapping)sample1.YamlDocument.Root;
var entities = mapping.Entities

View File

@@ -85,8 +85,10 @@
<Compile Include="Settings\ViewModels\SettingsIndexViewModel.cs" />
<Compile Include="Themes\AdminMenu.cs" />
<Compile Include="Themes\Controllers\AdminController.cs" />
<Compile Include="Themes\Models\Theme.cs" />
<Compile Include="Themes\Models\ThemeSiteSettings.cs" />
<Compile Include="Themes\Models\ThemeSiteSettingsHandler.cs" />
<Compile Include="Themes\Records\ThemeRecord.cs" />
<Compile Include="Themes\Records\ThemeSiteSettingsRecord.cs" />
<Compile Include="Themes\Services\ThemeService.cs" />
<Compile Include="Themes\ViewModels\ThemesIndexViewModel.cs" />

View File

@@ -7,8 +7,7 @@ namespace Orchard.Core.Themes {
public void GetNavigation(NavigationBuilder builder) {
builder.Add("Themes", "11",
menu => menu
.Add("Manage Themes", "2.0", item => item.Action("Index", "Admin", new { area = "Themes" }))
.Add("Upload a Theme", "2.1", item => item.Action("Index", "Admin",new { area = "Themes" })));
.Add("Manage Themes", "2.0", item => item.Action("Index", "Admin", new { area = "Themes" })));
}
}
}

View File

@@ -1,4 +1,5 @@
using System.Web.Mvc;
using System;
using System.Web.Mvc;
using Orchard.Core.Themes.ViewModels;
using Orchard.Localization;
using Orchard.Themes;
@@ -19,7 +20,16 @@ namespace Orchard.Core.Themes.Controllers {
public Localizer T { get; set; }
public ActionResult Index() {
return View(new ThemesIndexViewModel());
try {
var themes = _themeService.GetInstalledThemes();
var currentTheme = _themeService.GetCurrentTheme();
var model = new ThemesIndexViewModel { CurrentTheme = currentTheme, Themes = themes };
return View(model);
}
catch (Exception exception) {
_notifier.Error(T("Listing themes failed: " + exception.Message));
return View(new ThemesIndexViewModel());
}
}
}
}

View File

@@ -0,0 +1,43 @@
using Orchard.Core.Themes.Records;
using Orchard.Models;
using Orchard.Themes;
namespace Orchard.Core.Themes.Models {
public class Theme : ContentPart<ThemeRecord>, ITheme {
public static readonly ContentType ContentType = new ContentType { Name = "theme", DisplayName = "Themes" };
#region Implementation of ITheme
public string ThemeName {
get;
set;
}
public string DisplayName {
get;
set;
}
public string Description {
get;
set;
}
public string Version {
get;
set;
}
public string Author {
get;
set;
}
public string HomePage {
get;
set;
}
#endregion
}
}

View File

@@ -0,0 +1,12 @@
using Orchard.Models.Records;
namespace Orchard.Core.Themes.Records {
public class ThemeRecord : ContentPartRecord {
public virtual string ThemeName { get; set; }
public virtual string DisplayName { get; set; }
public virtual string Description { get; set; }
public virtual string Version { get; set; }
public virtual string Author { get; set; }
public virtual string HomePage { get; set; }
}
}

View File

@@ -1,5 +1,6 @@
using System;
using System.Collections.Generic;
using Orchard.Extensions;
using Orchard.Logging;
using Orchard.Models;
using Orchard.Settings;
@@ -8,7 +9,10 @@ using Orchard.Core.Themes.Models;
namespace Orchard.Core.Themes.Services {
public class ThemeService : IThemeService {
public ThemeService() {
private readonly IExtensionManager _extensionManager;
public ThemeService(IExtensionManager extensionManager) {
_extensionManager = extensionManager;
Logger = NullLogger.Instance;
}
@@ -28,11 +32,37 @@ namespace Orchard.Core.Themes.Services {
}
public ITheme GetThemeByName(string name) {
throw new NotImplementedException();
foreach (var descriptor in _extensionManager.AvailableExtensions()) {
if (String.Equals(descriptor.Name, name, StringComparison.OrdinalIgnoreCase)) {
return new Theme {
Author = descriptor.Author ?? String.Empty,
Description = descriptor.Description ?? String.Empty,
DisplayName = descriptor.DisplayName ?? String.Empty,
HomePage = descriptor.HomePage ?? String.Empty,
ThemeName = descriptor.Name,
Version = descriptor.Version ?? String.Empty
};
}
}
return null;
}
public IEnumerable<ITheme> GetInstalledThemes() {
throw new NotImplementedException();
List<ITheme> themes = new List<ITheme>();
foreach (var descriptor in _extensionManager.AvailableExtensions()) {
if (String.Equals(descriptor.ExtensionType, "Theme", StringComparison.OrdinalIgnoreCase)) {
Theme theme = new Theme {
Author = descriptor.Author ?? String.Empty,
Description = descriptor.Description ?? String.Empty,
DisplayName = descriptor.DisplayName ?? String.Empty,
HomePage = descriptor.HomePage ?? String.Empty,
ThemeName = descriptor.Name,
Version = descriptor.Version ?? String.Empty
};
themes.Add(theme);
}
}
return themes;
}
#endregion

View File

@@ -1,6 +1,10 @@
using Orchard.Mvc.ViewModels;
using System.Collections.Generic;
using Orchard.Mvc.ViewModels;
using Orchard.Themes;
namespace Orchard.Core.Themes.ViewModels {
public class ThemesIndexViewModel : AdminViewModel {
public ITheme CurrentTheme { get; set; }
public IEnumerable<ITheme> Themes { get; set; }
}
}

View File

@@ -7,6 +7,14 @@
Themes</h2>
</div>
<div class="yui-u">
List of Orchard Themes
<% foreach (var theme in Model.Themes) { %>
<p>Name: <%= theme.ThemeName %></p>
<p>DisplayName: <%= theme.DisplayName %></p>
<p>Description: <%= theme.Description %></p>
<p>Author: <%= theme.Author %></p>
<p>Version: <%= theme.Version %></p>
<p>HomePage: <%= theme.HomePage %></p>
<% } %>
Current Theme: <%= Model.CurrentTheme != null ? Model.CurrentTheme.ThemeName : "None" %>
</div>
<% Html.Include("AdminFoot"); %>

View File

@@ -175,6 +175,10 @@
<Content Include="Content\Images\title_background.gif" />
<Content Include="Content\Site2.css" />
<Content Include="Content\Site3.css" />
<Content Include="Themes\BlueSky\Theme.gif" />
<Content Include="Themes\BlueSky\Theme.txt" />
<Content Include="Themes\PinkPretty\Theme.gif" />
<Content Include="Themes\PinkPretty\Theme.txt" />
<Content Include="Views\Shared\AdminHead.aspx" />
<Content Include="Views\Shared\AdminFoot.aspx" />
<Content Include="Views\Shared\Messages.ascx" />
@@ -187,7 +191,6 @@
<Folder Include="App_Data\" />
<Folder Include="Media\Images\" />
<Folder Include="Media\Videos\" />
<Folder Include="Themes\" />
</ItemGroup>
<Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" />
<Import Project="$(MSBuildExtensionsPath)\Microsoft\VisualStudio\v9.0\WebApplications\Microsoft.WebApplication.targets" />

Binary file not shown.

After

Width:  |  Height:  |  Size: 39 KiB

View File

@@ -0,0 +1,6 @@
name: Blue Sky
author: Jon Wall
description: This theme uses the best of colors Blue.
version: 1.0
tags: blue
homepage: http://www.orchardproject.net

Binary file not shown.

After

Width:  |  Height:  |  Size: 33 KiB

View File

@@ -0,0 +1,6 @@
name: Pretty in Pink
author: Bertrand Le Roy
description: This theme is full of butterflies, hearts and unicorns.
version: 1.0
tags: pink,butterfly,heart,unicorn
homepage: http://weblogs.asp.net/bleroy

View File

@@ -33,13 +33,12 @@ namespace Orchard.Environment {
builder.Register<PrecompiledExtensionLoader>().As<IExtensionLoader>().SingletonScoped();
builder.Register<DynamicExtensionLoader>().As<IExtensionLoader>().SingletonScoped();
//builder.Register((ctx, p) => new PackageFolders(MapPaths(p.Named<IEnumerable<string>>("paths"))))
// .As<IPackageFolders>()
// .WithExtendedProperty("paths", new[] { "~/Packages" })
// .SingletonScoped();
builder.Register<ExtensionFolders>().As<IExtensionFolders>()
builder.Register<PackageFolders>().As<IExtensionFolders>()
.WithArguments(new NamedParameter("paths", new[] { "~/Core", "~/Packages" }))
.SingletonScoped();
builder.Register<ThemeFolders>().As<IExtensionFolders>()
.WithArguments(new NamedParameter("paths", new[] { "~/Themes" }))
.SingletonScoped();
registrations(builder);

View File

@@ -2,9 +2,13 @@
public class ExtensionDescriptor {
public string Location { get; set; }
public string Name { get; set; }
public string ExtensionType { get; set; }
// extension metadata
public string DisplayName { get; set; }
public string Description { get; set; }
public string Version { get; set; }
public string Author { get; set; }
public string HomePage { get; set; }
}
}

View File

@@ -1,4 +1,5 @@
using System.Collections.Generic;
using System;
using System.Collections.Generic;
using System.Linq;
using Orchard.Extensions.Loaders;
using Yaml.Grammar;
@@ -10,34 +11,44 @@ namespace Orchard.Extensions {
}
public class ExtensionManager : IExtensionManager {
private readonly IExtensionFolders _folders;
private readonly IEnumerable<IExtensionFolders> _folders;
private readonly IEnumerable<IExtensionLoader> _loaders;
private IEnumerable<ExtensionEntry> _activeExtensions;
public ExtensionManager(IExtensionFolders folders, IEnumerable<IExtensionLoader> loaders) {
public ExtensionManager(IEnumerable<IExtensionFolders> folders, IEnumerable<IExtensionLoader> loaders) {
_folders = folders;
_loaders = loaders.OrderBy(x => x.Order);
}
public IEnumerable<ExtensionDescriptor> AvailableExtensions() {
var names = _folders.ListNames();
foreach (var name in names) {
var parseResult = _folders.ParseManifest(name);
var mapping = (Mapping)parseResult.YamlDocument.Root;
var fields = mapping.Entities
.Where(x => x.Key is Scalar)
.ToDictionary(x => ((Scalar)x.Key).Text, x => x.Value);
yield return new ExtensionDescriptor {
Location = parseResult.Location,
Name = name,
DisplayName = GetValue(fields, "name"),
Description = GetValue(fields, "description"),
Version = GetValue(fields, "version")
};
List<ExtensionDescriptor> availableExtensions = new List<ExtensionDescriptor>();
foreach (var folder in _folders) {
foreach (var name in folder.ListNames()) {
availableExtensions.Add(GetDescriptorForExtension(name, folder));
}
}
return availableExtensions;
}
private static ExtensionDescriptor GetDescriptorForExtension(string name, IExtensionFolders folder) {
string extensionType = folder is ThemeFolders ? "Theme" : "Package";
var parseResult = folder.ParseManifest(name);
var mapping = (Mapping)parseResult.YamlDocument.Root;
var fields = mapping.Entities
.Where(x => x.Key is Scalar)
.ToDictionary(x => ((Scalar)x.Key).Text, x => x.Value);
return new ExtensionDescriptor {
Location = parseResult.Location,
Name = name,
ExtensionType = extensionType,
DisplayName = GetValue(fields, "name"),
Description = GetValue(fields, "description"),
Version = GetValue(fields, "version"),
Author = GetValue(fields, "author"),
HomePage = GetValue(fields, "homepage")
};
}
private static string GetValue(
@@ -56,9 +67,12 @@ namespace Orchard.Extensions {
}
private IEnumerable<ExtensionEntry> BuildActiveExtensions() {
//TODO: this component needs access to some "current settings" to know which are active
foreach (var descriptor in AvailableExtensions()) {
//TODO: this component needs access to some "current settings" to know which are active
yield return BuildEntry(descriptor);
// Extensions that are Themes don't have buildable components.
if (String.Equals(descriptor.ExtensionType, "Package", StringComparison.OrdinalIgnoreCase)) {
yield return BuildEntry(descriptor);
}
}
}

View File

@@ -0,0 +1,12 @@
using System.Web.Hosting;
namespace Orchard.Extensions.Helpers {
public static class PathHelpers {
public static string GetPhysicalPath(string path) {
if (path.StartsWith("~") && HostingEnvironment.IsHosted) {
return HostingEnvironment.MapPath(path);
}
return path;
}
}
}

View File

@@ -0,0 +1,15 @@
using System.Collections.Generic;
using Yaml.Grammar;
namespace Orchard.Extensions {
public interface IExtensionFolders {
IEnumerable<string> ListNames();
ParseResult ParseManifest(string name);
}
public class ParseResult {
public string Location { get; set; }
public string Name { get; set; }
public YamlDocument YamlDocument { get; set; }
}
}

View File

@@ -1,40 +1,20 @@
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Web.Hosting;
using Orchard.Extensions.Helpers;
using Yaml.Grammar;
namespace Orchard.Extensions {
public interface IExtensionFolders {
IEnumerable<string> ListNames();
ParseResult ParseManifest(string name);
}
public class ParseResult {
public string Location { get; set; }
public string Name { get; set; }
public YamlDocument YamlDocument { get; set; }
}
public class ExtensionFolders : IExtensionFolders {
public class PackageFolders : IExtensionFolders {
private readonly IEnumerable<string> _paths;
public ExtensionFolders(IEnumerable<string> paths) {
public PackageFolders(IEnumerable<string> paths) {
_paths = paths;
}
static string GetPhysicalPath(string path) {
if (path.StartsWith("~") && HostingEnvironment.IsHosted) {
return HostingEnvironment.MapPath(path);
}
return path;
}
public IEnumerable<string> ListNames() {
foreach (var path in _paths) {
foreach (var directoryName in Directory.GetDirectories(GetPhysicalPath(path))) {
foreach (var directoryName in Directory.GetDirectories(PathHelpers.GetPhysicalPath(path))) {
if (File.Exists(Path.Combine(directoryName, "Package.txt")))
yield return Path.GetFileName(directoryName);
}
@@ -43,7 +23,7 @@ namespace Orchard.Extensions {
public ParseResult ParseManifest(string name) {
foreach (var path in _paths) {
var extensionDirectoryPath = Path.Combine(GetPhysicalPath(path), name);
var extensionDirectoryPath = Path.Combine(PathHelpers.GetPhysicalPath(path), name);
var extensionManifestPath = Path.Combine(extensionDirectoryPath, "Package.txt");
if (!File.Exists(extensionManifestPath)) {
continue;

View File

@@ -0,0 +1,41 @@
using System.Collections.Generic;
using System.IO;
using System.Linq;
using Orchard.Extensions.Helpers;
using Yaml.Grammar;
namespace Orchard.Extensions {
public class ThemeFolders : IExtensionFolders {
private readonly IEnumerable<string> _paths;
public ThemeFolders(IEnumerable<string> paths) {
_paths = paths;
}
public IEnumerable<string> ListNames() {
foreach (var path in _paths) {
foreach (var directoryName in Directory.GetDirectories(PathHelpers.GetPhysicalPath(path))) {
if (File.Exists(Path.Combine(directoryName, "Theme.txt")))
yield return Path.GetFileName(directoryName);
}
}
}
public ParseResult ParseManifest(string name) {
foreach (var path in _paths) {
var extensionDirectoryPath = Path.Combine(PathHelpers.GetPhysicalPath(path), name);
var extensionManifestPath = Path.Combine(extensionDirectoryPath, "Theme.txt");
if (!File.Exists(extensionManifestPath)) {
continue;
}
var yamlStream = YamlParser.Load(extensionManifestPath);
return new ParseResult {
Location = path,
Name = name,
YamlDocument = yamlStream.Documents.Single()
};
}
return null;
}
}
}

View File

@@ -121,13 +121,16 @@
<Compile Include="Environment\IOrchardShellEvents.cs" />
<Compile Include="Extensions\ExtensionDescriptor.cs" />
<Compile Include="Extensions\ExtensionEntry.cs" />
<Compile Include="Extensions\ExtensionFolders.cs" />
<Compile Include="Extensions\Helpers\PathHelpers.cs" />
<Compile Include="Extensions\PackageFolders.cs" />
<Compile Include="Extensions\ExtensionManager.cs" />
<Compile Include="Extensions\IExtensionFolders.cs" />
<Compile Include="Extensions\Loaders\CoreExtensionLoader.cs" />
<Compile Include="Extensions\Loaders\DynamicExtensionLoader.cs" />
<Compile Include="Extensions\Loaders\IExtensionLoader.cs" />
<Compile Include="Extensions\Loaders\PrecompiledExtensionLoader.cs" />
<Compile Include="Extensions\Loaders\ReferencedExtensionLoader.cs" />
<Compile Include="Extensions\ThemeFolders.cs" />
<Compile Include="IEvents.cs" />
<Compile Include="Localization\IText.cs" />
<Compile Include="Localization\LocalizationModule.cs" />

View File

@@ -6,5 +6,10 @@ namespace Orchard.Themes {
/// </summary>
public interface ITheme : IContent {
string ThemeName { get; set; }
string DisplayName { get; set; }
string Description { get; set; }
string Version { get; set; }
string Author { get; set; }
string HomePage { get; set; }
}
}