コード例 #1
0
        private string MethodsGroup_Description(DocumentorContext context, params object[] parameters)
        {
            MethodInfo     restMethod = parameters[0] as MethodInfo;
            OrderAttribute attr       = restMethod.GetRadishAttribute <OrderAttribute>();
            MethodGroup    group      = context.MethodGroups[attr.GroupKey];

            return(group.Description);
        }
コード例 #2
0
ファイル: Documentor.cs プロジェクト: kevinheader/Radish-2
        /// <summary>
        /// Creates documentation content.
        /// </summary>
        /// <returns>
        /// HTML documentation content as string.
        /// </returns>
        private string CreateDocumentation()
        {
            if (TemplateSet == null)
            {
                TemplateSet = new SimpleTemplateSet();
            }

            // take all REST methods marked with [Method] attibute
            RestMethods =
                RestApiAssemblies
                .Distinct()
                .SelectMany(a => a.GetTypes())
                .SelectMany(c => c.GetMethods()
                            .Where(m => m.IsDefined(typeof(MethodAttribute), false)));

            // methods count
            int methodsCount = RestMethods.Count();

            // order methods according to groups order and methods order in each group
            RestMethods = RestMethods.OrderBy(m =>
            {
                // get method group info from attribute
                OrderAttribute attrGroup = m.GetRadishAttribute <OrderAttribute>();

                // if group is not defined for the method, assume the method has default order "0"
                if (attrGroup == null)
                {
                    return(0);
                }

                // if group is not defined in groups list
                if (attrGroup.GroupKey != null && !MethodGroups.ContainsKey(attrGroup.GroupKey))
                {
                    string fullMethodName = string.Format("{0}.{1}()", m.ReflectedType.Name, m.Name);
                    throw new Exception(String.Format("Group with key \"{0}\" was specified for the method \"{1}\", but group with this key was not added to the Documentor. Use AddMethodGroup(\"{0}\", ...) to set it.", attrGroup.GroupKey, fullMethodName));
                }

                // if default group (group key is null or empty)
                if (String.IsNullOrEmpty(attrGroup.GroupKey))
                {
                    return(attrGroup.MethodOrder);
                }
                // group was defined
                else
                {
                    return((int)(MethodGroups[attrGroup.GroupKey].GroupOrder * methodsCount) + attrGroup.MethodOrder);
                }
            });

            // initiate rendering documentation with Page template
            return(TemplateSet.RenderTemplate <AbstractTemplateSet>(mContext, ts => ts.Page));
        }
コード例 #3
0
        private string Page_MethodsList(DocumentorContext context, params object[] parameters)
        {
            StringBuilder sbMethods      = new StringBuilder();
            string        latestGroupKey = null;

            foreach (MethodInfo method in context.RestMethods)
            {
                OrderAttribute attrOrder = method.GetRadishAttribute <OrderAttribute>();
                if (attrOrder != null)
                {
                    if (!String.IsNullOrEmpty(attrOrder.GroupKey) && latestGroupKey != attrOrder.GroupKey)
                    {
                        sbMethods.Append(context.RenderTemplate <BasicTemplateSet>(ts => ts.MethodsGroup, method));
                    }
                    latestGroupKey = attrOrder.GroupKey;
                }
                sbMethods.Append(context.RenderTemplate <BasicTemplateSet>(ts => ts.Method, method));
            }
            return(sbMethods.ToString());
        }