Skip to content

Commit fbbb6af

Browse files
committed
WIP
1 parent cbdfb78 commit fbbb6af

23 files changed

Lines changed: 1190 additions & 124 deletions
Lines changed: 46 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -1,60 +1,60 @@
11
using System.Collections.Generic;
22
using System.IO;
33
using System.Threading.Tasks;
4-
using TurnerSoftware.CascadingStyles.Rules;
4+
using TurnerSoftware.CascadingStyles.ObjectModel;
55

66
namespace TurnerSoftware.CascadingStyles.Formatter
77
{
88
public class StyleSheetFormatter
99
{
1010
public async ValueTask WriteAsync(StyleSheet styleSheet, TextWriter writer)
1111
{
12-
foreach (var rule in styleSheet.Rules)
13-
{
14-
await WriteRuleAsync(rule, writer);
15-
}
12+
//foreach (var rule in styleSheet.Rules)
13+
//{
14+
// await WriteRuleAsync(rule, writer);
15+
//}
1616
}
1717

18-
private static async ValueTask WriteRuleAsync(Rule rule, TextWriter writer)
19-
{
20-
if (rule is StyleRule styleRule)
21-
{
22-
await WriteStyleRuleAsync(styleRule, writer);
23-
}
24-
else if (rule is MediaRule mediaRule)
25-
{
26-
await writer.WriteAsync("@media ");
27-
await writer.WriteAsync(mediaRule.Condition);
28-
await WriteBlockAsync(mediaRule.Rules, writer);
29-
}
30-
}
31-
32-
private static async ValueTask WriteStyleRuleAsync(StyleRule styleRule, TextWriter writer)
33-
{
34-
await writer.WriteAsync(styleRule.SelectorText);
35-
await writer.WriteAsync('{');
36-
37-
foreach (var (property, value) in styleRule.Style)
38-
{
39-
await writer.WriteAsync(property);
40-
await writer.WriteAsync(':');
41-
await writer.WriteAsync(value);
42-
await writer.WriteAsync(';');
43-
}
44-
45-
await writer.WriteAsync('}');
46-
}
47-
48-
private static async ValueTask WriteBlockAsync(ICollection<Rule> rules, TextWriter writer)
49-
{
50-
writer.Write('{');
51-
52-
foreach (var rule in rules)
53-
{
54-
await WriteRuleAsync(rule, writer);
55-
}
56-
57-
writer.Write('}');
58-
}
18+
//private static async ValueTask WriteRuleAsync(Rule rule, TextWriter writer)
19+
//{
20+
// if (rule is StyleRule styleRule)
21+
// {
22+
// await WriteStyleRuleAsync(styleRule, writer);
23+
// }
24+
// else if (rule is MediaRule mediaRule)
25+
// {
26+
// await writer.WriteAsync("@media ");
27+
// await writer.WriteAsync(mediaRule.Condition);
28+
// await WriteBlockAsync(mediaRule.Rules, writer);
29+
// }
30+
//}
31+
32+
//private static async ValueTask WriteStyleRuleAsync(StyleRule styleRule, TextWriter writer)
33+
//{
34+
// await writer.WriteAsync(styleRule.SelectorText);
35+
// await writer.WriteAsync('{');
36+
37+
// foreach (var (property, value) in styleRule.Style)
38+
// {
39+
// await writer.WriteAsync(property);
40+
// await writer.WriteAsync(':');
41+
// await writer.WriteAsync(value);
42+
// await writer.WriteAsync(';');
43+
// }
44+
45+
// await writer.WriteAsync('}');
46+
//}
47+
48+
//private static async ValueTask WriteBlockAsync(ICollection<Rule> rules, TextWriter writer)
49+
//{
50+
// writer.Write('{');
51+
52+
// foreach (var rule in rules)
53+
// {
54+
// await WriteRuleAsync(rule, writer);
55+
// }
56+
57+
// writer.Write('}');
58+
//}
5959
}
6060
}
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.Linq;
4+
using System.Text;
5+
using System.Threading.Tasks;
6+
7+
namespace TurnerSoftware.CascadingStyles.ObjectModel
8+
{
9+
public struct Dimension
10+
{
11+
public readonly double Number;
12+
public readonly StringValue Unit;
13+
14+
public Dimension(double number, StringValue unit)
15+
{
16+
Number = number;
17+
Unit = unit;
18+
}
19+
}
20+
}
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
namespace TurnerSoftware.CascadingStyles.ObjectModel
2+
{
3+
public interface ICssRule { }
4+
}
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
using System.Collections.Generic;
2+
3+
namespace TurnerSoftware.CascadingStyles.ObjectModel
4+
{
5+
public class MediaQuery : ICssRule
6+
{
7+
public List<MediaQueryGroup> Query { get; init; } = new List<MediaQueryGroup>();
8+
9+
public List<ICssRule> Rules { get; init; } = new List<ICssRule>();
10+
}
11+
12+
public struct MediaQueryGroup
13+
{
14+
public readonly IReadOnlyList<IMediaQueryComponent> Components;
15+
16+
public MediaQueryGroup(IReadOnlyList<IMediaQueryComponent> components)
17+
{
18+
Components = components;
19+
}
20+
}
21+
22+
public interface IMediaQueryComponent { }
23+
24+
public sealed class MediaExpression : IMediaQueryComponent
25+
{
26+
public readonly StringValue Feature;
27+
public readonly StringValue Expression;
28+
}
29+
30+
public sealed class MediaQueryConstants : IMediaQueryComponent
31+
{
32+
public static readonly MediaQueryConstants Only = new("ONLY");
33+
public static readonly MediaQueryConstants Not = new("NOT");
34+
public static readonly MediaQueryConstants And = new("AND");
35+
36+
private readonly string Value;
37+
38+
private MediaQueryConstants(string value)
39+
{
40+
Value = value;
41+
}
42+
43+
public override string ToString() => Value;
44+
}
45+
}

0 commit comments

Comments
 (0)