Beispiel #1
0
        private static string Render(Selector sel, int nesting)
        {
            string prefix = "";
            for (int i = 0; i < nesting; i++) {
                prefix += "\t";
            }
            StringBuilder txt = new StringBuilder();

            bool first = true;
            foreach (Tag t in sel.Tags) {
                if (first) {
                    first = false;
                    txt.Append(prefix);
                } else {
                    txt.Append(", ");
                }
                txt.Append(t.ToString());
            }
            txt.Append(" {\r\n");
            foreach (Property prp in sel.Properties) {
                txt.Append("\t");
                txt.Append(prefix);
                txt.Append(prp.Attribute);
                txt.Append(": ");

                bool pfirst = true;
                foreach (PropertyValue pv in prp.Values) {
                    if (pfirst) { pfirst = false; } else { txt.Append(" "); }
                    if (pv.Type == BoneSoft.CSS.ValueType.Url) {
                        txt.Append("url(");
                    } else if (pv.Type == BoneSoft.CSS.ValueType.Hex && !pv.Value.StartsWith("#")) {
                        txt.Append("#");
                    }
                    txt.Append(pv.Value);
                    if (pv.Type == BoneSoft.CSS.ValueType.Unit) {
                        txt.Append(pv.Unit.ToString().ToLower());
                    } else if (pv.Type == BoneSoft.CSS.ValueType.Percent) {
                        txt.Append("%");
                    } else if (pv.Type == BoneSoft.CSS.ValueType.Url) {
                        txt.Append(")");
                    }
                }
                if (prp.Important) {
                    txt.Append(" !important");
                }
                txt.Append(";\r\n");
            }
            txt.AppendFormat("{0}}}", prefix);

            return txt.ToString();
        }
Beispiel #2
0
        void selector(out Selector sel)
        {
            sel = new Selector();
            SimpleSelector ss = null;
            Combinator? cb = null;

            simpleselector(out ss);
            sel.SimpleSelectors.Add(ss);
            while (la.kind == 4) {
                Get();
            }
            while (StartOf(12)) {
                if (la.kind == 29 || la.kind == 30 || la.kind == 31) {
                    if (la.kind == 29) {
                        Get();
                        cb = Combinator.PrecededImmediatelyBy;
                    } else if (la.kind == 30) {
                        Get();
                        cb = Combinator.ChildOf;
                    } else {
                        Get();
                        cb = Combinator.PrecededBy;
                    }
                }
                while (la.kind == 4) {
                    Get();
                }
                simpleselector(out ss);
                if (cb.HasValue) { ss.Combinator = cb.Value; }
                sel.SimpleSelectors.Add(ss);

                cb = null;
                while (la.kind == 4) {
                    Get();
                }
            }
        }
Beispiel #3
0
        public static void RenderSelector(StringBuilder sb, Selector sel)
        {
            bool first = true;
            foreach (SimpleSelector ss in sel.SimpleSelectors)
            {
                if (first) {
                    first = false;
                } else {
                    sb.Append(" ");
                }

                RenderSimpleSelector(sb, ss);
            }
        }
Beispiel #4
0
 public static string Render(Selector sel)
 {
     return Render(sel, 0);
 }
Beispiel #5
0
        static string Render(Selector sel)
        {
            StringBuilder txt = new StringBuilder();

            bool first = true;
            foreach (SimpleSelector ss in sel.SimpleSelectors) {
                if (first) { first = false; } else { txt.Append(" "); }
                txt.AppendFormat("<span class=\"simpleSelector\">{0}</span>", Render(ss));
            }

            return txt.ToString();
        }