Example #1
0
 public string Results(PictureDirectoryController ctl)
 {
     try
     {
         var hb = RegisterHelpers(ctl);
         var compiledTemplate = hb.Compile(template);
         var s = compiledTemplate(this);
         return(s);
     }
     catch (Exception ex)
     {
         return(ex.Message + "<br>\n" + ex.StackTrace);
     }
 }
Example #2
0
        private IHandlebars RegisterHelpers(PictureDirectoryController ctl)
        {
            var handlebars = PythonModel.RegisterHelpers(DbUtil.Db);

            handlebars.RegisterHelper("SmallUrl", (w, ctx, args) =>
            {
                GetPictureUrl(ctx, w, ctx.SmallId,
                              Picture.SmallMissingMaleId, Picture.SmallMissingFemaleId, Picture.SmallMissingGenericId);
            });
            handlebars.RegisterHelper("MediumUrl", (w, ctx, args) =>
            {
                GetPictureUrl(ctx, w, ctx.MediumId,
                              Picture.MediumMissingMaleId, Picture.MediumMissingFemaleId, Picture.MediumMissingGenericId);
            });
            handlebars.RegisterHelper("ImagePos", (w, ctx, args) => { w.Write(ctx.X != null || ctx.Y != null ? $"{ctx.X ?? 0}% {ctx.Y ?? 0}%" : "top"); });
            handlebars.RegisterHelper("IfAccess", (w, opt, ctx, args) =>
            {
                if (HasAccess)
                {
                    opt.Template(w, (object)ctx);
                }
                else
                {
                    opt.Inverse(w, (object)ctx);
                }
            });
            handlebars.RegisterHelper("PagerTop", (w, ctx, args) => { w.Write(ViewExtensions2.RenderPartialViewToString(ctl, "PagerTop", this)); });
            handlebars.RegisterHelper("PagerBottom", (w, ctx, args) => { w.Write(ViewExtensions2.RenderPartialViewToString(ctl, "PagerBottom", this)); });
            handlebars.RegisterHelper("PagerHidden", (w, ctx, args) => { w.Write(ViewExtensions2.RenderPartialViewToString(ctl, "PagerHidden", this)); });
            handlebars.RegisterHelper("SortBirthday", (w, ctx, args) => { w.Write(SortLink("Birthday")); });
            handlebars.RegisterHelper("SortName", (w, ctx, args) => { w.Write(SortLink("Name")); });
            handlebars.RegisterHelper("CityStateZip", (w, ctx, args) => { w.Write(Util.FormatCSZ4(ctx.City, ctx.St, ctx.Zip)); });
            handlebars.RegisterHelper("BirthDay", (w, ctx, args) =>
            {
                var dob = (string)ctx.DOB;
                w.Write(dob.ToDate().ToString2("m"));
            });
            return(handlebars);
        }