Project Description

Lr.Templating is a basic library that simplifies templating documents.

Example #1

        /// <summary>
        /// Example where we build a template from a string.
        /// </summary>
        private static string ApiUsageFromString()
        {
            var template =
                TemplateFactory.New()
                .FromString("{greeting} {audience}!");

            template
                .Map("{greeting}")
                .To("Hello");

            template
                .Map("{audience}")
                .To("World");

            var personalisedTemplate
                = template.GetProcessedTemplate();

            return personalisedTemplate;
        }

Example #2

        /// <summary>
        /// Example where we build an TObject dependent template from file, be it a txt, html, css, or whatever 'template' file.
        ///
        /// We then can attach (map)
        /// - fixed (or constant) values to the placeholder;
        /// - functions that return a <see cref="string"/> value;
        /// - functions that take in a TObject, and return a <see cref="string"/> value.
        ///
        /// We call .GetProcessedTemplate() on the <see cref="ITemplate"/> and receive the filled out template.
        /// </summary>
        private static IEnumerable<string> ApiUsageForGenericVersion()
        {
            var currentDirectory = Directory.GetCurrentDirectory();

            var template =
                TemplateFactory.New<Person>()
                .FromFile(currentDirectory + @"\template.html");

            template
                .Map("{naam}")
                .To(p => p.FriendlyName);

            template
                .Map("{date}")
                .To(() => DateTime.Now.ToShortDateString() + " " + DateTime.Now.ToLongTimeString());

            foreach(var person in PeopleRepository.GetAll()) {
                var personalisedTemplate =
                template.GetProcessedTemplate(person);

                yield return personalisedTemplate;
            }
        }

NuGet

Lr.Core can be found on NuGet at https://www.nuget.org/packages/Lr.Templating/.

Requirements

Last edited Jun 16, 2014 at 9:48 PM by LeRenard, version 5