예제 #1
0
        /// <summary>
        /// Create special buttons
        /// </summary>
        /// <typeparam name="T">Generic type to be used. This type must implement IExtendedHtmlString</typeparam>
        /// <param name="html">Current HTML element</param>
        /// <param name="type">Gumby button type</param>
        /// <param name="sizeOrstyle">Gumby button size/style</param>
        /// <returns>A Gumby button styled hyperlink</returns>
        /// <exception cref="GumbyThemeException">Thrown when a valid Gumby framework
        /// theme is not selected</exception>
        public static IExtendedHtmlString AsButton <T>(this T html, EGumbyButton type, params EGumbyButtonStyle[] sizeOrstyle) where T : IExtendedHtmlString
        {
            if (WebExtrasSettings.GumbyTheme == EGumbyTheme.None)
            {
                throw new GumbyThemeException();
            }

            if (!WebExtrasMvcUtil.CanDisplayAsButton(html))
            {
                throw new InvalidUsageException("The AsButton decorator can only be used with Button and Hyperlink extensions");
            }

            List <string> classes = new List <string>
            {
                "btn",
                type.ToString().ToLowerInvariant()
            };

            // if a style was specified then don't add the theme class
            EGumbyButtonStyle[] styles =
            {
                EGumbyButtonStyle.Oval,
                EGumbyButtonStyle.Rounded,
                EGumbyButtonStyle.Squared,
                EGumbyButtonStyle.Pill_Left,
                EGumbyButtonStyle.Pill_Right
            };

            int styleCnt = sizeOrstyle.Where(styles.Contains).Count();

            if (styleCnt == 0)
            {
                classes.Add(WebExtrasSettings.GumbyTheme.ToString().ToLowerInvariant());
            }

            // if no size was specified set as medium
            EGumbyButtonStyle[] sizes =
            {
                EGumbyButtonStyle.XLarge,
                EGumbyButtonStyle.Large,
                EGumbyButtonStyle.Medium,
                EGumbyButtonStyle.Small
            };

            int sizeCnt = sizeOrstyle.Where(sizes.Contains).Count();

            if (sizeCnt == 0)
            {
                classes.Add("medium");
            }

            HtmlComponent div = new HtmlComponent(EHtmlTag.Div);

            div.Attributes["class"] = string.Join(" ", classes
                                                  .Concat(sizeOrstyle.Select(s => s.ToString().ToLowerInvariant().Replace('_', '-'))));

            div.AppendTags.Add(html.Component);

            return(new ExtendedHtmlString(div));
        }
예제 #2
0
        /// <summary>
        ///   Create special buttons
        /// </summary>
        /// <typeparam name="T">Generic type to be used. Can only be either Hyperlink or Button</typeparam>
        /// <param name="html">Current HTML element</param>
        /// <param name="types">Bootstrap button types</param>
        /// <returns>A special button</returns>
        public static T AsButton <T>(this T html, params EBootstrapButton[] types) where T : IExtendedHtmlString
        {
            if (!WebExtrasMvcUtil.CanDisplayAsButton(html))
            {
                throw new InvalidUsageException("The AsButton decorator can only be used with Button and Hyperlink extensions");
            }

            html.Component.CssClasses.Add(string.Join(" ", types.Select(t => t.GetStringValue())));

            return(html);
        }
예제 #3
0
        public void CanDisplayAsButton_Returns_True_For_Button()
        {
            // arrange
            Button btn = new Button(EButton.Regular, string.Empty, string.Empty);

            // act
            bool result = WebExtrasMvcUtil.CanDisplayAsButton(btn);

            // assert
            Assert.IsTrue(result);
        }