Git Product home page Git Product logo

umbraco.codegen's Introduction

Umbraco uSync Code Generator

Synchronizes C# classes with uSync DocumentType files.

Add all assemblies to Umbraco/Bin and you're good to go. (Yes, yes, package is coming) Config is read from uSync and ~/config/CodeGen.config.

Depends on https://github.com/icsharpcode/NRefactory

Binaries available here: http://lars-erik.github.io/Umbraco.CodeGen/

##Recommended uSync setup: <usync read="true" write="false" attach="true" .../>

Having write="true" will overwrite your code, so don't use it unless you don't want to edit generated code.

DO NOT CODE FIRST BEFORE FIRST RUN OF USYNC! YOU'LL LOSE YOUR CODE!

DO NOT WRITE LOGIC IN THE CLASSES, ONLY PROPERTIES! YOU'LL LOSE YOUR CODE!

Classes are partial for this reason

##Recommended CodeGen config (~/config/CodeGen.config):

###CodeGenerator element

ModelPath

If you have ReSharper, set the Models\Synchronized folder as Namespace Provider=False. Otherwise, make a folder that has the namespace structure you want. The code generation will attemt to create DocumentType XML for ALL classes found in the specified folder.

BaseClass

A class in the same namespace as the generated/code first classes with at least the following structure:

public class DocumentTypeBase
{
    protected IPublishedContent Content; // Can be field or property, must be named Content

    protected DocumentTypeBase(IPublishedContent content) // Must implement ctor with one IPublishedContent arg
    {
        Content = content;
    }
}

The class itself can be named whatever.

It should however not be in the synced folders, keep it one step up, for instance under Models.

Namespace

Preferably the correct namespace for your model folder. :)

GenerateClasses

Whether to generate class for document types when saved. (Works with uSync attach=true)

GenerateXml

Whether to generate XML for document types when Umbraco starts. (Works with uSync read=true)

RemovePrefix

Partially implemented and not at all tested. Should remove prefixes from class and property names if you have them in your aliases.

OverwriteReadOnly

For everyone lucky enough to have a SCS locking the files.

TypeMappings

Pretty self explanatory if you should use this tool at all. ;) For some reason the CSharpCodeDomProvider adds @ to intristic type aliases. (string, int etc.) Use the class names of the types to avoid it. DataTypeId = the editor ID.

###Supported code constructs

Class attributes

  • [DisplayName] - Document type name
  • [Description] - Guess what

Class name

Alias, camelCased in XML, PascalCased in C#.

Class fields

  • String icon
  • String thumbnail
  • Boolean allowAtRoot
  • String[] allowedTemplates
  • String defaultTemplate
  • Type[] structure

Class ctor

See base class

Property attributes

  • [DisplayName] - Property name
  • [Description] - Yup
  • [Category] - Tab name, leave empty for "generic properties"
  • [DataType] - DataType definition ID (Not editor)
  • [RegularExpression] - Validation
  • [Required] - Mandatory

Property name

Alias, camelCased in XML, PascalCased in C#.

Property getter

Will be regenerated as return Content.GetPropertyValue<T>("alias")

ANY CODE BUT THIS WILL BE DELETED ON ROUNDTRIP!

###Gotchas:

  • Generated classes are partial DO NOT write code other than properties in the generated classes!
  • If document type and property has the same name, the class is suffixed with "Class"

umbraco.codegen's People

Contributors

lars-erik avatar

Watchers

 avatar  avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.