Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/nicbell/ucreate

Create strongly typed views and generate DocTypes, DataTypes, MediaTypes and MemberTypes for Umbraco 7 using a code-first approach.
https://github.com/nicbell/ucreate

umbraco

Last synced: 2 months ago
JSON representation

Create strongly typed views and generate DocTypes, DataTypes, MediaTypes and MemberTypes for Umbraco 7 using a code-first approach.

Awesome Lists containing this project

README

        

UCreate [![Build status](https://ci.appveyor.com/api/projects/status/60v4v2cbl6nxmf0q?svg=true)](https://ci.appveyor.com/project/nicbell/ucreate) [![Nuget](https://buildstats.info/nuget/ucreate)](https://www.nuget.org/packages/UCreate/)
=======

Create doc types, media types, data types, member types and member groups for Umbraco 7 using a code-first approach. Inspired by [USiteBuilder](https://github.com/spopovic/uSiteBuilder).

Available on NuGet
---
```
PM> Install-Package UCreate
```

Usage
---

The only configuration you'll need to get started is an app setting in your ```web.config```. This tells UCreate to sync your doc types, media types, data types, member types and member groups on application start.

```xml
...

...

...

...
```

DocType example
---
Doc types support property inheritance. Here is a list of available [icons](http://nicbell.github.io/ucreate/icons.html).
```csharp
[DocType(Name = "Page With Title",
Icon = "icon-zip color-blue",
AllowedAsRoot = true,
AllowedTemplates = new[] { "PageWithTitle" },
DefaultTemplate = "PageWithTitle",
CompositionTypes = new[] { typeof(TaggedPage) })]
public class PageWithTitle : PublishedContentModel
{
public PageWithTitle(IPublishedContent content) : base(content)
{ }

[Property(Alias = "heading", TypeName = PropertyTypes.Textstring, Description = "Heading for page", Mandatory = true, TabName = "Content")]
public string Heading {
get { return Content.GetPropertyValue("heading"); }
}

[Property(Alias = "itemDate", Name = "Item Date", TypeName = PropertyTypes.DatePicker, Description = "Date", Mandatory = true, TabName = "Content")]
public DateTime ItemDate
{
get { return Content.GetPropertyValue("itemDate"); }
}
}
```

MediaType example
---
Media types support property inheritance.
```csharp
[MediaType(Name = "Folder With Cover",
Icon = "icon-folder color-blue",
AllowedAsRoot = true,
IsContainer = true,
AllowedChildTypes = new[] { typeof(FolderWithCover), typeof(Image) })]
public class FolderWithCover
{
[Property(Alias = "coverImage", TypeName = PropertyTypes.MediaPicker, Description = "Cover image.", Mandatory = true)]
public string CoverImage { get; set; }
}
```

DataType with prevalues example
---
```csharp
[DataType(EditorAlias = Umbraco.Core.Constants.PropertyEditors.ColorPickerAlias,
Name = "Nice Color Picker",
Key = "1bfca1e7-95d0-485e-bd94-9fe9c2b8821f",
DBType = DataTypeDatabaseType.Nvarchar)]
public class NiceColorPicker : IHasPreValues
{
///
/// Implementing PreValues
///
public IDictionary PreValues
{
get
{
return new Dictionary {
{"1", new PreValue("ff00ff")},
{"2", new PreValue("1f00f1")},
{"3", new PreValue("123123")},
{"4", new PreValue("ffffff")}
};
}
}
}
```

MemberType example
---
```csharp
[MemberType(Name = "Employee", Description = "Member who represents an employee", Icon = "icon-user color-green")]
public class Employee
{
[MemberProperty(Alias = "jobTitle", TypeName = PropertyTypes.Textstring, Description = "Employee's job title", Mandatory = true, TabName = "Job Details", CanEdit = true, ShowOnProfile = true)]
public string JobTitle { get; set; }

[MemberProperty(Alias = "jobDescription", TypeName = PropertyTypes.Textarea, Description = "Employee's job description", Mandatory = false, TabName = "Job Details", CanEdit = true, ShowOnProfile = false)]
public string JobDescription { get; set; }

[MemberProperty(Alias = "profilePicture", TypeName = PropertyTypes.MediaPicker, Description = "Admin profile picture", Mandatory = false, CanEdit = true, ShowOnProfile = true)]
public string ProfilePicture { get; set; }
}
```

MemberGroup example
---
```csharp
[MemberGroup(Name = "Staff")]
public class Staff
{
}
```

Strongly typed views
---
In order to use your doc types on the front-end you need to enable the `PublishedContentModel` factory. UCreate can do this for you if add the following app setting:
```xml
...

...

...

...
```
Then using the doc types in your views is pretty simple.
```html
@inherits UmbracoTemplatePage

@{
Layout = null;
}


PageWithTitle

@Model.Content.Heading

```

Contributing
---
If you have a fix for something don't be shy, submit a pull request.