public void Add_id()
        {
            var h = new HtmlAttributes(@class => "class1");

            h.Id("anId");

            Assert.That(h.ToHtmlString(), Is.EqualTo(" class=\"class1\" id=\"anId\""));
        }
        public void Add_new_attribute_using_a_lambda()
        {
            var h = new HtmlAttributes(href => "http://url/");

            h.Attr(data_value => "val");

            Assert.That(h.ToHtmlString(), Is.EqualTo(" data-value=\"val\" href=\"http://url/\""));
        }
        public void Add_css_classes()
        {
            var h = new HtmlAttributes(@class => "class1");

            h.AddClass("class2 class3");

            Assert.That(h.ToHtmlString(), Is.EqualTo(" class=\"class2 class3 class1\""));
        }
public static System.Web.WebPages.HelperResult BeginSection(IHtmlString title, IHtmlString leadingHtml, HtmlAttributes htmlAttributes) {
#line default
#line hidden
return new System.Web.WebPages.HelperResult(__razor_helper_writer => {

#line 14 "..\..\Templates\HtmlHelpers.cshtml"
                                                                                                 


#line default
#line hidden
WriteLiteralTo(__razor_helper_writer, "    <fieldset");


#line 15 "..\..\Templates\HtmlHelpers.cshtml"
WriteTo(__razor_helper_writer, htmlAttributes);


#line default
#line hidden
WriteLiteralTo(__razor_helper_writer, ">\r\n");

WriteLiteralTo(__razor_helper_writer, "        <legend>");


#line 16 "..\..\Templates\HtmlHelpers.cshtml"
WriteTo(__razor_helper_writer, title);


#line default
#line hidden
WriteLiteralTo(__razor_helper_writer, "</legend>\r\n");

WriteLiteralTo(__razor_helper_writer, "        ");


#line 17 "..\..\Templates\HtmlHelpers.cshtml"
WriteTo(__razor_helper_writer, leadingHtml);


#line default
#line hidden
WriteLiteralTo(__razor_helper_writer, "\r\n");

WriteLiteralTo(__razor_helper_writer, "        <dl>\r\n");


#line 19 "..\..\Templates\HtmlHelpers.cshtml"


#line default
#line hidden
});

#line 19 "..\..\Templates\HtmlHelpers.cshtml"
}
示例#5
0
 /// <summary>
 /// Creates the HTML for a form tag.
 /// </summary>
 /// <param name="action">The URL the form submits to</param>
 /// <param name="method">The HTTP method the form submits with</param>
 /// <param name="htmlAttributes">Any HTML attributes that should be applied to the form; specified as an anonymous object</param>
 /// <param name="encType">The encoding type the form uses</param>
 /// <returns>The HTML for the form</returns>
 public static IHtmlString BuildFormTag(string action, FormMethod method, HtmlAttributes htmlAttributes = null, EncType? encType = null)
 {
     var tagBuilder = new TagBuilder("form");
     if (htmlAttributes != null)
         tagBuilder.MergeAttributes(htmlAttributes.Attributes);
     tagBuilder.MergeAttribute("action", action);
     tagBuilder.MergeAttribute("method", HtmlHelper.GetFormMethodString(method), true);
     if (encType.HasValue)
     {
         tagBuilder.MergeAttribute("enctype", encType.Humanize());
     }
     return new HtmlString(tagBuilder.ToString(TagRenderMode.StartTag));
 }
        /// <summary>
        /// Creates the HTML for a single checkbox.
        /// </summary>
        /// <param name="name">The name/id for the checkbox</param>
        /// <param name="isChecked">Whether or not the checkbox is currently checked</param>
        /// <param name="htmlAttributes">Any HTML attributes that should be applied to the checkbox</param>
        /// <param name="value">The value to submit when the checkbox is ticked</param>
        /// <returns>The HTML for the checkbox</returns>
        public static IHtmlString BuildSingleCheckbox(string name, bool isChecked, HtmlAttributes htmlAttributes, string value = "true")
        {
            var t = new TagBuilder("input");
            t.Attributes.Add("value", value);
            t.Attributes.Add("type", "checkbox");
            if (value == "true")
                t.GenerateId(name);
            t.Attributes.Add("name", name);
            if (isChecked)
                t.Attributes.Add("checked", "checked");
            if (htmlAttributes != null)
                t.MergeAttributes(htmlAttributes.Attributes, false);

            return new HtmlString(t.ToString(TagRenderMode.SelfClosing));
        }
示例#7
0
        /// <summary>
        /// Creates the HTML for a submit &lt;button&gt;.
        /// </summary>
        /// <param name="content">The content to display for the button</param>
        /// <param name="type">The type of submit button; submit (default) or reset</param>
        /// <param name="value">The value to submit with the button</param>
        /// <param name="id">The id/name to use for the button</param>
        /// <param name="htmlAttributes">Any HTML attributes that should be applied to the button</param>
        /// <returns>The HTML for the submit button</returns>
        public static IHtmlString BuildButton(IHtmlString content, string type = null, string id = null, string value = null, HtmlAttributes htmlAttributes = null)
        {
            var t = new TagBuilder("button") {InnerHtml = content.ToHtmlString()};
            if (value != null)
                t.Attributes.Add("value", value);
            if (type != null)
                t.Attributes.Add("type", type);
            if (id != null)
            {
                t.Attributes.Add("id", id);
                t.Attributes.Add("name", id);
            }
            if (htmlAttributes != null)
                t.MergeAttributes(htmlAttributes.Attributes, true);

            return new HtmlString(t.ToString(TagRenderMode.Normal));
        }
        public void Construct_via_lambdas()
        {
            var h = new HtmlAttributes(style => "width: 100%;", cellpadding => 0, @class => "class1 class2", src => "http://url/", data_somedata => "\"rubbi&h\"");

            Assert.That(h.ToHtmlString(), Is.EqualTo(ExpectedHtml));
        }
        public void Replace_and_add_attributes_using_dictionary()
        {
            var h = new HtmlAttributes(data_existing => "old");

            h.Attrs(new Dictionary<string, object> {{"data-existing", "new"}, {"data-new", "newnew"}});

            Assert.That(h.ToHtmlString(), Is.EqualTo(" data-existing=\"new\" data-new=\"newnew\""));
        }
示例#10
0
 public virtual IHtmlString BeginSection(IHtmlString title, IHtmlString leadingHtml, HtmlAttributes htmlAttributes)
 {
     return HtmlHelpers.BeginSection(title, leadingHtml, htmlAttributes);
 }
        public void Construct_via_dictionary()
        {
            var h = new HtmlAttributes(Dictionary);

            Assert.That(h.ToHtmlString(), Is.EqualTo(ExpectedHtml));
        }
        public void Ensure_merged_attributes_are_case_sensitive([Values(1,2,3)] int setMethod)
        {
            var h = new HtmlAttributes(name => "Old");

            switch (setMethod)
            {
                case 1:
                    h.Attr(Name => "honey-badger");
                    break;
                case 2:
                    h.Attr("Name", "honey-badger");
                    break;
                case 3:
                    h.Attrs(new {Name = "honey-badger"});
                    break;
            }

            Assert.That(h.ToHtmlString(), Is.EqualTo(" name=\"honey-badger\""));
        }
示例#13
0
 /// <summary>
 /// Creates the HTML for a submit &lt;button&gt;.
 /// </summary>
 /// <param name="text">The text to display for the button</param>
 /// <param name="type">The type of submit button; submit (default) or reset</param>
 /// <param name="value">The value to submit with the button</param>
 /// <param name="id">The id/name to use for the button</param>
 /// <param name="htmlAttributes">Any HTML attributes that should be applied to the button</param>
 /// <returns>The HTML for the submit button</returns>
 public static IHtmlString BuildButton(string text, string type = null, string id = null, string value = null, HtmlAttributes htmlAttributes = null)
 {
     return BuildButton(new HtmlString(HttpUtility.HtmlEncode(text)), type, id, value, htmlAttributes);
 }
示例#14
0
        /// <summary>
        /// Creates the HTML for a label.
        /// </summary>
        /// <param name="for">The name/id for the checkbox</param>
        /// <param name="labelText">The text inside the label</param>
        /// <param name="htmlAttributes">Any HTML attributes that should be applied to the checkbox</param>
        /// <returns>The HTML for the checkbox</returns>
        public static IHtmlString BuildLabel(string @for, IHtmlString labelText, HtmlAttributes htmlAttributes)
        {
            var t = new TagBuilder("label");
            t.Attributes.Add("for", TagBuilder.CreateSanitizedId(@for));
            t.InnerHtml = labelText.ToHtmlString();

            if (htmlAttributes != null)
                t.MergeAttributes(htmlAttributes.Attributes, false);

            return new HtmlString(t.ToString(TagRenderMode.Normal));
        }
 /// <summary>
 /// Creates the HTML for a submit &lt;button&gt;.
 /// </summary>
 /// <param name="text">The text to display for the button</param>
 /// <param name="type">The type of submit button; submit (default) or reset</param>
 /// <param name="value">The value to submit with the button</param>
 /// <param name="id">The id/name to use for the button</param>
 /// <param name="htmlAttributes">Any HTML attributes that should be applied to the button</param>
 /// <returns>The HTML for the submit button</returns>
 public static IHtmlString BuildButton(string text, string type = null, string id = null, string value = null, HtmlAttributes htmlAttributes = null)
 {
     return BuildButton(text.ToHtml(), type, id, value, htmlAttributes);
 }
示例#16
0
        /// <summary>
        /// Creates the HTML for a select.
        /// </summary>
        /// <param name="name">The name/id of the select</param>
        /// <param name="selectListItems">The items for the select list</param>
        /// <param name="multiple">Whether or not multiple items can be selected</param>
        /// <param name="htmlAttributes">Any HTML attributes that should be applied to the select</param>
        /// <returns>The HTML for the select</returns>
        public static IHtmlString BuildSelect(string name, IEnumerable<SelectListItem> selectListItems, bool multiple, HtmlAttributes htmlAttributes)
        {
            var t = new TagBuilder("select");
            if (name != null)
            {
                t.Attributes.Add("name", name);
                t.GenerateId(name);
            }
            if (htmlAttributes != null)
                t.MergeAttributes(htmlAttributes.Attributes, true);
            if (multiple)
                t.Attributes.Add("multiple", "multiple");

            foreach (var item in selectListItems)
            {
                var option = new TagBuilder("option");
                if (item.Selected)
                    option.Attributes.Add("selected", "selected");
                option.Attributes.Add("value", item.Value);
                option.SetInnerText(item.Text);
                t.InnerHtml += option.ToString();
            }

            return new HtmlString(t.ToString());
        }
        public void Replace_and_add_attributes_using_anonymous_object()
        {
            var h = new HtmlAttributes(data_existing => "old");

            h.Attrs(new {data_existing = "new", data_new = "newnew"});

            Assert.That(h.ToHtmlString(), Is.EqualTo(" data-existing=\"new\" data-new=\"newnew\""));
        }
示例#18
0
        /// <summary>
        /// Creates the HTML for an input.
        /// </summary>
        /// <param name="name">The name/id of the input</param>
        /// <param name="value">The value of the input</param>
        /// <param name="type">The type of the input</param>
        /// <param name="htmlAttributes">Any HTML attributes that should be applied to the button</param>
        /// <returns>The HTML for the input</returns>
        public static IHtmlString BuildInput(string name, string value, string type, HtmlAttributes htmlAttributes)
        {
            var t = new TagBuilder("input");
            t.Attributes.Add("name", name);
            t.GenerateId(name);
            t.Attributes.Add("value", value);
            t.Attributes.Add("type", type);
            if (htmlAttributes != null)
                t.MergeAttributes(htmlAttributes.Attributes, true);

            return new HtmlString(t.ToString(TagRenderMode.SelfClosing));
        }
        public void Replace_attributes_with_empty_string_when_null_value_added_using_key_value([Values(1, 2)] int setMethod)
        {
            var h = new HtmlAttributes(name => "Old");

            switch (setMethod)
            {
                case 1:
                    h.Attr(name => null);
                    break;
                case 2:
                    h.Attr("name", null);
                    break;
            }

            Assert.That(h.ToHtmlString(), Is.EqualTo(" name=\"\""));
        }
        public void Make_disabled()
        {
            var h = new HtmlAttributes(@class => "class1");

            h.Disabled();

            Assert.That(h.ToHtmlString(), Is.EqualTo(" class=\"class1\" disabled=\"disabled\""));
        }
        public void Ensure_new_attributes_are_case_sensitive([Values(1, 2, 3)] int constructorOption)
        {
            HtmlAttributes h = null;

            switch (constructorOption)
            {
                case 1:
                    h = new HtmlAttributes(Name => "honey-badger");
                    break;
                case 2:
                    h = new HtmlAttributes(new Dictionary<string, object>{{"Name", "honey-badger"}});
                    break;
                case 3:
                    h = new HtmlAttributes(new { Name = "honey-badger" });
                    break;
            }

            Assert.That(h.ToHtmlString(), Is.EqualTo(" name=\"honey-badger\""));
        }
        public void Add_sanitised_id()
        {
            var h = new HtmlAttributes();

            h.Id("Model.Id");

            Assert.That(h.ToHtmlString(), Is.EqualTo(" id=\"Model_Id\""));
        }
        public void Construct_via_anonymous_object()
        {
            var h = new HtmlAttributes(AnonymousObject);

            Assert.That(h.ToHtmlString(), Is.EqualTo(ExpectedHtml));
        }
        public void Make_readonly()
        {
            var h = new HtmlAttributes(@class => "class1");

            h.Readonly();

            Assert.That(h.ToHtmlString(), Is.EqualTo(" class=\"class1\" readonly=\"readonly\""));
        }
        public void Not_make_disabled_when_guard_is_false()
        {
            var h = new HtmlAttributes(@class => "class1");

            h.Disabled(false);

            Assert.That(h.ToHtmlString(), Is.EqualTo(" class=\"class1\""));
        }
public static System.Web.WebPages.HelperResult BeginNestedSection(IHtmlString title, IHtmlString leadingHtml, HtmlAttributes htmlAttributes)
{
#line default
#line hidden
return new System.Web.WebPages.HelperResult(__razor_helper_writer => {

#line 22 "..\..\Templates\HtmlHelpers.cshtml"
 


#line default
#line hidden
WriteLiteralTo(__razor_helper_writer, "            <dt>");


#line 23 "..\..\Templates\HtmlHelpers.cshtml"
WriteTo(__razor_helper_writer, title);


#line default
#line hidden
WriteLiteralTo(__razor_helper_writer, "</dt>\r\n");

WriteLiteralTo(__razor_helper_writer, "            <dd>\r\n");

WriteLiteralTo(__razor_helper_writer, "                ");


#line 25 "..\..\Templates\HtmlHelpers.cshtml"
WriteTo(__razor_helper_writer, leadingHtml);


#line default
#line hidden
WriteLiteralTo(__razor_helper_writer, "\r\n");

WriteLiteralTo(__razor_helper_writer, "                <dl");


#line 26 "..\..\Templates\HtmlHelpers.cshtml"
WriteTo(__razor_helper_writer, htmlAttributes);


#line default
#line hidden
WriteLiteralTo(__razor_helper_writer, ">\r\n");


#line 27 "..\..\Templates\HtmlHelpers.cshtml"


#line default
#line hidden
});

#line 27 "..\..\Templates\HtmlHelpers.cshtml"
}
 private HtmlAttributes ReturnAsHtmlAttributes(HtmlAttributes attrs)
 {
     return attrs;
 }
        public void Replace_existing_attribute_using_a_lambda()
        {
            var h = new HtmlAttributes(href => "http://url/");

            h.Attr(href => "newhref");

            Assert.That(h.ToHtmlString(), Is.EqualTo(" href=\"newhref\""));
        }
示例#29
0
 /// <summary>
 /// Constructs a field configuration.
 /// </summary>
 public FieldConfiguration()
 {
     Attributes = new HtmlAttributes();
     DisplayType = FieldDisplayType.Default;
     TrueString = "Yes";
     FalseString = "No";
     NoneString = "";
     Bag = new ExpandoObject();
 }
        public void Replace_and_add_attributes_using_lambdas()
        {
            var h = new HtmlAttributes(data_existing => "old");

            h.Attrs(data_existing => "new", data_new => "newnew");

            Assert.That(h.ToHtmlString(), Is.EqualTo(" data-existing=\"new\" data-new=\"newnew\""));
        }