mirror of
https://github.com/OrchardCMS/Orchard.git
synced 2025-04-05 21:01:35 +08:00
- create theme command now adds to the new Orchard.Themes project when /IncludeInSolution:true /CreateProject:false
- create theme command now sets BaseTheme in theme.txt when using /BasedOn option. --HG-- branch : dev
This commit is contained in:
parent
af3a348770
commit
245059a8e2
@ -3,5 +3,6 @@ Author: The Orchard Team
|
|||||||
Website: http://www.orchardproject.net
|
Website: http://www.orchardproject.net
|
||||||
Description: Description for the theme
|
Description: Description for the theme
|
||||||
Version: 1.0
|
Version: 1.0
|
||||||
|
BaseTheme: $$BaseTheme$$
|
||||||
# todo: provide tags
|
# todo: provide tags
|
||||||
# Tags: Classic, Serif
|
# Tags: Classic, Serif
|
||||||
|
@ -19,12 +19,6 @@ namespace Orchard.CodeGeneration.Commands {
|
|||||||
private readonly IExtensionManager _extensionManager;
|
private readonly IExtensionManager _extensionManager;
|
||||||
private readonly ISchemaCommandGenerator _schemaCommandGenerator;
|
private readonly ISchemaCommandGenerator _schemaCommandGenerator;
|
||||||
|
|
||||||
private static readonly string[] _ignoredExtensions = new [] {
|
|
||||||
"obj", "pdb", "exclude"
|
|
||||||
};
|
|
||||||
private static readonly string[] _ignoredPaths = new [] {
|
|
||||||
"/obj/"
|
|
||||||
};
|
|
||||||
private static readonly string[] _themeDirectories = new [] {
|
private static readonly string[] _themeDirectories = new [] {
|
||||||
"", "Content", "Styles", "Scripts", "Views", "Zones"
|
"", "Content", "Styles", "Scripts", "Views", "Zones"
|
||||||
};
|
};
|
||||||
@ -35,6 +29,7 @@ namespace Orchard.CodeGeneration.Commands {
|
|||||||
private const string ModuleName = "CodeGeneration";
|
private const string ModuleName = "CodeGeneration";
|
||||||
private static readonly string _codeGenTemplatePath = HostingEnvironment.MapPath("~/Modules/Orchard." + ModuleName + "/CodeGenerationTemplates/");
|
private static readonly string _codeGenTemplatePath = HostingEnvironment.MapPath("~/Modules/Orchard." + ModuleName + "/CodeGenerationTemplates/");
|
||||||
private static readonly string _orchardWebProj = HostingEnvironment.MapPath("~/Orchard.Web.csproj");
|
private static readonly string _orchardWebProj = HostingEnvironment.MapPath("~/Orchard.Web.csproj");
|
||||||
|
private static readonly string _orchardThemesProj = HostingEnvironment.MapPath("~/Themes/Orchard.Themes.csproj");
|
||||||
|
|
||||||
public CodeGenerationCommands(
|
public CodeGenerationCommands(
|
||||||
IExtensionManager extensionManager,
|
IExtensionManager extensionManager,
|
||||||
@ -131,23 +126,23 @@ namespace Orchard.CodeGeneration.Commands {
|
|||||||
}
|
}
|
||||||
|
|
||||||
[CommandName("generate create theme")]
|
[CommandName("generate create theme")]
|
||||||
[CommandHelp("generate create theme <theme-name> [/IncludeInSolution:true|false][/BasedOn:<theme-name>][]\r\n\tCreate a new Orchard theme")]
|
[CommandHelp("generate create theme <theme-name> [/CreateProject:true|false][/IncludeInSolution:true|false][/BasedOn:<theme-name>]\r\n\tCreate a new Orchard theme")]
|
||||||
[OrchardSwitches("IncludeInSolution,BasedOn,CreateProject")]
|
[OrchardSwitches("IncludeInSolution,BasedOn,CreateProject")]
|
||||||
public void CreateTheme(string themeName) {
|
public void CreateTheme(string themeName) {
|
||||||
Context.Output.WriteLine(T("Creating Theme {0}", themeName));
|
Context.Output.WriteLine(T("Creating Theme {0}", themeName));
|
||||||
if (_extensionManager.AvailableExtensions().Any(extension => String.Equals(themeName, extension.DisplayName, StringComparison.OrdinalIgnoreCase))) {
|
if (_extensionManager.AvailableExtensions().Any(extension => String.Equals(themeName, extension.Name, StringComparison.OrdinalIgnoreCase))) {
|
||||||
Context.Output.WriteLine(T("Creating Theme {0} failed: an extention of the same name already exists", themeName));
|
Context.Output.WriteLine(T("Creating Theme {0} failed: an extention of the same name already exists", themeName));
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
string baseThemePath = null;
|
|
||||||
if (!string.IsNullOrEmpty(BasedOn)) {
|
if (!string.IsNullOrEmpty(BasedOn)) {
|
||||||
baseThemePath = HostingEnvironment.MapPath("~/Themes/" + BasedOn + "/");
|
if (!_extensionManager.AvailableExtensions().Any(extension =>
|
||||||
if (string.IsNullOrEmpty(baseThemePath) || !Directory.Exists(baseThemePath)) {
|
string.Equals(extension.ExtensionType, "Theme", StringComparison.OrdinalIgnoreCase) &&
|
||||||
Context.Output.WriteLine(T("Creating Theme {0} failed: could not find base theme '{1}'", themeName, baseThemePath));
|
string.Equals(BasedOn, extension.Name, StringComparison.OrdinalIgnoreCase))) {
|
||||||
|
Context.Output.WriteLine(T("Creating Theme {0} failed: base theme named {1} was not found.", themeName, BasedOn));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
IntegrateTheme(themeName, baseThemePath);
|
IntegrateTheme(themeName, BasedOn);
|
||||||
Context.Output.WriteLine(T("Theme {0} created successfully", themeName));
|
Context.Output.WriteLine(T("Theme {0} created successfully", themeName));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -209,10 +204,10 @@ namespace Orchard.CodeGeneration.Commands {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void IntegrateTheme(string themeName, string baseThemePath) {
|
private void IntegrateTheme(string themeName, string baseTheme) {
|
||||||
CreateThemeFromTemplates(Context.Output, T,
|
CreateThemeFromTemplates(Context.Output, T,
|
||||||
themeName,
|
themeName,
|
||||||
baseThemePath,
|
baseTheme,
|
||||||
CreateProject ? Guid.NewGuid().ToString().ToUpper() : null,
|
CreateProject ? Guid.NewGuid().ToString().ToUpper() : null,
|
||||||
IncludeInSolution);
|
IncludeInSolution);
|
||||||
}
|
}
|
||||||
@ -258,13 +253,7 @@ namespace Orchard.CodeGeneration.Commands {
|
|||||||
return text;
|
return text;
|
||||||
}
|
}
|
||||||
|
|
||||||
private static bool IgnoreFile(string filePath) {
|
private static void CreateThemeFromTemplates(TextWriter output, Localizer T, string themeName, string baseTheme, string projectGuid, bool includeInSolution) {
|
||||||
return String.IsNullOrEmpty(filePath) ||
|
|
||||||
_ignoredPaths.Any(filePath.Contains) ||
|
|
||||||
_ignoredExtensions.Contains(Path.GetExtension(filePath) ?? "");
|
|
||||||
}
|
|
||||||
|
|
||||||
private static void CreateThemeFromTemplates(TextWriter output, Localizer T, string themeName, string baseThemePath, string projectGuid, bool includeInSolution) {
|
|
||||||
var themePath = HostingEnvironment.MapPath("~/Themes/" + themeName + "/");
|
var themePath = HostingEnvironment.MapPath("~/Themes/" + themeName + "/");
|
||||||
var createdFiles = new HashSet<string>();
|
var createdFiles = new HashSet<string>();
|
||||||
var createdFolders = new HashSet<string>();
|
var createdFolders = new HashSet<string>();
|
||||||
@ -277,44 +266,34 @@ namespace Orchard.CodeGeneration.Commands {
|
|||||||
createdFolders.Add(folder);
|
createdFolders.Add(folder);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (baseThemePath != null) {
|
|
||||||
// copy BasedOn theme file by file
|
var webConfig = themePath + "Views\\Web.config";
|
||||||
foreach (var file in Directory.GetFiles(baseThemePath, "*", SearchOption.AllDirectories)) {
|
File.WriteAllText(webConfig, File.ReadAllText(_codeGenTemplatePath + "\\ViewsWebConfig.txt"));
|
||||||
// ignore dlls, etc
|
createdFiles.Add(webConfig);
|
||||||
if (IgnoreFile(file)) {
|
|
||||||
continue;
|
var templateText = File.ReadAllText(_codeGenTemplatePath + "\\ThemeManifest.txt").Replace("$$ThemeName$$", themeName);
|
||||||
}
|
if (string.IsNullOrEmpty(baseTheme)) {
|
||||||
var destPath = file.Replace(baseThemePath, themePath);
|
templateText = templateText.Replace("BaseTheme: $$BaseTheme$$\r\n", "");
|
||||||
Directory.CreateDirectory(Path.GetDirectoryName(destPath));
|
|
||||||
File.Copy(file, destPath);
|
|
||||||
createdFiles.Add(destPath);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
// non-BasedOn theme default files
|
templateText = templateText.Replace("$$BaseTheme$$", baseTheme);
|
||||||
var webConfig = themePath + "Views\\Web.config";
|
|
||||||
File.WriteAllText(webConfig, File.ReadAllText(_codeGenTemplatePath + "\\ViewsWebConfig.txt"));
|
|
||||||
createdFiles.Add(webConfig);
|
|
||||||
}
|
}
|
||||||
var templateText = File.ReadAllText(_codeGenTemplatePath + "\\ThemeManifest.txt").Replace("$$ThemeName$$", themeName);
|
|
||||||
File.WriteAllText(themePath + "Theme.txt", templateText);
|
File.WriteAllText(themePath + "Theme.txt", templateText);
|
||||||
createdFiles.Add(themePath + "Theme.txt");
|
createdFiles.Add(themePath + "Theme.txt");
|
||||||
|
|
||||||
string itemGroup = null;
|
|
||||||
if (projectGuid != null || includeInSolution) {
|
|
||||||
itemGroup = CreateProjectItemGroup(themePath, createdFiles, createdFolders);
|
|
||||||
}
|
|
||||||
|
|
||||||
// create new csproj for the theme
|
// create new csproj for the theme
|
||||||
if (projectGuid != null) {
|
if (projectGuid != null) {
|
||||||
|
var itemGroup = CreateProjectItemGroup(themePath, createdFiles, createdFolders);
|
||||||
string projectText = CreateCsProject(themeName, projectGuid, itemGroup);
|
string projectText = CreateCsProject(themeName, projectGuid, itemGroup);
|
||||||
File.WriteAllText(themePath + "\\" + themeName + ".csproj", projectText);
|
File.WriteAllText(themePath + "\\" + themeName + ".csproj", projectText);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (includeInSolution) {
|
if (includeInSolution) {
|
||||||
if (projectGuid == null) {
|
if (projectGuid == null) {
|
||||||
// include in solution but dont create a project: just add the references to Orchard.Web
|
// include in solution but dont create a project: just add the references to Orchard.Themes project
|
||||||
AddFilesToOrchardWeb(output, T, itemGroup);
|
var itemGroup = CreateProjectItemGroup(HostingEnvironment.MapPath("~/Themes/"), createdFiles, createdFolders);
|
||||||
|
AddFilesToOrchardThemesProject(output, T, itemGroup);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
// create a project (already done) and add it to the solution
|
// create a project (already done) and add it to the solution
|
||||||
@ -363,12 +342,12 @@ namespace Orchard.CodeGeneration.Commands {
|
|||||||
return string.Format(CultureInfo.InvariantCulture, "<ItemGroup>\r\n{0}\r\n </ItemGroup>\r\n ", contentInclude);
|
return string.Format(CultureInfo.InvariantCulture, "<ItemGroup>\r\n{0}\r\n </ItemGroup>\r\n ", contentInclude);
|
||||||
}
|
}
|
||||||
|
|
||||||
private static void AddFilesToOrchardWeb(TextWriter output, Localizer T, string itemGroup) {
|
private static void AddFilesToOrchardThemesProject(TextWriter output, Localizer T, string itemGroup) {
|
||||||
if (!File.Exists(_orchardWebProj)) {
|
if (!File.Exists(_orchardThemesProj)) {
|
||||||
output.WriteLine(T("Warning: Orchard.Web project file could not be found at {0}", _orchardWebProj));
|
output.WriteLine(T("Warning: Orchard.Themes project file could not be found at {0}", _orchardThemesProj));
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
var projectText = File.ReadAllText(_orchardWebProj);
|
var projectText = File.ReadAllText(_orchardThemesProj);
|
||||||
|
|
||||||
// find where the first ItemGroup is after any References
|
// find where the first ItemGroup is after any References
|
||||||
var refIndex = projectText.LastIndexOf("<Reference Include");
|
var refIndex = projectText.LastIndexOf("<Reference Include");
|
||||||
@ -376,11 +355,11 @@ namespace Orchard.CodeGeneration.Commands {
|
|||||||
var firstItemGroupIndex = projectText.IndexOf("<ItemGroup>", refIndex);
|
var firstItemGroupIndex = projectText.IndexOf("<ItemGroup>", refIndex);
|
||||||
if (firstItemGroupIndex != -1) {
|
if (firstItemGroupIndex != -1) {
|
||||||
projectText = projectText.Insert(firstItemGroupIndex, itemGroup);
|
projectText = projectText.Insert(firstItemGroupIndex, itemGroup);
|
||||||
File.WriteAllText(_orchardWebProj, projectText);
|
File.WriteAllText(_orchardThemesProj, projectText);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
output.WriteLine(T("Warning: Unable to modify Orchard.Web project file at {0}", _orchardWebProj));
|
output.WriteLine(T("Warning: Unable to modify Orchard.Themes project file at {0}", _orchardThemesProj));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user