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 void Add_new_attribute()
        {
            var h = new HtmlAttributes(href => "http://url/");

            h.Attr("data-value", "val");

            Assert.That(h.ToHtmlString(), Is.EqualTo(" data-value=\"val\" href=\"http://url/\""));
        }
 /// <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 Nancy.ViewEngines.Razor.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", method.GetFormMethodString(), true);
     if (encType.HasValue)
     {
         tagBuilder.MergeAttribute("enctype", encType.Humanize());
     }
     return new NonEncodedHtmlString(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 Nancy.ViewEngines.Razor.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 NonEncodedHtmlString(t.ToString(TagRenderMode.SelfClosing));
        }
        /// <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 Nancy.ViewEngines.Razor.IHtmlString BuildButton(Nancy.ViewEngines.Razor.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 NonEncodedHtmlString(t.ToString(TagRenderMode.Normal));
        }
Esempio n. 6
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 Nancy.ViewEngines.Razor.IHtmlString BuildButton(Nancy.ViewEngines.Razor.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 NonEncodedHtmlString(t.ToString(TagRenderMode.Normal)));
        }
Esempio n. 7
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 Nancy.ViewEngines.Razor.IHtmlString BuildButton(string text, string type = null, string id = null, string value = null, HtmlAttributes htmlAttributes = null)
 {
     return(BuildButton(new NonEncodedHtmlString(HttpUtility.HtmlEncode(text)), type, id, value, htmlAttributes));
 }
Esempio n. 8
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 Nancy.ViewEngines.Razor.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", method.GetFormMethodString(), true);
            if (encType.HasValue)
            {
                tagBuilder.MergeAttribute("enctype", encType.Humanize());
            }
            return(new NonEncodedHtmlString(tagBuilder.ToString(TagRenderMode.StartTag)));
        }
Esempio n. 9
0
 public virtual Nancy.ViewEngines.Razor.IHtmlString BeginNestedSection(Nancy.ViewEngines.Razor.IHtmlString title, Nancy.ViewEngines.Razor.IHtmlString leadingHtml, HtmlAttributes htmlAttributes)
 {
     return(HtmlHelpers.BeginNestedSection(title, leadingHtml, htmlAttributes));
 }
        public static Nancy.ViewEngines.Razor.HelperResult BeginNestedSection(Nancy.ViewEngines.Razor.IHtmlString title, Nancy.ViewEngines.Razor.IHtmlString leadingHtml, HtmlAttributes htmlAttributes)
        {
#line default
#line hidden
            return(new Nancy.ViewEngines.Razor.HelperResult(__razor_helper_writer => {
#line 23 "..\..\Templates\HtmlHelpers.cshtml"



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


#line 24 "..\..\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 26 "..\..\Templates\HtmlHelpers.cshtml"
                WriteTo(__razor_helper_writer, leadingHtml);


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

                WriteLiteralTo(__razor_helper_writer, "                <dl");


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


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


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


#line default
#line hidden
            }));

#line 28 "..\..\Templates\HtmlHelpers.cshtml"
        }
        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\""));
        }
        /// <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 Nancy.ViewEngines.Razor.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 NonEncodedHtmlString(t.ToString(TagRenderMode.SelfClosing));
        }
        public static Nancy.ViewEngines.Razor.HelperResult BeginNestedSection(Nancy.ViewEngines.Razor.IHtmlString title, Nancy.ViewEngines.Razor.IHtmlString leadingHtml, HtmlAttributes htmlAttributes) {
#line default
#line hidden
            return new Nancy.ViewEngines.Razor.HelperResult(__razor_helper_writer => {

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



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


#line 24 "..\..\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 26 "..\..\Templates\HtmlHelpers.cshtml"
                WriteTo(__razor_helper_writer, leadingHtml);


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

                WriteLiteralTo(__razor_helper_writer, "                <dl");


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


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


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


#line default
#line hidden
            });

#line 28 "..\..\Templates\HtmlHelpers.cshtml"
        }
        public static Nancy.ViewEngines.Razor.HelperResult BeginSection(Nancy.ViewEngines.Razor.IHtmlString title, Nancy.ViewEngines.Razor.IHtmlString leadingHtml, HtmlAttributes htmlAttributes) {
#line default
#line hidden
            return new Nancy.ViewEngines.Razor.HelperResult(__razor_helper_writer => {

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



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


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


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

                WriteLiteralTo(__razor_helper_writer, "        <legend>");


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


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

                WriteLiteralTo(__razor_helper_writer, "        ");


#line 18 "..\..\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 20 "..\..\Templates\HtmlHelpers.cshtml"


#line default
#line hidden
            });

#line 20 "..\..\Templates\HtmlHelpers.cshtml"
        }
        public void Construct_via_anonymous_object()
        {
            var h = new HtmlAttributes(AnonymousObject);

            Assert.That(h.ToHtmlString(), Is.EqualTo(ExpectedHtml));
        }
        public void Construct_via_dictionary()
        {
            var h = new HtmlAttributes(Dictionary);

            Assert.That(h.ToHtmlString(), Is.EqualTo(ExpectedHtml));
        }
        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_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\""));
        }
Esempio n. 19
0
        /// <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 Nancy.ViewEngines.Razor.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 NonEncodedHtmlString(t.ToString(TagRenderMode.SelfClosing)));
        }
 /// <summary>
 /// Constructs a field configuration.
 /// </summary>
 public FieldConfiguration()
 {
     Attributes = new HtmlAttributes();
     DisplayType = FieldDisplayType.Default;
     TrueString = "Yes";
     FalseString = "No";
     NoneString = "";
     HasLabel = true;
     Bag = new ExpandoObject();
 }
 public virtual Nancy.ViewEngines.Razor.IHtmlString BeginForm(string action, FormMethod method, HtmlAttributes htmlAttributes, EncType? enctype)
 {
     return HtmlCreator.BuildFormTag(action, method, htmlAttributes, enctype);
 }
        /// <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 Nancy.ViewEngines.Razor.IHtmlString BuildLabel(string @for,  Nancy.ViewEngines.Razor.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 NonEncodedHtmlString(t.ToString(TagRenderMode.Normal));
        }
        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\""));
        }
 /// <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 Nancy.ViewEngines.Razor.IHtmlString BuildButton(string text, string type = null, string id = null, string value = null, HtmlAttributes htmlAttributes = null)
 {
     return BuildButton(new NonEncodedHtmlString(HttpUtility.HtmlEncode(text)), type, id, value, htmlAttributes);
 }
 private HtmlAttributes ReturnAsHtmlAttributes(HtmlAttributes attrs)
 {
     return attrs;
 }
        public void Replace_existing_attribute()
        {
            var h = new HtmlAttributes(href => "http://url/");

            h.Attr("href", "newhref");

            Assert.That(h.ToHtmlString(), Is.EqualTo(" href=\"newhref\""));
        }
Esempio n. 27
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 Nancy.ViewEngines.Razor.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 NonEncodedHtmlString(t.ToString(TagRenderMode.SelfClosing)));
        }
 public virtual Nancy.ViewEngines.Razor.IHtmlString BeginNestedSection(Nancy.ViewEngines.Razor.IHtmlString title,   Nancy.ViewEngines.Razor.IHtmlString leadingHtml, HtmlAttributes htmlAttributes)
 {
     return HtmlHelpers.BeginNestedSection(title, leadingHtml, htmlAttributes);
 }
Esempio n. 29
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 Nancy.ViewEngines.Razor.IHtmlString BuildLabel(string @for, Nancy.ViewEngines.Razor.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 NonEncodedHtmlString(t.ToString(TagRenderMode.Normal)));
        }
        public static Nancy.ViewEngines.Razor.HelperResult BeginSection(Nancy.ViewEngines.Razor.IHtmlString title, Nancy.ViewEngines.Razor.IHtmlString leadingHtml, HtmlAttributes htmlAttributes)
        {
#line default
#line hidden
            return(new Nancy.ViewEngines.Razor.HelperResult(__razor_helper_writer => {
#line 15 "..\..\Templates\HtmlHelpers.cshtml"



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


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


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

                WriteLiteralTo(__razor_helper_writer, "        <legend>");


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


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

                WriteLiteralTo(__razor_helper_writer, "        ");


#line 18 "..\..\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 20 "..\..\Templates\HtmlHelpers.cshtml"


#line default
#line hidden
            }));

#line 20 "..\..\Templates\HtmlHelpers.cshtml"
        }
Esempio n. 31
0
 public virtual Nancy.ViewEngines.Razor.IHtmlString BeginForm(string action, FormMethod method, HtmlAttributes htmlAttributes, EncType?enctype)
 {
     return(HtmlCreator.BuildFormTag(action, method, htmlAttributes, enctype));
 }