/// <summary>
        /// Gets a shortcode definition for the specified shortcode name.
        /// </summary>
        /// <param name="shortcodeName"></param>
        /// <returns></returns>
        public static DynamicShortcodeDefinition GetShortcodeDefinition(string shortcodeName)
        {
            DynamicShortcodeDefinition newShortcode = null;

            var shortcodeDefinition = LavaShortcodeCache.All().Where(c => c.TagName != null && c.TagName.Equals(shortcodeName, StringComparison.OrdinalIgnoreCase)).FirstOrDefault();

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

            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(",").ToList();

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

            return(newShortcode);
        }
        /// <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));
            }
        }
        /// <summary>
        /// Initializes the specified tag name.
        /// </summary>
        /// <param name="tagName">Name of the tag.</param>
        /// <param name="markup">The markup.</param>
        /// <param name="tokens">The tokens.</param>
        /// <exception cref="System.Exception">Could not find the variable to place results in.</exception>
        public override void Initialize(string tagName, string markup, List <string> tokens)
        {
            _markup    = markup;
            _tagName   = tagName;
            _shortcode = LavaShortcodeCache.All().Where(c => c.TagName == tagName).FirstOrDefault();

            base.Initialize(tagName, markup, tokens);
        }
        /// <summary>
        /// Method that will be run at Rock startup
        /// </summary>
        public override void OnStartup()
        {
            // get all the block dynamic shortcodes and register them
            var blockShortCodes = LavaShortcodeCache.All().Where(s => s.TagType == TagType.Block);

            foreach (var shortcode in blockShortCodes)
            {
                // register this shortcode
                Template.RegisterShortcode <DynamicShortcodeBlock>(shortcode.TagName);
            }
        }
Exemple #5
0
        /// <summary>
        /// Method that will be run at Rock startup
        /// </summary>
        public override void OnStartup()
        {
            // get all the inline dynamic shortcodes and register them
            var inlineShortCodes = LavaShortcodeCache.All().Where(s => s.TagType == TagType.Inline);

            foreach (var shortcode in inlineShortCodes)
            {
                // register this shortcode
                Template.RegisterShortcode <DynamicShortcodeInline>(shortcode.TagName);
            }
        }
Exemple #6
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);
            }
        }