Skip to content

Instantly share code, notes, and snippets.

View jamiepollock's full-sized avatar

Jamie Pollock jamiepollock

View GitHub Profile
@jamiepollock
jamiepollock / Bootstrap3.cshtml
Created April 16, 2017 00:35
Example of Umbraco GridSettings using the Bootstrap3.cshtml with Umbraco v7.5.4+
@inherits UmbracoViewPage<dynamic>
@using Umbraco.Web.Templates;
@using Newtonsoft.Json.Linq;
@using Our.Umbraco.GridSettings.Web;
@using Our.Umbraco.GridSettings.Services;
@using Our.Umbraco.GridSettings.Resolvers;
@{
var attributesResolver = new GroupByPrefixTokenGridSettingsAttributesResolver("_");
var attributesService = new GridSettingsAttributesService(attributesResolver);
}
@jamiepollock
jamiepollock / MyDirective.js
Created January 11, 2016 10:22
Simple reusable rte editor - wrapping umb-editor rte with a reusable config for use in a custom Umbraco backoffice ui
angular.module("umbraco.directives").directive('simplerichtexteditor', function (assetsService) {
return {
restrict: 'E',
scope: {
field: '='
},
controller: function ($scope, $element) {
$scope.model = {
alias: 'simpleRichtextEditor',
view: 'rte',
@jamiepollock
jamiepollock / DecimalTests.cs
Created February 1, 2017 04:03
Tests for Decimal conversion in Umbraco Ditto
using NUnit.Framework;
using Our.Umbraco.Ditto.Tests.Mocks;
namespace Our.Umbraco.Ditto.Tests
{
[TestFixture]
[Category("Processors")]
public class DecimalTests
{
public class MyModel
@jamiepollock
jamiepollock / FormHtmlApiController.cs
Created January 26, 2017 19:12
In Theory (TM)! How to return an Umbraco Form HTML from an ApiController
using System.Web;
using Umbraco.Web.WebApi;
namespace My.Website.Controllers.Api
{
public class FormHtmlApiController : UmbracoApiController
{
public IHtmlString Get(string id)
{
return Umbraco.RenderMacro("FormsRenderForm", new { FormGuid = id });
@jamiepollock
jamiepollock / ProtectedContentNotifyEventHandler.cs
Last active June 27, 2016 13:04
ProtectedContentNotifyEventHandler an Umbraco event which will look for any members who have access to the current content node being saved then send an email to them
using System;
using System.Collections.Generic;
using System.Linq;
using Umbraco.Core;
using Umbraco.Core.Models;
using Umbraco.Core.Services;
namespace DemoApp
{
public class ProtectedContentNotifyEventHandler : ApplicationEventHandler
@jamiepollock
jamiepollock / MyContentSmellerEventHandler.cs
Created June 7, 2016 15:02
Untested example of checking what's changed between revisions of a IContent save event handler in Umbraco.
using System.Linq;
using Umbraco.Core;
using Umbraco.Core.Models;
using Umbraco.Core.Services;
namespace My.App.Events
{
public class MyContentSmellerEventHandler : ApplicationEventHandler
{
protected override void ApplicationStarted(UmbracoApplicationBase umbracoApplication, ApplicationContext applicationContext)
@jamiepollock
jamiepollock / ArchetypeLabelHelper.js
Created April 7, 2016 16:48
A JS Helper for making Umbraco Archetype template labels beautiful :)
var ArchetypeLabelHelper = (function () {
//private helpers
if (!String.prototype.format) {
String.prototype.format = function () {
var args = arguments;
return this.replace(/{(\d+)}/g, function (match, number) {
return typeof args[number] != 'undefined'
? args[number]
: match
;
@jamiepollock
jamiepollock / JsonDropDownListApiController.cs
Created November 27, 2013 22:19
A demo Umbraco v6+ UmbracoApiController (an Umbraco Context wrapped WebApiController). Each request returns an array of strings which would typically be read in by a JavaScript library as JSON.
using System;
using System.Collections.Generic;
using Umbraco.Core.Models;
using Umbraco.Web.Mvc;
using Umbraco.Web.WebApi;
namespace UmbracoDemo.Controllers
{
[PluginController("JsonDropDownList")]
public class JsonDropDownListApiController : UmbracoApiController
@jamiepollock
jamiepollock / CustomDittoValueResolver.cs
Created September 21, 2015 14:58
Custom Ditto ValueResolver - Single IPublishedContent from IEnumerable<IPublishedContent
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using Our.Umbraco.Ditto;
using Umbraco.Core.Models;
namespace My.Website.ComponentModel
{
public class SinglePublishedContentUmbracoPropertyAttribute : UmbracoPropertyAttribute
@jamiepollock
jamiepollock / MultipleIPublishedTypeConverterBase.cs
Last active September 22, 2015 07:59
Ditto TypeConverter - Multiple IEnumerable<IPublishedContent> & Single IPublishedContent
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Globalization;
using Umbraco.Core;
using Umbraco.Core.Models;
namespace My.Website.ComponentModel.TypeConverters
{
public abstract class MultipleIPublishedContentTypeConverterBase<T> : TypeConverter