Esempio n. 1
0
 /// <summary>
 /// Writes the serialization of the node guided by the formatter to the
 /// given stream.
 /// </summary>
 /// <param name="style">The style node to format.</param>
 /// <param name="stream">The output stream to use.</param>
 public static async Task ToCssAsync(this IStyleFormattable style, Stream stream)
 {
     using (var writer = new StreamWriter(stream))
     {
         await style.ToCssAsync(writer).ConfigureAwait(false);
     }
 }
Esempio n. 2
0
        /// <summary>
        /// Gets the associated for the provided entity, if any.
        /// </summary>
        /// <param name="node">The node to start the retrieval.</param>
        /// <param name="entity">The entity to look for.</param>
        /// <returns>The associated node, or null if there is none..</returns>
        public static CssNode GetAssociatedNode(this CssNode node, IStyleFormattable entity)
        {
            if (node == null)
            {
                throw new ArgumentNullException("node");
            }

            if (entity == null)
            {
                throw new ArgumentNullException("entity");
            }

            var target = default(CssNode);

            if (Object.ReferenceEquals(node.Entity, entity))
            {
                return(node);
            }

            foreach (var child in node.Children)
            {
                target = child.GetAssociatedNode(entity);

                if (target != null)
                {
                    break;
                }
            }

            return(target);
        }
Esempio n. 3
0
        public static string ToCss(this IStyleFormattable style, IStyleFormatter formatter)
        {
            var sb = Pool.NewStringBuilder();

            using (var writer = new StringWriter(sb))
            {
                style.ToCss(writer, formatter);
            }
            return(sb.ToPool());
        }
        string IStyleFormatter.Style(string selector, IStyleFormattable rules)
        {
            var sb     = Pool.NewStringBuilder().Append(selector).Append(" { ");
            var length = sb.Length;

            using (var writer = new StringWriter(sb))
            {
                rules.ToCss(writer, this);
            }

            if (sb.Length > length)
            {
                sb.Append(' ');
            }
            return(sb.Append('}').ToPool());
        }
Esempio n. 5
0
        string IStyleFormatter.Style(string selector, IStyleFormattable rules)
        {
            var sb      = Pool.NewStringBuilder().Append(selector).Append(" {");
            var content = rules.ToCss(this);

            if (!string.IsNullOrEmpty(content))
            {
                sb.Append(NewLine);
                sb.Append(Indent(content));
                sb.Append(NewLine);
            }
            else
            {
                sb.Append(' ');
            }
            return(sb.Append('}').ToPool());
        }
Esempio n. 6
0
 /// <summary>
 /// Returns the (complete) CSS style representation of the node.
 /// </summary>
 /// <param name="style">The style node to format.</param>
 /// <returns>The source code snippet.</returns>
 public static String ToCss(this IStyleFormattable style)
 {
     return(style.ToCss(CssStyleFormatter.Instance));
 }
Esempio n. 7
0
 /// <summary>
 /// Writes the serialization of the node guided by the formatter.
 /// </summary>
 /// <param name="style">The style node to format.</param>
 /// <param name="writer">The output target of the serialization.</param>
 public static Task ToCssAsync(this IStyleFormattable style, TextWriter writer) =>
 writer.WriteAsync(style.ToCss());
Esempio n. 8
0
 /// <summary>
 /// Writes the serialization of the node guided by the formatter.
 /// </summary>
 /// <param name="style">The style node to format.</param>
 /// <param name="writer">The output target of the serialization.</param>
 public static void ToCss(this IStyleFormattable style, TextWriter writer) =>
 style.ToCss(writer, CssStyleFormatter.Instance);
Esempio n. 9
0
 /// <summary>
 /// Returns the (complete) CSS style representation of the node.
 /// </summary>
 /// <param name="style">The style node to format.</param>
 /// <returns>The source code snippet.</returns>
 public static String ToCss(this IStyleFormattable style) =>
 style.ToCss(CssStyleFormatter.Instance);
Esempio n. 10
0
 public static void ToCss(this IStyleFormattable style, TextWriter writer)
 {
     style.ToCss(writer, CompressedStyleFormatter.Instance);
 }
Esempio n. 11
0
        String IStyleFormatter.Style(String selector, IStyleFormattable rules)
        {
            var sb = Pool.NewStringBuilder().Append(selector).Append(" {");
            var content = rules.ToCss(this);

            if (!String.IsNullOrEmpty(content))
            {
                sb.Append(_newLineString);
                sb.Append(Intend(content));
                sb.Append(_newLineString);
            }
            else
            {
                sb.Append(' ');
            }

            return sb.Append('}').ToPool();
        }
Esempio n. 12
0
        String IStyleFormatter.Style(String selector, IStyleFormattable rules)
        {
            var sb = Pool.NewStringBuilder().Append(selector).Append(" { ");
            var length = sb.Length;

            using (var writer = new StringWriter(sb))
            {
                rules.ToCss(writer, this);
            }

            if (sb.Length > length)
            {
                sb.Append(' ');
            }

            return sb.Append('}').ToPool();
        }
 /// <summary>
 /// Returns a prettified serialization of the node guided by the
 /// PrettyStyleFormatter with the default options.
 /// </summary>
 /// <param name="style">The style node to format.</param>
 /// <returns>The source code snippet.</returns>
 public static String Prettify(this IStyleFormattable style) =>
 style.ToCss(new PrettyStyleFormatter());
 /// <summary>
 /// Returns a minified serialization of the node guided by the
 /// MinifyStyleFormatter with the default options.
 /// </summary>
 /// <param name="style">The style node to format.</param>
 /// <returns>The source code snippet.</returns>
 public static String Minify(this IStyleFormattable style) =>
 style.ToCss(new MinifyStyleFormatter());