mirror of
https://github.com/OrchardCMS/Orchard.git
synced 2025-10-15 19:54:57 +08:00
Ability to create and install packages of simple themes.
--HG-- branch : dev
This commit is contained in:
@@ -14,6 +14,10 @@ namespace Orchard.Tests.Stubs {
|
||||
return Directory.GetDirectories(path);
|
||||
}
|
||||
|
||||
public IEnumerable<string> ListFiles(string path, bool recursive) {
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
public bool FileExists(string virtualPath) {
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
@@ -5,6 +5,8 @@ using System.IO.Packaging;
|
||||
using System.Linq;
|
||||
using System.Net.Mime;
|
||||
using System.Reflection;
|
||||
using System.Web;
|
||||
using System.Web.Hosting;
|
||||
using System.Xml.Linq;
|
||||
using Orchard.Environment.Extensions;
|
||||
using Orchard.Environment.Extensions.Models;
|
||||
@@ -16,6 +18,19 @@ namespace Orchard.Packaging.Services {
|
||||
private readonly IExtensionManager _extensionManager;
|
||||
private readonly IWebSiteFolder _webSiteFolder;
|
||||
|
||||
private static readonly string[] _ignoredThemeExtensions = new[] {
|
||||
"obj", "pdb", "exclude"
|
||||
};
|
||||
private static readonly string[] _ignoredThemePaths = new[] {
|
||||
"/obj/"
|
||||
};
|
||||
|
||||
private static bool IgnoreFile(string filePath) {
|
||||
return String.IsNullOrEmpty(filePath) ||
|
||||
_ignoredThemePaths.Any(filePath.Contains) ||
|
||||
_ignoredThemeExtensions.Contains(Path.GetExtension(filePath) ?? "");
|
||||
}
|
||||
|
||||
public PackageBuilder(IExtensionManager extensionManager, IWebSiteFolder webSiteFolder) {
|
||||
_extensionManager = extensionManager;
|
||||
_webSiteFolder = webSiteFolder;
|
||||
@@ -27,7 +42,7 @@ namespace Orchard.Packaging.Services {
|
||||
var context = new CreateContext();
|
||||
BeginPackage(context);
|
||||
try {
|
||||
EstablishPaths(context, _webSiteFolder, extensionDescriptor.Location, extensionDescriptor.Name);
|
||||
EstablishPaths(context, _webSiteFolder, extensionDescriptor.Location, extensionDescriptor.Name, extensionDescriptor.ExtensionType);
|
||||
SetCoreProperties(context, extensionDescriptor);
|
||||
|
||||
string projectFile = extensionDescriptor.Name + ".csproj";
|
||||
@@ -36,6 +51,10 @@ namespace Orchard.Packaging.Services {
|
||||
EmbedProjectFiles(context, "Compile", "Content", "None", "EmbeddedResource");
|
||||
EmbedReferenceFiles(context);
|
||||
}
|
||||
else if (extensionDescriptor.ExtensionType == "Theme") {
|
||||
// this is a simple theme with no csproj
|
||||
EmbedThemeFiles(context);
|
||||
}
|
||||
}
|
||||
finally {
|
||||
EndPackage(context);
|
||||
@@ -110,6 +129,21 @@ namespace Orchard.Packaging.Services {
|
||||
}
|
||||
}
|
||||
|
||||
private void EmbedThemeFiles(CreateContext context) {
|
||||
var basePath = HostingEnvironment.VirtualPathProvider.GetDirectory(context.SourcePath).VirtualPath;
|
||||
foreach (var virtualPath in context.SourceFolder.ListFiles(context.SourcePath, true)) {
|
||||
// ignore dlls, etc
|
||||
if (IgnoreFile(virtualPath)) {
|
||||
continue;
|
||||
}
|
||||
// full virtual path given but we need the relative path so it can be put into
|
||||
// the package that way (the package itself is the logical base path).
|
||||
// Get it by stripping the basePath off including the slash.
|
||||
var relativePath = virtualPath.Replace(basePath, "");
|
||||
EmbedVirtualFile(context, relativePath, MediaTypeNames.Application.Octet);
|
||||
}
|
||||
}
|
||||
|
||||
private XName Ns(string localName) {
|
||||
return XName.Get(localName, "http://schemas.microsoft.com/developer/msbuild/2003");
|
||||
}
|
||||
@@ -120,9 +154,14 @@ namespace Orchard.Packaging.Services {
|
||||
context.Package = Package.Open(context.Stream, FileMode.Create, FileAccess.ReadWrite);
|
||||
}
|
||||
|
||||
private static void EstablishPaths(CreateContext context, IWebSiteFolder webSiteFolder, string locationPath, string moduleName) {
|
||||
private static void EstablishPaths(CreateContext context, IWebSiteFolder webSiteFolder, string locationPath, string moduleName, string moduleType) {
|
||||
context.SourceFolder = webSiteFolder;
|
||||
if (moduleType == "Theme") {
|
||||
context.SourcePath = "~/Themes/" + moduleName + "/";
|
||||
}
|
||||
else {
|
||||
context.SourcePath = "~/Modules/" + moduleName + "/";
|
||||
}
|
||||
context.TargetPath = "\\" + moduleName + "\\";
|
||||
}
|
||||
|
||||
|
@@ -38,6 +38,10 @@ namespace Orchard.Packaging.Services {
|
||||
ExtractProjectFiles(context, "Compile", "Content", "None", "EmbeddedResource");
|
||||
ExtractReferenceFiles(context);
|
||||
}
|
||||
else if (context.ExtensionType == "Theme") {
|
||||
// this is a simple theme with no csproj
|
||||
ExtractThemeFiles(context);
|
||||
}
|
||||
}
|
||||
finally {
|
||||
EndPackage(context);
|
||||
@@ -108,6 +112,14 @@ namespace Orchard.Packaging.Services {
|
||||
}
|
||||
}
|
||||
|
||||
private void ExtractThemeFiles(ExpandContext context) {
|
||||
foreach (var relativePath in from p in context.Package.GetParts()
|
||||
where p.Uri.ToString().StartsWith("/" + context.ExtensionName + "/", StringComparison.OrdinalIgnoreCase)
|
||||
select p.Uri.ToString().Substring(("/" + context.ExtensionName + "/").Length)) {
|
||||
ExtractFile(context, relativePath);
|
||||
}
|
||||
}
|
||||
|
||||
private bool PartExists(ExpandContext context, string relativePath) {
|
||||
Uri projectUri = PackUriHelper.CreatePartUri(new Uri(context.SourcePath + relativePath, UriKind.Relative));
|
||||
return context.Package.PartExists(projectUri);
|
||||
|
@@ -8,6 +8,7 @@ namespace Orchard.FileSystems.WebSite {
|
||||
/// </summary>
|
||||
public interface IWebSiteFolder : IVolatileProvider {
|
||||
IEnumerable<string> ListDirectories(string virtualPath);
|
||||
IEnumerable<string> ListFiles(string virtualPath, bool recursive);
|
||||
|
||||
bool FileExists(string virtualPath);
|
||||
string ReadFile(string virtualPath);
|
||||
|
@@ -28,6 +28,36 @@ namespace Orchard.FileSystems.WebSite {
|
||||
.ToArray();
|
||||
}
|
||||
|
||||
private IEnumerable<string> ListFiles(IEnumerable<string> directories) {
|
||||
return from dir in directories
|
||||
from file in ListFiles(dir, true)
|
||||
select file;
|
||||
}
|
||||
|
||||
public IEnumerable<string> ListFiles(string virtualPath, bool recursive) {
|
||||
if (!recursive) {
|
||||
return from VirtualFile file in HostingEnvironment.VirtualPathProvider.GetDirectory(virtualPath).Files
|
||||
select file.VirtualPath;
|
||||
}
|
||||
return (from VirtualFile file in HostingEnvironment.VirtualPathProvider.GetDirectory(virtualPath).Files
|
||||
select file.VirtualPath).Concat(ListFiles(ListDirectories(virtualPath)));
|
||||
/*
|
||||
|
||||
var path = HostingEnvironment.MapPath(virtualPath);
|
||||
if (path == null || !Directory.Exists(path)) {
|
||||
return Enumerable.Empty<string>();
|
||||
}
|
||||
|
||||
if (!path.EndsWith("\\")) {
|
||||
path += "\\";
|
||||
}
|
||||
|
||||
var files = Directory.GetFiles(path, searchPattern, recursive ? SearchOption.AllDirectories : SearchOption.TopDirectoryOnly);
|
||||
// strip base path to make it relative and replace '\' with '/'
|
||||
return from file in files
|
||||
select "~/" + file.Replace(path, "").Replace("\\", "/");*/
|
||||
}
|
||||
|
||||
public bool FileExists(string virtualPath) {
|
||||
return HostingEnvironment.VirtualPathProvider.FileExists(virtualPath);
|
||||
}
|
||||
|
Reference in New Issue
Block a user