AutoWikiBrowser.Plugins.Kingbotk.Templating.AddTemplateParmFromExistingTemplate C# (CSharp) Method

AddTemplateParmFromExistingTemplate() private method

Store a parameter from the exploded on-page template into the Parameters collection
private AddTemplateParmFromExistingTemplate ( string parameterName, string parameterValue ) : void
parameterName string
parameterValue string
return void
        internal void AddTemplateParmFromExistingTemplate(string parameterName, string parameterValue)
        {
            // Let's merge duplicates when one or both is empty:
            if (Parameters.ContainsKey(parameterName))
            {
                // This code is very similar to ReplaceTemplateParm(), but that is for programmatic changes (i.e. not
                // from template), needs an Article object, doesn't understand empty new values, and doesn't report
                // bad tags. Turned out to be easier to rewrite here than to modify it.
                if (Parameters[parameterName].Value != parameterValue)
                {
                    // existing value is empty, overwrite with new
                    if (string.IsNullOrEmpty(Parameters[parameterName].Value))
                    {
                        Parameters[parameterName].Value = parameterValue;
                    }
                    else if (!string.IsNullOrEmpty(parameterValue))
                    {
                        BadTemplate = true;
                    }
                }
            }
            else
            {
                Parameters.Add(parameterName, new TemplateParametersObject(parameterValue));
            }
        }

Usage Example

Beispiel #1
0
        protected string MatchEvaluator(Match match)
        {
            if (match.Groups["parm"].Captures.Count != match.Groups["val"].Captures.Count)
            {
                Template.BadTemplate = true;
            }
            else
            {
                Template.FoundTemplate = true;
                TheArticle.PluginCheckTemplateCall(match.Groups["tl"].Value, PluginShortName);

                if (HasAlternateNames)
                {
                    PluginCheckTemplateName(match.Groups["tlname"].Value);
                }
                //.Trim)

                if (match.Groups["parm"].Captures.Count > 0)
                {
                    for (int i = 0; i <= match.Groups["parm"].Captures.Count - 1; i++)
                    {
                        string value = match.Groups["val"].Captures[i].Value;
                        string parm  = match.Groups["parm"].Captures[i].Value;

                        Template.AddTemplateParmFromExistingTemplate(parm, value);
                    }
                }
            }

            return(Constants.TemplaterPlaceholder);
        }