Skip to content

Instantly share code, notes, and snippets.

View jamiepollock's full-sized avatar

Jamie Pollock jamiepollock

View GitHub Profile
@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 / 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 / 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 / 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 / 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 / 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 / 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 / package.manifest
Created September 19, 2014 16:32
A custom umbraco directive which allows the user to bing an umb-editor to a property whilst providing a custom config.
{
javascript: [
'~/App_Plugins/YourPackage/your.controller.js',
'~/App_Plugins/YourPackage/umbraco-editor-with-config.js',
]
}
@jamiepollock
jamiepollock / LocalizedEditorModelEventManagerEventHandler.cs
Created October 21, 2016 16:30
Working with EditorModelEventManager to localise an EditorContentModel powered by /config/lang/*.user.xml files
using System.Collections.Generic;
using System.Globalization;
using Umbraco.Core;
using Umbraco.Core.Services;
using Umbraco.Web;
using Umbraco.Web.Editors;
using Umbraco.Web.Models.ContentEditing;
namespace MyWebsite
{
@jamiepollock
jamiepollock / CustomMigrationBase.cs
Last active January 22, 2018 16:49
A layer on top of Umbraco's MigrationBase for checking a table has Indexes, Constraints & Columns
using System.Linq;
using Umbraco.Core.Logging;
using Umbraco.Core.Persistence.Migrations;
using Umbraco.Core.Persistence.SqlSyntax;
namespace My.Website.Migrations
{
public abstract class CustomMigrationBase : MigrationBase
{
public CustomMigrationBase(ISqlSyntaxProvider sqlSyntax, ILogger logger) : base(sqlSyntax, logger)