Example #1
0
        // only for style rule.
        public string GetRuleTextAddOrUpdateDeclaration(Guid CmsCssRuleId, string PropertyName, string Value, bool Importance = false)
        {
            var cmsrule = SiteDb.CssRules.Get(CmsCssRuleId);

            if (cmsrule != null)
            {
                var declarations = CSSSerializer.deserializeDeclarationBlock(cmsrule.CssText);
                declarations.updateDeclaration(new CSSDeclaration()
                {
                    propertyname = PropertyName, value = Value, important = Importance
                });
                string ruletext = CSSSerializer.serializeDeclarationBlock(declarations);

                string newruletext = cmsrule.SelectorText + "\r\n{\r\n" + ruletext + "\r\n}\r\n";
                return(newruletext);
            }
            return(null);
        }
Example #2
0
        internal virtual void UpdateDom(IRepository repo, RenderContext context, IDomObject domObject, Element element)
        {
            SourceUpdate sourceUpdate;

            if (!string.IsNullOrWhiteSpace(Attribute))
            {
                element.setAttribute(Attribute, Value);
                sourceUpdate = new SourceUpdate
                {
                    StartIndex = element.location.openTokenStartIndex,
                    EndIndex   = element.location.openTokenEndIndex,
                    NewValue   = Service.DomService.ReSerializeOpenTag(element)
                };
            }
            else if (!string.IsNullOrWhiteSpace(Property))
            {
                var style = element.getAttribute("style");

                var cssDeclar  = CSSSerializer.deserializeDeclarationBlock(style);
                var propertise = cssDeclar.item;
                var exist      = propertise.Find(o => o.propertyname.ToLower() == Property.ToLower());

                if (exist == null)
                {
                    propertise.Add(new CSSDeclaration
                    {
                        important    = Important,
                        propertyname = Property,
                        value        = Value
                    });
                }
                else
                {
                    exist.value     = Value;
                    exist.important = Important;
                    propertise.Remove(exist);
                    propertise.Add(exist);
                }

                cssDeclar.item = cssDeclar.item.Where(o => !string.IsNullOrWhiteSpace(o.propertyname) && !string.IsNullOrWhiteSpace(o.value)).ToList();
                var newStyle = CSSSerializer.serializeDeclarationBlock(cssDeclar);
                element.setAttribute("style", newStyle);
                sourceUpdate = new SourceUpdate
                {
                    StartIndex = element.location.openTokenStartIndex,
                    EndIndex   = element.location.openTokenEndIndex,
                    NewValue   = Service.DomService.ReSerializeOpenTag(element)
                };
            }
            else
            {
                sourceUpdate = new SourceUpdate
                {
                    StartIndex = element.location.openTokenEndIndex + 1,
                    EndIndex   = element.location.endTokenStartIndex - 1,
                    NewValue   = Value
                };
            }

            UpdateDomObject(repo, context, domObject, sourceUpdate);
        }