Esempio n. 1
0
        public override string ProcessTag(NDjango.Interfaces.IContext context, string content, object[] parms)
        {
            var htmlHelperOption = context.tryfind("Html");

            if (htmlHelperOption == null)
            {
                return("");
            }

            var htmlHelper = (HtmlHelper)htmlHelperOption.Value;

            var string_writer = new StringWriter();
            var writer        = htmlHelper.ViewContext.Writer;

            try
            {
                htmlHelper.ViewContext.Writer = string_writer;
                htmlHelper.RenderPartial(parms[0].ToString());
                string_writer.Flush();
            }
            finally
            {
                htmlHelper.ViewContext.Writer = writer;
            }

            return(string_writer.ToString());
        }
Esempio n. 2
0
        public override string ProcessTag(NDjango.Interfaces.IContext context, string content, object[] parms)
        {
            var htmlHelperOption = context.tryfind("Html");

            if (htmlHelperOption == null)
            {
                return("");
            }

            var htmlHelper = (HtmlHelper)htmlHelperOption.Value;

            var string_writer = new StringWriter();
            var writer        = htmlHelper.ViewContext.Writer;

            try
            {
                htmlHelper.ViewContext.Writer = string_writer;
                var form = htmlHelper.BeginForm();
                string_writer.Flush();
                var start = string_writer.ToString();

                string_writer = new StringWriter();
                htmlHelper.ViewContext.Writer = string_writer;
                form.EndForm();
                string_writer.Flush();
                var end = string_writer.ToString();

                return(start + content + end);
            }
            finally
            {
                htmlHelper.ViewContext.Writer = writer;
            }
        }
Esempio n. 3
0
        /// <summary>
        /// Processes the tag.
        /// </summary>
        /// <param name="content">The content.</param>
        /// <param name="parms">The parms.</param>
        /// <returns></returns>
        public override string ProcessTag(NDjango.Interfaces.IContext context, string content, object[] parms)
        {
            IValidator v = null;

            foreach (string ns in parms)
            {
                v =
                    v == null?
                    ValidationRepository.Instance.GetValidatorForNamespace(ns) :
                        v.Merge(ValidationRepository.Instance.GetValidatorForNamespace(ns));
            }

            if (v == null)
            {
                throw new ArgumentException("Provided namespaces aren't valid", parms.Aggregate("[", (s, e) => s + e + ";") + "]");
            }

            return
                (new StringBuilder()
                 .AppendLine("\r\n<script type=\"text/javascript\">")
                 .AppendLine("if (validation == undefined) var validation = new Array();")
                 .AppendLine(JSEmitter.Instance.Emit(v, "validation[\"" + v.Name + "\"]"))
                 .AppendLine("</script>")
                 .ToString());
        }
Esempio n. 4
0
        public override string ProcessTag(NDjango.Interfaces.IContext context, string content, object[] parms)
        {
            var htmlHelperOption = context.tryfind("Html");

            if (htmlHelperOption == null)
            {
                return("");
            }

            var htmlHelper = (HtmlHelper)htmlHelperOption.Value;

            var metadata_provider = new DataAnnotationsModelMetadataProvider();

            if (context.ModelType == null)
            {
                htmlHelper.ViewData.ModelMetadata = null;
            }
            else
            {
                var model = Activator.CreateInstance(context.ModelType.Value);
                htmlHelper.ViewData.ModelMetadata = metadata_provider.GetMetadataForType(() => model, context.ModelType.Value);
            }

            var result = htmlHelper.Label(parms[0].ToString());

            if (result == null)
            {
                return("");
            }
            else
            {
                return(result.ToHtmlString());
            }
        }
Esempio n. 5
0
            public override string ProcessTag(NDjango.Interfaces.IContext context, string contents, object[] parms)
            {
                StringBuilder res = new StringBuilder();

                foreach (object o in parms)
                {
                    res.Append(o);
                }

                return(res
                       .Append(contents)
                       .ToString());
            }
Esempio n. 6
0
        public override string GenerateUrl(string pathTemplate, string[] parameters, NDjango.Interfaces.IContext context)
        {
            var htmlHelperOption = context.tryfind("Html");

            if (htmlHelperOption == null)
            {
                return("");
            }

            var htmlHelper = (HtmlHelper)htmlHelperOption.Value;
            var anchor     = LinkExtensions.ActionLink(htmlHelper, pathTemplate, pathTemplate, parameters[0]).ToHtmlString();

            //retriving relativePath from anchor element.
            var startindex = anchor.IndexOf("href") + 6; var endIndex = anchor.IndexOf("\"", startindex);

            return(anchor.Substring(startindex, endIndex - startindex));
        }
Esempio n. 7
0
        public override string GenerateUrl(string pathTemplate, string[] parameters, NDjango.Interfaces.IContext context)
        {
            var contextOption = context.tryfind(NDjangoView.aspmvcContextKey);

            if (contextOption == null || contextOption.Value == null)
            {
                throw new ApplicationException("Unable to locate asp mvc request context. Did someone modify djangocontext." + NDjangoView.aspmvcContextKey + "?");
            }

            RequestContext requestContext = contextOption.Value as RequestContext;

            if (parameters.Length > 1)
            {
                throw new ApplicationException("Only 0 or 1 parameters are supported by the asp.mvc version of the URL tag");
            }
            else if (parameters.Length == 1)
            {
                return(new UrlHelper(requestContext).Action(pathTemplate, parameters[0]));
            }
            else
            {
                return(new UrlHelper(requestContext).Action(pathTemplate));
            }
        }
Esempio n. 8
0
 public override string GenerateUrl(string pathTemplate, string[] parameters, NDjango.Interfaces.IContext context)
 {
     return(rootDir + String.Format(pathTemplate.Trim('/'), parameters));
 }
Esempio n. 9
0
 public override string GenerateUrl(string formatString, string[] parameters, NDjango.Interfaces.IContext context)
 {
     return("/appRoot/" + String.Format(formatString.Trim('/'), parameters));
 }