예제 #1
0
        public void WorkWithExCss()
        {
            // Could read in a file here...
            string css = "html{ background-color: #5a5eed; color: #FFFFFF; margin: 5px; } h2{ background-color: red }";

            var stylesheet = new ExCSS.StylesheetParser().Parse(css);

            // Get the info out - long hand
            //var info = stylesheet.Children.First(c => ((ExCSS.StyleRule)c).SelectorText == "html") as ExCSS.StyleRule;
            //var selector = info.SelectorText;
            //var firstCssProperty = info.Style.BackgroundColor;

            // Get the info out - New way
            var info            = stylesheet.StyleRules.First() as ExCSS.StyleRule;
            var selector        = info.SelectorText;
            var backgroundColor = info.Style.BackgroundColor;
            var foregroundColor = info.Style.Color;
            var margin          = info.Style.Margin;


            //// Create a new stylesheet
            var newParser = new ExCSS.StylesheetParser();

            ExCSS.StyleRule r = new ExCSS.StyleRule(newParser);
            r.SelectorText          = "h1";
            r.Style.BackgroundColor = "red";

            ExCSS.StyleRule r2 = new ExCSS.StyleRule(newParser);
            r2.SelectorText          = "h2";
            r2.Style.BackgroundColor = "green";

            var newstylesheet = r.ToCss() + System.Environment.NewLine + r2.ToCss();
        }
예제 #2
0
        public void CreateStylesheet_WithCssProperties_ExpectStandardStringBack()
        {
            // Arrange
            string expectedResult = @"h1 { background-color: rgb(255, 0, 0) }" + Environment.NewLine
                                    + "h2 { background-color: rgb(0, 128, 0) }";

            var newParser = new ExCSS.StylesheetParser();

            ExCSS.StyleRule r = new ExCSS.StyleRule(newParser);
            r.SelectorText          = "h1";
            r.Style.BackgroundColor = "red";

            ExCSS.StyleRule r2 = new ExCSS.StyleRule(newParser);
            r2.SelectorText          = "h2";
            r2.Style.BackgroundColor = "green";

            // Act
            var newstylesheet = r.ToCss() + System.Environment.NewLine + r2.ToCss();

            // Assert
            Assert.Equal(expectedResult, newstylesheet);
        }
예제 #3
0
        static void Main(string[] args)
        {
            { // FONTAWESOME :-)
                Console.WriteLine("MAKE FontAwesome");
                var          data = new Data();
                ExCSS.Parser p    = new ExCSS.Parser();
                var          css  = p.Parse(File.ReadAllText("font-awesome.css"));
                foreach (var item in css.StyleRules)
                {
                    ExCSS.StyleRule srule = item as ExCSS.StyleRule;
                    //.fa-glass:before
                    string cleanName = srule.Value.Replace(".fa-", "").Replace(":before", "").Replace("-", "_");

                    foreach (var name in cleanName.Split(','))
                    {
                        FontSymbol d = new FontSymbol();
                        d.Name = MakeCamelText(name);

                        var decl = srule.Declarations.FirstOrDefault(A => A.Name.ToLower() == "content");
                        if (decl != null)
                        {
                            var term = decl.Term as ExCSS.PrimitiveTerm;
                            if (term != null)
                            {
                                d.Hex = string.Format("{0:X}", (int)(term.Value as string)[0]);
                                data.Symbols.Add(d);
                            }
                        }
                    }
                }
                MakeJson(data, "fontawesome.json", false);
                Console.WriteLine("MAKE FontAwesome DONE.");
            }


            Console.Read();
        }