Skip to content

Instantly share code, notes, and snippets.

@lars-erik
Created October 23, 2013 07:55
Show Gist options
  • Save lars-erik/78b7fd7bbb4a8ade669c to your computer and use it in GitHub Desktop.
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.
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());
}
}
}
//------------------------------------------------------------------------------
// <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");
}
}
}
}
@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>
//------------------------------------------------------------------------------
// <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");
}
}
}
}
@inherits CodeGenTest.Web.Models.UmbracoTemplatePage<CodeGenTest.Web.Models.DocumentTypes.Content>
@{
Layout = "Layout.cshtml";
}
@Html.Partial("Heading")
<p>@Html.Raw(CurrentPage.Body)</p>
namespace CodeGenTest.Web.Models.DocumentTypes
{
public partial class Content : IContent
{
}
}
//------------------------------------------------------------------------------
// <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");
}
}
}
}
namespace CodeGenTest.Web.Models.DocumentTypes
{
public partial class DeviantContent : IContent
{
}
}
@inherits CodeGenTest.Web.Models.UmbracoTemplatePage<CodeGenTest.Web.Models.DocumentTypes.DeviantContent>
@{
Layout = "Layout.cshtml";
}
@Html.Partial("Heading")
@inherits CodeGenTest.Web.Models.UmbracoTemplatePage<CodeGenTest.Web.Models.IContent>
<h2>@CurrentPage.Heading</h2>
using Umbraco.Core.Models;
namespace CodeGenTest.Web.Models
{
public interface IContent : IPublishedContent
{
string Heading { get; }
}
}
@inherits CodeGenTest.Web.Models.UmbracoTemplatePage<CodeGenTest.Web.Models.IContent>
<html>
<head>
<title>@CurrentPage.Heading</title>
</head>
<body>
@RenderBody()
</body>
</html>
using Umbraco.Core.Models;
using Umbraco.Core.Models.PublishedContent;
namespace CodeGenTest.Web.Models
{
public class TypedModelBase : PublishedContentModel
{
public TypedModelBase(IPublishedContent content) : base(content)
{
}
}
}
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