mirror of
https://github.com/OrchardCMS/Orchard.git
synced 2025-11-28 09:22:55 +08:00
Modified template module project to include mvc project type.
Modified module codegen command to include orchard controller t4 template. --HG-- branch : contributions
This commit is contained in:
@@ -0,0 +1,98 @@
|
|||||||
|
<#@ template language="C#" HostSpecific="True" #>
|
||||||
|
<#
|
||||||
|
MvcTextTemplateHost mvcHost = (MvcTextTemplateHost)(Host);
|
||||||
|
#>
|
||||||
|
using System.Web.Mvc;
|
||||||
|
using Orchard.Localization;
|
||||||
|
using Orchard;
|
||||||
|
|
||||||
|
namespace <#= mvcHost.Namespace #>
|
||||||
|
{
|
||||||
|
public class <#= mvcHost.ControllerName #> : Controller
|
||||||
|
{
|
||||||
|
public IOrchardServices Services { get; set; }
|
||||||
|
|
||||||
|
public <#= mvcHost.ControllerName #>(IOrchardServices services) {
|
||||||
|
Services = services;
|
||||||
|
T = NullLocalizer.Instance;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Localizer T { get; set; }
|
||||||
|
|
||||||
|
<#
|
||||||
|
if(mvcHost.AddActionMethods) {
|
||||||
|
#>
|
||||||
|
public ActionResult Index()
|
||||||
|
{
|
||||||
|
return View();
|
||||||
|
}
|
||||||
|
|
||||||
|
public ActionResult Details(int id)
|
||||||
|
{
|
||||||
|
return View();
|
||||||
|
}
|
||||||
|
|
||||||
|
public ActionResult Create()
|
||||||
|
{
|
||||||
|
return View();
|
||||||
|
}
|
||||||
|
|
||||||
|
[HttpPost]
|
||||||
|
public ActionResult Create(FormCollection collection)
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
// TODO: Add insert logic here
|
||||||
|
|
||||||
|
return RedirectToAction("Index");
|
||||||
|
}
|
||||||
|
catch
|
||||||
|
{
|
||||||
|
return View();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public ActionResult Edit(int id)
|
||||||
|
{
|
||||||
|
return View();
|
||||||
|
}
|
||||||
|
|
||||||
|
[HttpPost]
|
||||||
|
public ActionResult Edit(int id, FormCollection collection)
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
// TODO: Add update logic here
|
||||||
|
|
||||||
|
return RedirectToAction("Index");
|
||||||
|
}
|
||||||
|
catch
|
||||||
|
{
|
||||||
|
return View();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public ActionResult Delete(int id)
|
||||||
|
{
|
||||||
|
return View();
|
||||||
|
}
|
||||||
|
|
||||||
|
[HttpPost]
|
||||||
|
public ActionResult Delete(int id, FormCollection collection)
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
// TODO: Add delete logic here
|
||||||
|
|
||||||
|
return RedirectToAction("Index");
|
||||||
|
}
|
||||||
|
catch
|
||||||
|
{
|
||||||
|
return View();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
<#
|
||||||
|
}
|
||||||
|
#>
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -6,7 +6,7 @@
|
|||||||
<ProductVersion>9.0.30729</ProductVersion>
|
<ProductVersion>9.0.30729</ProductVersion>
|
||||||
<SchemaVersion>2.0</SchemaVersion>
|
<SchemaVersion>2.0</SchemaVersion>
|
||||||
<ProjectGuid>{$$ModuleProjectGuid$$}</ProjectGuid>
|
<ProjectGuid>{$$ModuleProjectGuid$$}</ProjectGuid>
|
||||||
<ProjectTypeGuids>{349c5851-65df-11da-9384-00065b846f21};{fae04ec0-301f-11d3-bf4b-00c04f79efbc}</ProjectTypeGuids>
|
<ProjectTypeGuids>{E53F8FEA-EAE0-44A6-8774-FFD645390401};{349c5851-65df-11da-9384-00065b846f21};{fae04ec0-301f-11d3-bf4b-00c04f79efbc}</ProjectTypeGuids>
|
||||||
<OutputType>Library</OutputType>
|
<OutputType>Library</OutputType>
|
||||||
<AppDesignerFolder>Properties</AppDesignerFolder>
|
<AppDesignerFolder>Properties</AppDesignerFolder>
|
||||||
<RootNamespace>$$ModuleName$$</RootNamespace>
|
<RootNamespace>$$ModuleName$$</RootNamespace>
|
||||||
|
|||||||
@@ -23,7 +23,7 @@ namespace Orchard.CodeGeneration.Commands {
|
|||||||
"", "Content", "Styles", "Scripts", "Views", "Zones"
|
"", "Content", "Styles", "Scripts", "Views", "Zones"
|
||||||
};
|
};
|
||||||
private static readonly string[] _moduleDirectories = new [] {
|
private static readonly string[] _moduleDirectories = new [] {
|
||||||
"", "Properties", "Controllers", "Views", "Models", "Scripts", "Styles"
|
"", "Properties", "Controllers", "Views", "Models", "Scripts", "Styles", "CodeTemplates/AddController"
|
||||||
};
|
};
|
||||||
|
|
||||||
private const string ModuleName = "CodeGeneration";
|
private const string ModuleName = "CodeGeneration";
|
||||||
@@ -210,6 +210,7 @@ namespace Orchard.CodeGeneration.Commands {
|
|||||||
string propertiesPath = modulePath + "Properties";
|
string propertiesPath = modulePath + "Properties";
|
||||||
var content = new HashSet<string>();
|
var content = new HashSet<string>();
|
||||||
var folders = new HashSet<string>();
|
var folders = new HashSet<string>();
|
||||||
|
var contentNoDeploy = new HashSet<string>();
|
||||||
|
|
||||||
foreach(var folder in _moduleDirectories) {
|
foreach(var folder in _moduleDirectories) {
|
||||||
Directory.CreateDirectory(modulePath + folder);
|
Directory.CreateDirectory(modulePath + folder);
|
||||||
@@ -226,6 +227,8 @@ namespace Orchard.CodeGeneration.Commands {
|
|||||||
content.Add(modulePath + "Scripts\\Web.config");
|
content.Add(modulePath + "Scripts\\Web.config");
|
||||||
File.WriteAllText(modulePath + "Styles\\Web.config", File.ReadAllText(_codeGenTemplatePath + "StaticFilesWebConfig.txt"));
|
File.WriteAllText(modulePath + "Styles\\Web.config", File.ReadAllText(_codeGenTemplatePath + "StaticFilesWebConfig.txt"));
|
||||||
content.Add(modulePath + "Styles\\Web.config");
|
content.Add(modulePath + "Styles\\Web.config");
|
||||||
|
File.WriteAllText(modulePath + "CodeTemplates\\AddController\\Controller.tt", File.ReadAllText(_codeGenTemplatePath + "Controller.tt."));
|
||||||
|
contentNoDeploy.Add(modulePath + "CodeTemplates\\AddController\\Controller.tt");
|
||||||
|
|
||||||
string templateText = File.ReadAllText(_codeGenTemplatePath + "ModuleAssemblyInfo.txt");
|
string templateText = File.ReadAllText(_codeGenTemplatePath + "ModuleAssemblyInfo.txt");
|
||||||
templateText = templateText.Replace("$$ModuleName$$", moduleName);
|
templateText = templateText.Replace("$$ModuleName$$", moduleName);
|
||||||
@@ -238,7 +241,7 @@ namespace Orchard.CodeGeneration.Commands {
|
|||||||
File.WriteAllText(modulePath + "Module.txt", templateText);
|
File.WriteAllText(modulePath + "Module.txt", templateText);
|
||||||
content.Add(modulePath + "Module.txt");
|
content.Add(modulePath + "Module.txt");
|
||||||
|
|
||||||
var itemGroup = CreateProjectItemGroup(modulePath, content, folders);
|
var itemGroup = CreateProjectItemGroup(modulePath, content, folders, contentNoDeploy);
|
||||||
|
|
||||||
File.WriteAllText(modulePath + moduleName + ".csproj", CreateCsProject(moduleName, projectGuid, itemGroup));
|
File.WriteAllText(modulePath + moduleName + ".csproj", CreateCsProject(moduleName, projectGuid, itemGroup));
|
||||||
}
|
}
|
||||||
@@ -321,7 +324,7 @@ namespace Orchard.CodeGeneration.Commands {
|
|||||||
|
|
||||||
// create new csproj for the theme
|
// create new csproj for the theme
|
||||||
if (projectGuid != null) {
|
if (projectGuid != null) {
|
||||||
var itemGroup = CreateProjectItemGroup(themePath, createdFiles, createdFolders);
|
var itemGroup = CreateProjectItemGroup(themePath, createdFiles, createdFolders, null);
|
||||||
string projectText = CreateCsProject(themeName, projectGuid, itemGroup);
|
string projectText = CreateCsProject(themeName, projectGuid, itemGroup);
|
||||||
File.WriteAllText(themePath + "\\" + themeName + ".csproj", projectText);
|
File.WriteAllText(themePath + "\\" + themeName + ".csproj", projectText);
|
||||||
}
|
}
|
||||||
@@ -329,7 +332,7 @@ namespace Orchard.CodeGeneration.Commands {
|
|||||||
if (includeInSolution) {
|
if (includeInSolution) {
|
||||||
if (projectGuid == null) {
|
if (projectGuid == null) {
|
||||||
// include in solution but dont create a project: just add the references to Orchard.Themes project
|
// include in solution but dont create a project: just add the references to Orchard.Themes project
|
||||||
var itemGroup = CreateProjectItemGroup(HostingEnvironment.MapPath("~/Themes/"), createdFiles, createdFolders);
|
var itemGroup = CreateProjectItemGroup(HostingEnvironment.MapPath("~/Themes/"), createdFiles, createdFolders, null);
|
||||||
AddFilesToOrchardThemesProject(output, itemGroup);
|
AddFilesToOrchardThemesProject(output, itemGroup);
|
||||||
TouchSolution(output);
|
TouchSolution(output);
|
||||||
}
|
}
|
||||||
@@ -356,7 +359,8 @@ namespace Orchard.CodeGeneration.Commands {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private static string CreateProjectItemGroup(string relativeFromPath, HashSet<string> content, HashSet<string> folders) {
|
private static string CreateProjectItemGroup(string relativeFromPath, HashSet<string> content, HashSet<string> folders, HashSet<string> contentNoDeploy)
|
||||||
|
{
|
||||||
var contentInclude = "";
|
var contentInclude = "";
|
||||||
if (relativeFromPath != null && !relativeFromPath.EndsWith("\\", StringComparison.OrdinalIgnoreCase)) {
|
if (relativeFromPath != null && !relativeFromPath.EndsWith("\\", StringComparison.OrdinalIgnoreCase)) {
|
||||||
relativeFromPath += "\\";
|
relativeFromPath += "\\";
|
||||||
@@ -374,6 +378,10 @@ namespace Orchard.CodeGeneration.Commands {
|
|||||||
contentInclude += "\r\n" + string.Join("\r\n", from folder in folders
|
contentInclude += "\r\n" + string.Join("\r\n", from folder in folders
|
||||||
select " <Folder Include=\"" + folder.Replace(relativeFromPath, "") + "\" />");
|
select " <Folder Include=\"" + folder.Replace(relativeFromPath, "") + "\" />");
|
||||||
}
|
}
|
||||||
|
if (contentNoDeploy != null && contentNoDeploy.Count > 0) {
|
||||||
|
contentInclude += "\r\n" + string.Join("\r\n", from file in contentNoDeploy
|
||||||
|
select " <None Include=\"" + file.Replace(relativeFromPath, "") + "\" />");
|
||||||
|
}
|
||||||
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);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -82,6 +82,9 @@
|
|||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<Content Include="CodeGenerationTemplates\Placement.info" />
|
<Content Include="CodeGenerationTemplates\Placement.info" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
<ItemGroup>
|
||||||
|
<Content Include="CodeGenerationTemplates\Controller.tt" />
|
||||||
|
</ItemGroup>
|
||||||
<Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" />
|
<Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" />
|
||||||
<Import Project="$(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v10.0\WebApplications\Microsoft.WebApplication.targets" />
|
<Import Project="$(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v10.0\WebApplications\Microsoft.WebApplication.targets" />
|
||||||
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
|
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
|
||||||
|
|||||||
Reference in New Issue
Block a user