-
-
Save lars-erik/78b7fd7bbb4a8ade669c to your computer and use it in GitHub Desktop.
Using Umbraco.CodeGen with PublishedContentModel. Flipped a few core classes and methods to public for testing.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using Umbraco.Core; | |
using Umbraco.Core.Models.PublishedContent; | |
using Umbraco.Core.ObjectResolution; | |
namespace CodeGenTest.Web.App_Start | |
{ | |
public class ApplicationEvents : ApplicationEventHandler | |
{ | |
protected override void ApplicationInitialized(UmbracoApplicationBase umbracoApplication, ApplicationContext applicationContext) | |
{ | |
ResolverBase<PublishedContentModelFactoryResolver>.Reset(); | |
PublishedContentModelFactoryResolver.Current = | |
new PublishedContentModelFactoryResolver(new PublishedContentModelFactoryImpl()); | |
} | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//------------------------------------------------------------------------------ | |
// <auto-generated> | |
// This code was generated by a tool. | |
// Runtime Version:4.0.30319.18051 | |
// | |
// Changes to this file may cause incorrect behavior and will be lost if | |
// the code is regenerated. | |
// </auto-generated> | |
//------------------------------------------------------------------------------ | |
namespace CodeGenTest.Web.Models.DocumentTypes | |
{ | |
using System; | |
using System.ComponentModel; | |
using System.ComponentModel.DataAnnotations; | |
using Umbraco.Core.Models; | |
using Umbraco.Web; | |
public partial class Article : Content | |
{ | |
private string icon = "folder.gif"; | |
private string thumbnail = "folder.png"; | |
private string defaultTemplate = "Article"; | |
private string[] allowedTemplates = new string[] { | |
"Article"}; | |
public Article(IPublishedContent content) : | |
base(content) | |
{ | |
} | |
[DataType("Numeric")] | |
public virtual Int32 Rating | |
{ | |
get | |
{ | |
return Content.GetPropertyValue<Int32>("rating"); | |
} | |
} | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@inherits CodeGenTest.Web.Models.UmbracoTemplatePage<CodeGenTest.Web.Models.DocumentTypes.Article> | |
@{ | |
Layout = "Layout.cshtml"; | |
} | |
@Html.Partial("Heading") | |
<p>@Html.Raw(CurrentPage.Body)</p> | |
<p>@CurrentPage.Rating</p> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//------------------------------------------------------------------------------ | |
// <auto-generated> | |
// This code was generated by a tool. | |
// Runtime Version:4.0.30319.18051 | |
// | |
// Changes to this file may cause incorrect behavior and will be lost if | |
// the code is regenerated. | |
// </auto-generated> | |
//------------------------------------------------------------------------------ | |
namespace CodeGenTest.Web.Models.DocumentTypes | |
{ | |
using System; | |
using System.ComponentModel; | |
using System.ComponentModel.DataAnnotations; | |
using Umbraco.Core.Models; | |
using Umbraco.Web; | |
public partial class Content : TypedModelBase | |
{ | |
private string icon = "folder.gif"; | |
private string thumbnail = "folder.png"; | |
private bool allowAtRoot = true; | |
private string defaultTemplate = "Content"; | |
private string[] allowedTemplates = new string[] { | |
"Content"}; | |
private System.Type[] structure = new System.Type[] { | |
typeof(Content), | |
typeof(DeviantContent), | |
typeof(Article)}; | |
public Content(IPublishedContent content) : | |
base(content) | |
{ | |
} | |
[DataType("Textstring")] | |
public virtual String Heading | |
{ | |
get | |
{ | |
return Content.GetPropertyValue<String>("heading"); | |
} | |
} | |
[DataType("Richtext editor")] | |
public virtual String Body | |
{ | |
get | |
{ | |
return Content.GetPropertyValue<String>("body"); | |
} | |
} | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@inherits CodeGenTest.Web.Models.UmbracoTemplatePage<CodeGenTest.Web.Models.DocumentTypes.Content> | |
@{ | |
Layout = "Layout.cshtml"; | |
} | |
@Html.Partial("Heading") | |
<p>@Html.Raw(CurrentPage.Body)</p> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
namespace CodeGenTest.Web.Models.DocumentTypes | |
{ | |
public partial class Content : IContent | |
{ | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//------------------------------------------------------------------------------ | |
// <auto-generated> | |
// This code was generated by a tool. | |
// Runtime Version:4.0.30319.18051 | |
// | |
// Changes to this file may cause incorrect behavior and will be lost if | |
// the code is regenerated. | |
// </auto-generated> | |
//------------------------------------------------------------------------------ | |
namespace CodeGenTest.Web.Models.DocumentTypes | |
{ | |
using System; | |
using System.ComponentModel; | |
using System.ComponentModel.DataAnnotations; | |
using Umbraco.Core.Models; | |
using Umbraco.Web; | |
public partial class DeviantContent : TypedModelBase | |
{ | |
private string icon = "folder.gif"; | |
private string thumbnail = "folder.png"; | |
private string defaultTemplate = "Deviant"; | |
private string[] allowedTemplates = new string[] { | |
"Deviant"}; | |
public DeviantContent(IPublishedContent content) : | |
base(content) | |
{ | |
} | |
[DataType("Textstring")] | |
public virtual String Heading | |
{ | |
get | |
{ | |
return Content.GetPropertyValue<String>("heading"); | |
} | |
} | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
namespace CodeGenTest.Web.Models.DocumentTypes | |
{ | |
public partial class DeviantContent : IContent | |
{ | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@inherits CodeGenTest.Web.Models.UmbracoTemplatePage<CodeGenTest.Web.Models.DocumentTypes.DeviantContent> | |
@{ | |
Layout = "Layout.cshtml"; | |
} | |
@Html.Partial("Heading") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@inherits CodeGenTest.Web.Models.UmbracoTemplatePage<CodeGenTest.Web.Models.IContent> | |
<h2>@CurrentPage.Heading</h2> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using Umbraco.Core.Models; | |
namespace CodeGenTest.Web.Models | |
{ | |
public interface IContent : IPublishedContent | |
{ | |
string Heading { get; } | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@inherits CodeGenTest.Web.Models.UmbracoTemplatePage<CodeGenTest.Web.Models.IContent> | |
<html> | |
<head> | |
<title>@CurrentPage.Heading</title> | |
</head> | |
<body> | |
@RenderBody() | |
</body> | |
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using Umbraco.Core.Models; | |
using Umbraco.Core.Models.PublishedContent; | |
namespace CodeGenTest.Web.Models | |
{ | |
public class TypedModelBase : PublishedContentModel | |
{ | |
public TypedModelBase(IPublishedContent content) : base(content) | |
{ | |
} | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using Umbraco.Core.Models; | |
using Umbraco.Web.Mvc; | |
namespace CodeGenTest.Web.Models | |
{ | |
public abstract class UmbracoTemplatePage<T> : UmbracoTemplatePage | |
where T : IPublishedContent | |
{ | |
public new T CurrentPage { get { return (T) Model.Content; } } | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment