Ejemplo n.º 1
0
        public static HtmlString WrapedInLabel(this HtmlHelper helper, MvcHtmlString @object, object labelAttribtues = null, object wrappedObjectAttribtues = null)
        {
            StringBuilder sb = new StringBuilder();
            StringBuilder wrappedObjectSb = new StringBuilder();
            Match match = Regex.Match(@object.ToHtmlString(), @"id=""(?<ID>\w+)""");
            if (match.Success)
            {
                sb.AppendFormat("<label ");
                if (labelAttribtues != null)
                {
                    PropertyInfo[] propertyInfos = labelAttribtues.GetType().GetProperties();
                    foreach (PropertyInfo propertyInfo in propertyInfos)
                    {
                        sb.AppendFormat(@"{0}=""{1}"">", propertyInfo.Name, propertyInfo.GetValue(labelAttribtues, null));
                    }
                }
                sb.AppendFormat(@"<strong>{0}</strong>", match.Groups["ID"].Value);

                wrappedObjectSb.Append(@object.ToHtmlString());
                int firstWhiteSpace = @object.ToHtmlString().IndexOf(" ");

                if (wrappedObjectAttribtues != null)
                {
                    PropertyInfo[] propertyInfos = wrappedObjectAttribtues.GetType().GetProperties();
                    foreach (PropertyInfo propertyInfo in propertyInfos)
                    {
                        wrappedObjectSb.Insert(firstWhiteSpace,String.Format(@" {0}=""{1}"" ", propertyInfo.Name, propertyInfo.GetValue(wrappedObjectAttribtues, null)));
                    }
                }

                sb.AppendFormat("{0}", wrappedObjectSb);
                sb.Append("</label>");
            }
            return new HtmlString(sb.ToString());
        }
        public static string DefaultPagingHtml(int option, MvcHtmlString actionLink = null, bool active = false)
        {
            switch (option)
            {
                case PagingOptConst.Wrapper: return @"<ul class=""pagination"">{0}{1}{2}{3}{4}</ul>";
                case PagingOptConst.FirstLastButton: return string.Format(@"<li class=""paging-first-last"">{0}</li>", actionLink.ToHtmlString());
                case PagingOptConst.PrevNextButton: return string.Format(@"<li class=""paging-prev-next"">{0}</li>", actionLink.ToHtmlString());
                case PagingOptConst.NumberButton: return string.Format(@"<li class=""page-number {0}"">{1}</li>", active ? "paging-active" : string.Empty, actionLink.ToHtmlString());
                case PagingOptConst.NoneActionString: return string.Format(@"<li class=""paging-none-action""><a href=""javascript:;"">...</a></li>");
            }

            return string.Empty;
        }
Ejemplo n.º 3
0
        public static MvcHtmlString MenuItem(this HtmlHelper helper, MvcHtmlString link, string controller)
        {
            var li = new TagBuilder("li");
            if (helper.ViewContext.Controller.GetType().Name.ToLower() == String.Format("{0}controller", controller).ToLower())
                li.Attributes.Add("class", "selected");
            li.InnerHtml = link.ToHtmlString();
            return new MvcHtmlString(li.ToString());
                

        }
Ejemplo n.º 4
0
        private static bool resolve(MvcHtmlString content, int characters, out string resolved)
        {
            var stripped = content == null ?
                        string.Empty : content.ToHtmlString().StripHtml();

            if (stripped.Length > characters)
            {
                resolved = stripped.FirstCharacters(characters);
                return true;
            }

            resolved = stripped;
            return false;
        }
Ejemplo n.º 5
0
        public void HtmlHelperExtensionsImageAbsoultePathAndClassTest()
        {
            // Przekazany url
            const string Url = "test.com/someimg.jpg";

            // Oczekiwany tag html
            var expected =
                new MvcHtmlString(
                    "<img alt=\"" + AlternateText + "\" class=\"" + Class + "\" id=\"" + Id + "\" src=\"" + Url
                    + "\" />");

            // stworzenie instancji HtmlHelper
            var htmlHelper = new HtmlHelper(new ViewContext(), Substitute.For<IViewDataContainer>());

            // Wykonanie helpera Image
            var tag = htmlHelper.Image(Id, Url, AlternateText, new { @class = Class });

            // Sprawdzenie
            Assert.IsInstanceOfType(tag, typeof(MvcHtmlString));
            Assert.AreEqual(expected.ToHtmlString(), tag.ToHtmlString());
        }
Ejemplo n.º 6
0
        private static string getIdFromString(MvcHtmlString html)
        {
            string raw = html.ToHtmlString();
            if (raw.IndexOf("id=") == -1)
                throw new ArgumentException("MVC.Controls.DatePicker can only be used for MvcHtmlString with an html-id"
                    + Environment.NewLine + "[" + html.ToHtmlString() + "]");

            raw = raw.Substring(raw.IndexOf("id=") + 4);
            raw = raw.Substring(0, raw.IndexOf("\""));

            return raw;
        }
Ejemplo n.º 7
0
 public static MvcHtmlString ResponsiveTd(this HtmlHelper html, string label, MvcHtmlString content)
 {
     return new MvcHtmlString(string.Format(@"<td data-label=""{0}"">{1}</td>", label, content.ToHtmlString()));
 }
Ejemplo n.º 8
0
 public static MvcHtmlString EmbeddedTemplate(EntityBase entityBase, MvcHtmlString template, string defaultString)
 {
     return MvcHtmlString.Create("<script type=\"template\" id=\"{0}\" data-toString=\"{2}\">{1}</script>".Formato(
                         entityBase.Compose(EntityBaseKeys.Template),
                         regex.Replace(template.ToHtmlString(), m => m.Value + "X"),
                         defaultString));
 }
Ejemplo n.º 9
0
 public void AddLine(MvcHtmlString html)
 {
     if (!MvcHtmlString.IsNullOrEmpty(html))
         sb.AppendLine(html.ToHtmlString());
 }
Ejemplo n.º 10
0
        public static MvcHtmlString Concat(this MvcHtmlString one, MvcHtmlString other)
        {
            if (MvcHtmlString.IsNullOrEmpty(one))
                return other;

            if (MvcHtmlString.IsNullOrEmpty(other))
                return one;

            return MvcHtmlString.Create(one.ToHtmlString() + other.ToHtmlString());
        }
Ejemplo n.º 11
0
        public HtmlTag InnerHtml(MvcHtmlString html)
        {
            if (MvcHtmlString.IsNullOrEmpty(html))
                tagBuilder.InnerHtml = null;
            else
                tagBuilder.InnerHtml = html.ToHtmlString();

            return this;
        }
Ejemplo n.º 12
0
        public void HtmlHelperExtensionsImageRelativePathTest()
        {
            // Przekazany url
            const string Url = "~/someimg.jpg";

            // Oczekiwany url
            const string ExpectedUrl = "/app/someimg.jpg";

            // Oczekiwany tag html
            var expected =
                new MvcHtmlString("<img alt=\"" + AlternateText + "\" id=\"" + Id + "\" src=\"" + ExpectedUrl + "\" />");

            // stworzenie instancji HtmlHelper
            var htmlHelper = new HtmlHelper(new ViewContext(), Substitute.For<IViewDataContainer>());

            // Mokowanie HttpContextBase
            var fakeHttpContext = Substitute.ForPartsOf<HttpContextBase>();

            // Ustawienie właściwośći readonly Request
            // ReSharper disable once UnusedVariable
            fakeHttpContext.When(x => { var get = x.Request; }).DoNotCallBase();
            fakeHttpContext.Request.Returns(Substitute.ForPartsOf<HttpRequestBase>());

            // Ustawienie właściwośći readonly ApplicaitonPath
            // ReSharper disable once UnusedVariable
            fakeHttpContext.Request.When(x => { var get = x.ApplicationPath; }).DoNotCallBase();
            fakeHttpContext.Request.ApplicationPath.Returns("/app/");

            // Podststawienie i wykonanie helpera Image
            htmlHelper.ViewContext.HttpContext = fakeHttpContext;
            var tag = htmlHelper.Image(Id, Url, AlternateText);

            // Sprawdzenie
            Assert.IsInstanceOfType(tag, typeof(MvcHtmlString));
            Assert.AreEqual(expected.ToHtmlString(), tag.ToHtmlString());
        }
Ejemplo n.º 13
0
 public static MvcHtmlString GrayButton(this HtmlHelper html, MvcHtmlString content)
 {
     return GrayButton(html, content.ToHtmlString());
 }
Ejemplo n.º 14
0
 public static MvcHtmlString ReplaceNewLines(this HtmlHelper htmlHelper, MvcHtmlString str)
 {
     string pattern = @"\r\n|\n\r|\r|\n";
     string  htmlStr = str.ToHtmlString();
     string result = Regex.Replace(htmlStr, pattern, " ");
     StringBuilder builder = new StringBuilder();
     builder.Append(result);
     return MvcHtmlString.Create(builder.ToString());
 }