Skip to content

Commit 1097367

Browse files
committed
v3.0.0-alpha-04
1 parent aea0682 commit 1097367

22 files changed

+254
-408
lines changed

BlazorStyled.sln

+12
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,10 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "ServerSidePreRender", "src\
2525
EndProject
2626
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "ClientSideSample", "src\ClientSideSample\ClientSideSample.csproj", "{D9BBEBEB-4695-4033-90D2-89223661761C}"
2727
EndProject
28+
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "BlazorTypography", "..\BlazorTypography\src\BlazorTypography\BlazorTypography.csproj", "{77D2B9D7-84EC-482F-97F9-7C70F88268C1}"
29+
EndProject
30+
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "BlazorPrettyCode", "..\BlazorPrettyCode\src\BlazorPrettyCode\BlazorPrettyCode.csproj", "{8F8DEBF6-653A-41F7-AF65-88C5077DA10A}"
31+
EndProject
2832
Global
2933
GlobalSection(SolutionConfigurationPlatforms) = preSolution
3034
Debug|Any CPU = Debug|Any CPU
@@ -63,6 +67,14 @@ Global
6367
{D9BBEBEB-4695-4033-90D2-89223661761C}.Debug|Any CPU.Build.0 = Debug|Any CPU
6468
{D9BBEBEB-4695-4033-90D2-89223661761C}.Release|Any CPU.ActiveCfg = Release|Any CPU
6569
{D9BBEBEB-4695-4033-90D2-89223661761C}.Release|Any CPU.Build.0 = Release|Any CPU
70+
{77D2B9D7-84EC-482F-97F9-7C70F88268C1}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
71+
{77D2B9D7-84EC-482F-97F9-7C70F88268C1}.Debug|Any CPU.Build.0 = Debug|Any CPU
72+
{77D2B9D7-84EC-482F-97F9-7C70F88268C1}.Release|Any CPU.ActiveCfg = Release|Any CPU
73+
{77D2B9D7-84EC-482F-97F9-7C70F88268C1}.Release|Any CPU.Build.0 = Release|Any CPU
74+
{8F8DEBF6-653A-41F7-AF65-88C5077DA10A}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
75+
{8F8DEBF6-653A-41F7-AF65-88C5077DA10A}.Debug|Any CPU.Build.0 = Debug|Any CPU
76+
{8F8DEBF6-653A-41F7-AF65-88C5077DA10A}.Release|Any CPU.ActiveCfg = Release|Any CPU
77+
{8F8DEBF6-653A-41F7-AF65-88C5077DA10A}.Release|Any CPU.Build.0 = Release|Any CPU
6678
EndGlobalSection
6779
GlobalSection(SolutionProperties) = preSolution
6880
HideSolutionNode = FALSE

src/BlazorStyled/BlazorStyled.csproj

+1-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
<LangVersion>8.0</LangVersion>
77
<AddRazorSupportForMvc>true</AddRazorSupportForMvc>
88
<PackageId>BlazorStyled</PackageId>
9-
<Version>3.0.0-alpha-03</Version>
9+
<Version>3.0.0-alpha-04</Version>
1010
<Authors>Chanan Braunstein</Authors>
1111
<Title>BlazorStyled</Title>
1212
<Description>CSS in Blazor Components</Description>

src/BlazorStyled/IStyled.cs

+6-3
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,12 @@ namespace BlazorStyled
66
public interface IStyled
77
{
88
Task ClearStyles();
9-
Task<string> Css(string css);
10-
Task<string> Css(string className, string css);
11-
Task<string> Css(List<string> classes, string css);
9+
Task<string> CssAsync(string css);
10+
Task<string> CssAsync(string className, string css);
11+
Task<string> CssAsync(List<string> classes, string css);
12+
string Css(string css);
13+
string Css(string className, string css);
14+
string Css(List<string> classes, string css);
1215
Task<string> Keyframes(string css);
1316
Task Fontface(string css);
1417
Task AddGoogleFonts(List<GoogleFont> googleFonts);

src/BlazorStyled/Internal/ParsedClass.cs

+13-26
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
using System;
2-
using System.Collections.Generic;
1+
using System.Collections.Generic;
2+
using System.Security;
33
using System.Text;
44

55
namespace BlazorStyled.Internal
@@ -18,16 +18,21 @@ public ParsedClass(string name, string body)
1818
IsDynamic = false;
1919
Name = name;
2020
}
21-
if (IsMediaQuery)
21+
if ((IsMediaQuery && name.Contains("&")) || (IsMediaQuery & body.Contains("{")) ||IsKeyframes)
2222
{
2323
ChildClasses = new List<ParsedClass>();
24+
body = null;
2425
}
25-
if (body.EndsWith("} }") || body.EndsWith("}}"))
26+
else if(IsMediaQuery)
27+
{
28+
ChildClasses = new List<ParsedClass>();
29+
}
30+
if (body !=null && (body.EndsWith("} }") || body.EndsWith("}}")))
2631
{
2732
Declarations = ParseDeclerations(body.Substring(0, body.Length - 1));
2833
IsLastChild = true;
2934
}
30-
else if (body == "{")
35+
else if (body != null && body == "{") //TODO: This might not be needed anymore
3136
{
3237
ChildClasses = new List<ParsedClass>();
3338
}
@@ -50,6 +55,7 @@ public ParsedClass(string importUri)
5055

5156
private string ParseDeclerations(string body)
5257
{
58+
if (body == null) return null;
5359
string str = body.Trim();
5460
if (str.Contains("label"))
5561
{
@@ -60,40 +66,21 @@ private string ParseDeclerations(string body)
6066
if (end != -1)
6167
{
6268
Label = str.Substring(start + 1, end - start - 1).Trim();
63-
str = str.Substring(0, start - 5) + str.Substring(end, str.Length - end - 1);
69+
str = str.Substring(0, start - 5) + str.Substring(end + 1, str.Length - end - 1).Trim();
6470
}
6571
}
6672
}
6773
return str.StartsWith("{") && str.EndsWith("}") ? str.Substring(1, str.Trim().Length - 2).Trim() : str;
6874
}
6975

70-
private Tuple<string, string> ParseDeclaration(string input)
71-
{
72-
if (string.IsNullOrEmpty(input))
73-
{
74-
return null;
75-
}
76-
77-
try
78-
{
79-
string property = input.Substring(0, input.IndexOf(':')).ToLower().Trim();
80-
string value = input.Substring(input.IndexOf(':') + 1).Trim();
81-
return new Tuple<string, string>(property, value);
82-
}
83-
catch (Exception e)
84-
{
85-
throw StyledException.GetException(input, "This is likely cause by a missing ':' character", e);
86-
}
87-
}
88-
8976
public string Name { get; set; }
9077
public string Label { get; private set; }
9178
public IList<ParsedClass> ChildClasses { get; private set; }
9279
public bool IsDynamic { get; private set; }
9380
public bool IsParent => ChildClasses != null;
9481
public bool IsMediaQuery => !IsDynamic && Name.IndexOf("@media") != -1;
9582
public bool IsFontface => !IsDynamic && Name.IndexOf("@font-face") != -1;
96-
public bool IsKeyframes => !IsDynamic && IsParent && Name.IndexOf("@keyframe") != -1;
83+
public bool IsKeyframes => !IsDynamic && Name.IndexOf("@keyframe") != -1;
9784
public bool IsElement => !IsDynamic && !IsFontface && !IsKeyframes && !IsMediaQuery; //TODO: This might not be correct
9885
public bool IsLastChild { get; private set; }
9986
public string Parent { get; set; }

0 commit comments

Comments
 (0)