Ejemplo n.º 1
0
        public void Init(MarkdownPage markdownPage, Dictionary<string, object> scopeArgs,
            bool renderHtml, ViewDataDictionary viewData, HtmlHelper htmlHelper)
		{
            Init(null, null, markdownPage.Markdown, viewData, htmlHelper);

            this.RenderHtml = renderHtml;
			this.MarkdownPage = markdownPage;
			this.ScopeArgs = scopeArgs;
		}
Ejemplo n.º 2
0
 public static string RenderToHtml(this MarkdownPage markdownPage, Dictionary <string, object> scopeArgs)
 {
     return(RenderToString(markdownPage, scopeArgs, true));
 }
Ejemplo n.º 3
0
 public PageContext(MarkdownPage markdownPage, Dictionary <string, object> scopeArgs, bool renderHtml)
 {
     MarkdownPage = markdownPage;
     ScopeArgs    = scopeArgs ?? new Dictionary <string, object>();
     RenderHtml   = renderHtml;
 }
Ejemplo n.º 4
0
 public PageContext Create(MarkdownPage markdownPage, bool renderHtml)
 {
     return(new PageContext(markdownPage, ScopeArgs, renderHtml));
 }
Ejemplo n.º 5
0
        private void Prepare(MarkdownPage markdownPage)
        {
            var rawMethodExpr = methodExpr.Replace("Html.", "");

            if (rawMethodExpr == "Partial")
            {
                this.DependentPageName = this.Condition.ExtractContents("\"", "\"");
            }
            this.WriteRawHtml = rawMethodExpr == "Raw";

            var parts = methodExpr.Split('.');

            if (parts.Length > 2)
            {
                throw new ArgumentException("Unable to resolve method: " + methodExpr);
            }

            var usesBaseType     = parts.Length == 1;
            var typePropertyName = parts[0];
            var methodName       = usesBaseType ? parts[0] : parts[1];

            Type type = null;

            if (typePropertyName == "Html")
            {
                type = markdownPage.ExecutionContext.BaseType.HasGenericType()
                                           ? typeof(HtmlHelper <>)
                                           : typeof(HtmlHelper);
            }
            if (type == null)
            {
                type = usesBaseType
                                        ? markdownPage.ExecutionContext.BaseType
                                        : markdownPage.Markdown.MarkdownGlobalHelpers.TryGetValue(typePropertyName, out type) ? type : null;
            }

            if (type == null)
            {
                throw new InvalidDataException(string.Format(
                                                   "Unable to resolve type '{0}'. Check type exists in Config.MarkdownBaseType or Page.Markdown.MarkdownGlobalHelpers",
                                                   typePropertyName));
            }

            try
            {
                var mi = methodName == "Partial"
                    ? type.GetMethods(BindingFlags.Public | BindingFlags.Instance)
                         .FirstOrDefault(m => m.GetParameters().Length == 2 && m.Name == methodName)
                    : type.GetMethod(methodName, BindingFlags.Public | BindingFlags.Instance);

                if (mi == null)
                {
                    mi = HtmlHelper.GetMethod(methodName);
                    if (mi == null)
                    {
                        throw new ArgumentException("Unable to resolve method '" + methodExpr + "' on type " + type.Name);
                    }
                }

                base.ReturnType = mi.ReturnType;
            }
            catch (Exception ex)
            {
                throw;
            }

            var isMemberExpr = Condition.IndexOf('(') != -1;

            if (!isMemberExpr || this.WriteRawHtml)
            {
                base.Condition = methodExpr + "(" + Condition + ")";
            }
        }