Coder Social home page Coder Social logo

jamiepollock / ditto.resolvers Goto Github PK

View Code? Open in Web Editor NEW

This project forked from micklaw/ditto.resolvers

0.0 2.0 0.0 9.52 MB

Some resolvers that can be hooked to Ditto for Archetype, The Grid etc

License: MIT License

CSS 6.61% JavaScript 72.49% HTML 13.35% C# 1.18% ASP 5.56% XSLT 0.77% Erlang 0.03% Batchfile 0.01%

ditto.resolvers's Introduction

Ditto.Resolvers

Build status NuGet release

Ditto is awesome, we all know that, though it would be nice if we could hook third parties like Archetype and The Grid to the Ditto flow. This wee chunk of code is aiming to achieve just that.

Currently this only has support for Archetypes, but hopefully over the next couple of weeks we can add to that.

Archetypes

Setup is easy. Below is a Ditto class which maps to my Home document type, this document type has an Archetype property called PriceList (alias: priceList).

	public class Home : Page
    {
        public Home(IPublishedContent content) : base(content)
        {
        }

        public string Title { get; set; }

        public HtmlString Body { get; set; }

        [ArchetypeResolver]
        public List<PriceList> PriceList { get; set; }
    }

PriceList is just a POCO which inherits from the Archetype class ArchetypeFieldsetModel.

	public class PriceList : ArchetypeFieldsetModel
    {
        public string Title { get; set; }

        public int Quantity { get; set; }

        public string Price { get; set; }

        [TypeConverter(typeof(DittoContentPickerConverter))]
        public Content AssociatedPage { get; set; }
    }

Now when we use Ditto to map the Home document type via the .As(); extension method, our Archetype will map to our POCO. Nice and easy, eh? This will provide almost all the functionality of Ditto e.g. TypeConverters, LazyLoading to use on your Archetype POCOs.

Options

Alias

If your Archetype property on your Home document type doesn't match the Property name, you can set this in the ArchetypeResolverAttribute.

	[ArchetypeResolver("HomeDocTypePriceListAlias")]
	public List<PriceList> PriceList { get; set; }

Single items

Your Archetype doesn't have to be a list! Simply use a single Type of your Archetype POCO and it will attempt to map to that.

	[ArchetypeResolver]
	public PriceList PriceList { get; set; }

Multiple fieldsets

If you have enabled multiple fieldsets in your Archetype data type this would create a generic list including all of the different types of your POCOs which match an Archetype fieldset. The only caveat being your property on your Home document type would require to be a generic list with the base class ArchetypeFieldsetModel as its first generic property. This allows various different types inheriting from the base class to be assigned to the list.

	[ArchetypeResolver]
	public List<ArchetypeFieldsetModel> PriceList { get; set; }

Nested Archetypes

Rejoice. Nested Archetypes should also work so long as you have decorated the child Archetype property on your POCO with the ArchetypeResolverAttribute.

	public class PriceList : ArchetypeFieldsetModel
    {
        public string Title { get; set; }

        public int Quantity { get; set; }

        public string Price { get; set; }

        [TypeConverter(typeof(DittoContentPickerConverter))]
        public Content AssociatedPage { get; set; }
        
        [ArchetypeResolver]
		public List<UrlPicker> Links { get; set; }
    }

Archetypes Constraints

There are two contrainsts around POCO Archetypes currently.

  • Each POCO must inherit from the ArchetypeFieldsetModel in the Archetype assembly.
  • The Name of your class must match the Archetypes alias on the fieldset alias.

We can work around the second issue here in the coming weeks, but the first one is a deal breaker. Sorry if this offends you!

ditto.resolvers's People

Contributors

micklaw avatar

Watchers

 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.