Ejemplo n.º 1
0
        /// <summary>
        /// Merges a css rule.
        /// </summary>
        /// <returns>The rule.</returns>
        /// <param name="curStyle">Target TextStyleParameters</param>
        /// <param name="css">Css value</param>
        /// <param name="clone">If set to <c>true</c> clone the style</param>
        public static TextStyleParameters MergeRule(TextStyleParameters curStyle, string css, bool clone)
        {
            var parser = new CssParser ();
            var rules = parser.ParseAll (css);
            if (rules.Count () != 1) {
                throw new NotSupportedException ("Only a single css class may be merged at a time");
            }

            var mergedStyle = clone ? curStyle.Clone () : curStyle;

            var rule = rules.FirstOrDefault ();
            if (rule != null) {
                ParseCSSRule (ref mergedStyle, rule);
            }

            return mergedStyle;
        }
Ejemplo n.º 2
0
        public ActionResult Index()
        {
            AddJS("TinyColorPicker", "/cbuilderassets/js/corejs/edit-2-tinyColorPicker.js");
            AddJS("ColorPicker", "/cbuilderassets/js/corejs/edit-2-colors.js");
            AddJS("UIComponent", "/admin/js/UIComponents.js");
            AddJS("ThemeSettings", "/admin/js/themesettings.js");
            //AddJS("ColorPicker", "/lib/js/colorpicker.js");
            //AddCSS("ColorPicker", "/lib/css/colorpicker.css");


            string themeCSSPath = System.IO.Path.Combine(_hostingEnvironment.WebRootPath, "admin", "css", "theme.css");
            string cssText      = System.IO.File.ReadAllText(themeCSSPath);

            CssParser            parser = new CssParser();
            List <CssParserRule> rules  = parser.ParseAll(cssText).ToList();

            ThemeManagement themeManagement            = new ThemeManagement();
            List <MainComponentSettings> lstComponents = themeManagement.MapRulesToComponent(rules);

            List <MainComponentSettings> lstOtherComponents = lstComponents.FindAll(x => !x.IsPredefinedThemeSelector);

            List <MainComponentSettings> lstButtonComponents     = lstComponents.FindAll(x => Array.IndexOf(PredefinedCSS.buttonSelectors, x.Rules.FirstOrDefault().Selectors.FirstOrDefault()) > -1);
            List <MainComponentSettings> lstTextColorComponents  = lstComponents.FindAll(x => Array.IndexOf(PredefinedCSS.textColorSelectors, x.Rules.FirstOrDefault().Selectors.FirstOrDefault()) > -1);
            List <MainComponentSettings> lstLinkComponents       = lstComponents.FindAll(x => Array.IndexOf(PredefinedCSS.linkSelectors, x.Rules.FirstOrDefault().Selectors.FirstOrDefault()) > -1);
            List <MainComponentSettings> lstBackgroundComponents = lstComponents.FindAll(x => Array.IndexOf(PredefinedCSS.backgroundSelectors, x.Rules.FirstOrDefault().Selectors.FirstOrDefault()) > -1);
            List <MainComponentSettings> lstPillComponents       = lstComponents.FindAll(x => Array.IndexOf(PredefinedCSS.pillsSelectors, x.Rules.FirstOrDefault().Selectors.FirstOrDefault()) > -1);
            List <MainComponentSettings> lstCapsuleComponents    = lstComponents.FindAll(x => Array.IndexOf(PredefinedCSS.capsuleSelectors, x.Rules.FirstOrDefault().Selectors.FirstOrDefault()) > -1);
            List <MainComponentSettings> lstAlertBoxComponents   = lstComponents.FindAll(x => Array.IndexOf(PredefinedCSS.alertBoxSelectors, x.Rules.FirstOrDefault().Selectors.FirstOrDefault()) > -1);
            List <MainComponentSettings> lstBadgeComponents      = lstComponents.FindAll(x => Array.IndexOf(PredefinedCSS.badgeSelectors, x.Rules.FirstOrDefault().Selectors.FirstOrDefault()) > -1);


            ThemeSettingsViewModel themeSettingsViewModel = new ThemeSettingsViewModel();

            themeSettingsViewModel.OtherComponents      = lstOtherComponents;
            themeSettingsViewModel.ButtonComponents     = lstButtonComponents;
            themeSettingsViewModel.TextColorComponents  = lstTextColorComponents;
            themeSettingsViewModel.LinkComponents       = lstLinkComponents;
            themeSettingsViewModel.BackgroundComponents = lstBackgroundComponents;
            themeSettingsViewModel.PillComponents       = lstPillComponents;
            themeSettingsViewModel.AlertBoxComponents   = lstAlertBoxComponents;
            themeSettingsViewModel.BadgeComponents      = lstBadgeComponents;

            return(View(themeSettingsViewModel));
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Merges a css rule.
        /// </summary>
        /// <returns>The rule.</returns>
        /// <param name="curStyle">Target TextStyleParameters</param>
        /// <param name="css">Css value</param>
        /// <param name="clone">If set to <c>true</c> clone the style</param>
        public static TextStyleParameters MergeRule(TextStyleParameters curStyle, string css, bool clone)
        {
            var parser = new CssParser();
            var rules  = parser.ParseAll(css);

            if (rules.Count() != 1)
            {
                throw new NotSupportedException("Only a single css class may be merged at a time");
            }

            var mergedStyle = clone ? curStyle.Clone() : curStyle;

            var rule = rules.FirstOrDefault();

            if (rule != null)
            {
                ParseCSSRule(ref mergedStyle, rule, null);
            }

            return(mergedStyle);
        }
Ejemplo n.º 4
0
        /// <summary>
        /// Parses the specified CSS
        /// </summary>
        /// <param name="css">Css.</param>
        public static Dictionary<string, TextStyleParameters> Parse(string css)
        {
            var parser = new CssParser ();
            var rules = parser.ParseAll (css);

            var textStyles = new Dictionary<string, TextStyleParameters> ();

            foreach (var rule in rules) {
                foreach (var selector in rule.Selectors) {

                    // If it doesnt exist, create it
                    if (!textStyles.ContainsKey (selector))
                        textStyles [selector] = new TextStyleParameters (selector);

                    var curStyle = textStyles [selector];
                    ParseCSSRule (ref curStyle, rule);
                }

            }

            return textStyles;
        }
Ejemplo n.º 5
0
        static void Main(string[] args)
        {
            Options options = new Options(@"d:\code\csharp\Projects\_sample-files_\connect.css");

            String tmpcss = "";

            try {
                tmpcss = File.ReadAllText(options.CssFileNameFull);
            } catch (FileNotFoundException e) {
                Console.WriteLine(e.Message);
            }

            if (!String.IsNullOrEmpty(tmpcss))
            {
                HtmlAddons.CleanUpCss(ref tmpcss);

                CssParser cp = new CssParser();
                IEnumerable <CssParserRule> rules = cp.ParseAll(tmpcss);
                CssHolder ch = new CssHolder();

                foreach (CssParserRule rule in rules)
                {
                    foreach (string sel in rule.Selectors)
                    {
                        string tmpsel = sel.Replace(" > ", ">").Replace(" >", ">").Replace("> ", ">");
                        tmpsel = tmpsel.Replace(" + ", "+").Replace(" +", "+").Replace("+ ", "+");
                        tmpsel = tmpsel.Replace(" ", ">");
                        //remove pseudoselectors
                        tmpsel = Regex.Replace(tmpsel, @"(::?[^:]+?)+$", "", RegexOptions.Multiline);
                        //reove attributes
                        tmpsel = Regex.Replace(tmpsel, @"(\[[^[]+?])+$", "", RegexOptions.Multiline);
                        //Console.WriteLine(tmpsel);
                        if (!ch.HasItem(tmpsel, rule.Media))
                        {
                            ch.HolderItems.Add(new CssHolderItem(tmpsel, rule.Media));
                        }
                    }
                }

                ch.SortIt();

                TreeNode <CssTreeItem> tn = new TreeNode <CssTreeItem>(new CssTreeItem("html", "", "html", "html"));

                for (int x = 0; x < ch.HolderItems.Count; x++)
                {
                    string tmpmed = ch.HolderItems[x].MediaQuery;
                    string tmpsel = ch.HolderItems[x].Selector;
                    tmpsel = tmpsel.Trim();
                    string[] plussplit = tmpsel.Split('+');
                    string[] tmpsels;

                    if (tmpsel.Contains('+'))
                    {
                        string[] splits = HtmlAddons.SplitSelectors("", tmpsel).Split('\\');

                        foreach (string sp in splits)
                        {
                            tmpsels = sp.Split('>');
                            CreateTreeNodes(tmpsels, tmpmed, ref tn);
                        }
                    }
                    else
                    {
                        tmpsels = tmpsel.Split('>');
                        CreateTreeNodes(tmpsels, tmpmed, ref tn);
                    }
                }

                FixTreeNodes(ref tn);
                Console.WriteLine("-----------------------");

                string tmpstr = "<html>\r\n<head>\r\n<link rel=\"stylesheet\" href=\"" + options.CssFileName + "\">\r\n";
                //tmpstr = tmpstr + "<style type=\"text/css\">" + ".clear-csspreview:before,.clear-csspreview:after { content:\"\"; display:table; } .clear-csspreview:after { clear:both;} .clear-csspreview {margin:20px 0;  zoom:1;}"+ "</style>";
                //tmpstr = tmpstr + "<style type=\"text/css\">" + "div:before,div:after { content:\"\"; display:table; } div:after { clear:both;} div { zoom:1;}"+ "</style>";

                tmpstr = tmpstr + "</head>\r\n" + CrawlTree("html", 0, tn, options) + "\r\n</html>";
                try {
                    File.WriteAllText(options.CssFolderName + options.HtmlFileName, tmpstr, Encoding.UTF8);
                } catch (Exception e) {
                    Console.WriteLine(e.Message);
                }

                Console.WriteLine(tmpstr);
            }
            Console.ReadKey();
        }