/// <summary>
        /// Register the specified shortcodes with the Lava Engine.
        /// </summary>
        /// <param name="engine"></param>
        public static void RegisterShortcodes(ILavaEngine engine)
        {
            ClearCache();

            // Register shortcodes defined in the code base.
            try
            {
                var shortcodeTypes = Rock.Reflection.FindTypes(typeof(ILavaShortcode)).Select(a => a.Value).ToList();

                foreach (var shortcodeType in shortcodeTypes)
                {
                    engine.RegisterShortcode(shortcodeType.Name, (shortcodeName) =>
                    {
                        var shortcode = Activator.CreateInstance(shortcodeType) as ILavaShortcode;

                        return(shortcode);
                    });
                }
            }
            catch (Exception ex)
            {
                ExceptionLogService.LogException(ex, null);
            }

            // Register shortcodes defined in the current database.
            var shortCodes = LavaShortcodeCache.All();

            foreach (var shortcode in shortCodes)
            {
                engine.RegisterShortcode(shortcode.TagName, (shortcodeName) => GetShortcodeDefinition(shortcodeName));
            }
        }
Esempio n. 2
0
        /// <summary>
        /// Registers a shortcode definition that can be used to create new instances of a shortcode during the rendering process.
        /// </summary>
        /// <param name="shortcodeDefinition"></param>
        public static void RegisterShortcode(DynamicShortcodeDefinition shortcodeDefinition)
        {
            if (_engine == null)
            {
                return;
            }

            _engine.RegisterShortcode(shortcodeDefinition);
        }
        private static void RegisterStaticShortcodes(ILavaEngine engine)
        {
            // Get all shortcodes and call OnStartup methods
            try
            {
                var shortcodeTypes = Rock.Reflection.FindTypes(typeof(ILavaShortcode)).Select(a => a.Value).ToList();

                foreach (var shortcodeType in shortcodeTypes)
                {
                    // Create an instance of the shortcode to get the registration name.
                    var instance = Activator.CreateInstance(shortcodeType) as ILavaShortcode;

                    var name = instance.SourceElementName;

                    if (string.IsNullOrWhiteSpace(name))
                    {
                        name = shortcodeType.Name;
                    }

                    engine.RegisterShortcode(name, (shortcodeName) =>
                    {
                        var shortcode = Activator.CreateInstance(shortcodeType) as ILavaShortcode;

                        return(shortcode);
                    });
                }
            }
            catch (Exception ex)
            {
                ExceptionLogService.LogException(ex, null);
            }
        }
Esempio n. 4
0
        private static void InitializeLavaShortcodes(ILavaEngine engine)
        {
            // Register shortcodes defined in the codebase.
            try
            {
                var shortcodeTypes = Rock.Reflection.FindTypes(typeof(ILavaShortcode)).Select(a => a.Value).ToList();

                foreach (var shortcodeType in shortcodeTypes)
                {
                    // Create an instance of the shortcode to get the registration name.
                    var instance = Activator.CreateInstance(shortcodeType) as ILavaShortcode;

                    var name = instance.SourceElementName;

                    if (string.IsNullOrWhiteSpace(name))
                    {
                        name = shortcodeType.Name;
                    }

                    // Register the shortcode with a factory method to create a new instance of the shortcode from the System.Type defined in the codebase.
                    engine.RegisterShortcode(name, (shortcodeName) =>
                    {
                        var shortcode = Activator.CreateInstance(shortcodeType) as ILavaShortcode;

                        return(shortcode);
                    });
                }
            }
            catch (Exception ex)
            {
                ExceptionLogService.LogException(ex, null);
            }

            // Register shortcodes defined in the current database.
            var shortCodes = LavaShortcodeCache.All();

            foreach (var shortcode in shortCodes)
            {
                // Register the shortcode with the current Lava Engine.
                // The provider is responsible for retrieving the shortcode definition from the data store and managing the web-based shortcode cache.
                WebsiteLavaShortcodeProvider.RegisterShortcode(engine, shortcode.TagName);
            }
        }
        private static void RegisterDynamicShortcodes(ILavaEngine engine)
        {
            // Register dynamic shortcodes with a factory method to ensure that the latest definition is retrieved from the global cache each time the shortcode is used.
            Func <string, DynamicShortcodeDefinition> shortCodeFactory = (shortcodeName) =>
            {
                var shortcodeDefinition = LavaShortcodeCache.All().Where(c => c.TagName == shortcodeName).FirstOrDefault();

                if (shortcodeDefinition == null)
                {
                    return(null);
                }

                var newShortcode = new DynamicShortcodeDefinition();

                newShortcode.Name           = shortcodeDefinition.Name;
                newShortcode.TemplateMarkup = shortcodeDefinition.Markup;

                var parameters = RockSerializableDictionary.FromUriEncodedString(shortcodeDefinition.Parameters);

                newShortcode.Parameters = new Dictionary <string, string>(parameters.Dictionary);

                newShortcode.EnabledLavaCommands = shortcodeDefinition.EnabledLavaCommands.SplitDelimitedValues(",", StringSplitOptions.RemoveEmptyEntries).ToList();

                if (shortcodeDefinition.TagType == TagType.Block)
                {
                    newShortcode.ElementType = LavaShortcodeTypeSpecifier.Block;
                }
                else
                {
                    newShortcode.ElementType = LavaShortcodeTypeSpecifier.Inline;
                }

                return(newShortcode);
            };

            var shortCodes = LavaShortcodeCache.All();

            foreach (var shortcode in shortCodes)
            {
                engine.RegisterShortcode(shortcode.TagName, shortCodeFactory);
            }
        }
Esempio n. 6
0
 /// <summary>
 /// Register the specified shortcodes with the Lava Engine.
 /// </summary>
 /// <param name="engine"></param>
 public void RegisterShortcode(ILavaEngine engine, LavaShortcode shortcode)
 {
     engine.RegisterShortcode(shortcode.TagName, (shortcodeName) => GetShortcodeDefinition(shortcodeName));
 }
Esempio n. 7
0
 /// <summary>
 /// Register the specified shortcodes with the Lava Engine.
 /// </summary>
 /// <param name="engine"></param>
 public void RegisterShortcode(ILavaEngine engine, DynamicShortcodeDefinition shortcode)
 {
     engine.RegisterShortcode(shortcode.Name, (shortcodeName) => GetShortcodeDefinition(shortcodeName));
 }
 /// <summary>
 /// Register the specified shortcodes with the Lava Engine.
 /// </summary>
 /// <param name="engine"></param>
 /// <param name="shortcodeName"></param>
 public static void RegisterShortcode(ILavaEngine engine, string shortcodeName)
 {
     // Register a factory method that will retrieve the shortcde definition from the data store on demand.
     engine.RegisterShortcode(shortcodeName, (name) => GetShortcodeDefinition(name));
 }