Example #1
0
        TemplateElement Macro_Push_FirstCommit(TemplateFragmentMacro fragment)
        {
            string macroName = fragment.MacroName;

            if (!macroName.StartsWith("FirstCommit", StringComparison.Ordinal))
            {
                throw new ArgumentException("Macro name must start with FirstCommit", "fragment");
            }

            string propName = macroName.Substring(12);

            if (String.IsNullOrEmpty(propName))
            {
                throw new InvalidOperationException("A non-empty property name is required.");
            }

            var propref = new TemplateElementPropertyReference <Commit> (propName);

            return(new TemplateElementSynthetic <Push> (GetElementArgumentList(fragment), (Push data, List <TemplateElementArgument> args) =>
            {
                List <Commit> commits = data.Commits;
                if (commits == null || commits.Count == 0)
                {
                    return null;
                }

                Commit first = commits[0];
                return ShortenString(propref.Generate(first), args, -1);
            })
            {
                SkipNewlineIfLineEmpty = true
            });
        }
Example #2
0
        TemplateElement Macro_Push_FirstCommit_MessageSummary(TemplateFragmentMacro fragment)
        {
            string macroName = fragment.MacroName;

            if (String.Compare("FirstCommit.MessageSummary", macroName, StringComparison.Ordinal) != 0)
            {
                throw new ArgumentException("Macro name must be 'FirstCommit.MessageSummary'", "fragment");
            }

            var propref = new TemplateElementPropertyReference <Commit> ("Message");

            return(new TemplateElementSynthetic <Push> (GetElementArgumentList(fragment), (Push data, List <TemplateElementArgument> args) =>
            {
                List <Commit> commits = data.Commits;
                if (commits == null || commits.Count == 0)
                {
                    return null;
                }

                Commit first = commits[0];
                string ret = propref.Generate(first);
                if (String.IsNullOrEmpty(ret))
                {
                    return null;
                }

                return ShortenString(ret, args, 72);
            })
            {
                SkipNewlineIfLineEmpty = true
            });
        }
Example #3
0
        TemplateElement ProcessMacro(TemplateFragmentMacro macro)
        {
            string name = macro.MacroName;

            if (name.StartsWith("this.", StringComparison.Ordinal))
            {
                name = name.Substring(5);
            }

            Func <TemplateFragmentMacro, TemplateElement> processor = GetProcessor(name);

            if (processor != null)
            {
                return(processor(macro));
            }

            int dot = name.IndexOf('.');

            if (dot != -1)
            {
                string nameLead = name.Substring(0, dot);
                processor = GetProcessor(nameLead);
                if (processor != null)
                {
                    return(processor(macro));
                }
            }
            var ret = new TemplateElementPropertyReference <TData> (name);

            if (ret.IsCollection)
            {
                Type tt = typeof(Template <>);
                tt = tt.MakeGenericType(new Type[] { GetCollectionElementType(ret.PropertyType) });
                ITemplate template = Activator.CreateInstance(tt, new object[] { basePath, commitSourceID }) as ITemplate;
                if (!template.Compile())
                {
                    return(null);
                }

                ret.Template = template;
            }

            return(ret);
        }