コード例 #1
0
        /// <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);
        }
コード例 #2
0
ファイル: LavaService.cs プロジェクト: SparkDevNetwork/Rock
        /// <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);
        }
コード例 #3
0
        /// <summary>
        ///  Initialize this shortcode instance with metadata provided by a shortcode definition.
        /// </summary>
        /// <param name="definition"></param>
        public void Initialize(DynamicShortcodeDefinition definition, ILavaEngine engine)
        {
            if (_shortcode != null)
            {
                throw new Exception();
            }

            _shortcode = definition;
            _engine    = engine;
        }
コード例 #4
0
        /// <summary>
        /// Register a shortcode that is defined in the data store.
        /// The definition of a dynamic shortcode can be changed at runtime.
        /// </summary>
        /// <param name="name"></param>
        /// <param name="shortcodeFactoryMethod"></param>
        public void RegisterShortcode(DynamicShortcodeDefinition shortcodeDefinition)
        {
            if (shortcodeDefinition == null)
            {
                throw new Exception("Shortcode definition is required.");
            }

            if (shortcodeDefinition.ElementType == LavaShortcodeTypeSpecifier.Inline)
            {
                // Create a new factory method that returns an initialized Shortcode Tag element.
                Func <string, ILavaTag> tagFactoryMethod = (tagName) =>
                {
                    // Call the factory method we have been passed to retrieve the definition of the shortcode.
                    // The definition may change at runtime, so we need to execute the factory method every time we create a new shortcode instance.
                    var shortCodeName = LavaUtilityHelper.GetShortcodeNameFromLiquidElementName(tagName);

                    var shortcodeInstance = new DynamicShortcodeTag();

                    shortcodeInstance.Initialize(shortcodeDefinition, this);

                    return(shortcodeInstance);
                };

                // Register the shortcode as a custom tag, but use a decorated registration name that will not collide with a regular element name.
                var registrationKey = LavaUtilityHelper.GetLiquidElementNameFromShortcodeName(shortcodeDefinition.Name);

                RegisterTag(registrationKey, tagFactoryMethod);
            }
            else
            {
                // Create a new factory method that returns an initialized Shortcode Block element.
                Func <string, ILavaBlock> blockFactoryMethod = (blockName) =>
                {
                    // Call the factory method we have been passed to retrieve the definition of the shortcode.
                    // The definition may change at runtime, so we need to execute the factory method for each new shortcode instance.
                    var shortCodeName = LavaUtilityHelper.GetShortcodeNameFromLiquidElementName(blockName);

                    var shortcodeInstance = new DynamicShortcodeBlock(shortcodeDefinition, this);

                    return(shortcodeInstance);
                };

                // Register the shortcode as a custom block, but use a decorated registration name that will not collide with a regular element name.
                var registrationKey = LavaUtilityHelper.GetLiquidElementNameFromShortcodeName(shortcodeDefinition.Name);

                RegisterBlock(registrationKey, blockFactoryMethod);
            }
        }
コード例 #5
0
        public DynamicShortcode(DynamicShortcodeDefinition definition, ILavaEngine engine)
        {
            Initialize(definition, engine);

            AssertShortcodeIsInitialized();
        }