Skip to content

Commit

Permalink
1.0.0-preview7-05
Browse files Browse the repository at this point in the history
  • Loading branch information
chanan committed Aug 6, 2019
1 parent fdeace4 commit 8c1a6ea
Show file tree
Hide file tree
Showing 22 changed files with 445 additions and 154 deletions.
2 changes: 1 addition & 1 deletion src/BlazorStyled/BlazorStyled.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
<RazorLangVersion>3.0</RazorLangVersion>
<AddRazorSupportForMvc>true</AddRazorSupportForMvc>
<PackageId>BlazorStyled</PackageId>
<Version>1.0.0-preview7-04</Version>
<Version>1.0.0-preview7-05</Version>
<Authors>Chanan Braunstein</Authors>
<Title>BlazorStyled</Title>
<Description>CSS in Blazor Components</Description>
Expand Down
68 changes: 59 additions & 9 deletions src/BlazorStyled/Internal/StyledImpl.cs
Original file line number Diff line number Diff line change
Expand Up @@ -277,8 +277,10 @@ private RuleSet ParseRuleSet(string css)
IRule current = ruleSet;
string buffer = string.Empty;
bool nestedClassClosed = true; //Start from true becuase the parent doesnt need to be closed
foreach (char ch in css)
int i = 0;
do
{
char ch = css[i];
switch (ch)
{
case ';':
Expand All @@ -304,18 +306,39 @@ private RuleSet ParseRuleSet(string css)
{
Selector = buffer.Trim()
};
ruleSet.NestedRules.Add(nestedClass);
buffer = string.Empty;
current = nestedClass;
nestedClassClosed = false;
}
else
{
nestedClass = new MediaQuery

if (current.RuleType == RuleType.RuleSet)
{
Selector = buffer.Trim() + "{&"
};
nestedClass = new MediaQuery
{
Selector = buffer.Trim() + "{&"
};
ruleSet.NestedRules.Add(nestedClass);
buffer = string.Empty;
current = nestedClass;
nestedClassClosed = false;
}
else
{
nestedClass = new MediaQuery
{
Selector = buffer.Trim()
};
ruleSet.NestedRules.Add(nestedClass);
buffer = string.Empty;
nestedClassClosed = false;
string innerCss = GetInnerClassCss(css, i);
nestedClass.NestedRules = ParseRuleSet(innerCss).NestedRules;
i += innerCss.Length;
}
}
ruleSet.NestedRules.Add(nestedClass);
buffer = string.Empty;
current = nestedClass;
nestedClassClosed = false;
break;
case '}':
nestedClassClosed = true;
Expand All @@ -324,7 +347,8 @@ private RuleSet ParseRuleSet(string css)
buffer += ch;
break;
}
}
i++;
} while (i < css.Length);
if (!nestedClassClosed)
{
throw StyledException.GetException(css, "A nested class is missing a '}' character", null);
Expand All @@ -337,6 +361,32 @@ private RuleSet ParseRuleSet(string css)
return ruleSet;
}

private string GetInnerClassCss(string fullCss, int startFrom)
{
var startFromCss = fullCss.Substring(startFrom);
int start = startFromCss.IndexOf('{') + 1;
startFromCss = startFromCss.Substring(start);
int openBraces = 0;
int end = -1;
for(int i = 0; i < startFromCss.Length; i++)
{
char ch = startFromCss[i];
if (ch == '{') openBraces++;
if(ch == '}')
{
openBraces--;
if(openBraces < 0 )
{
end = i;
break;
}
}
}
if (end == -1) end = startFromCss.Length;
var css = startFromCss.Substring(start, end - start);
return css;
}

private Declaration ParseDeclaration(string input)
{
if (string.IsNullOrEmpty(input))
Expand Down
2 changes: 1 addition & 1 deletion src/BlazorStyled/StyledGoogleFont.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ namespace BlazorStyled
public class StyledGoogleFont : ComponentBase
{
[Parameter] private string Name { get; set; }
[Parameter] private string? Styles { get; set; }
[Parameter] private string Styles { get; set; }
[Inject] private IStyled StyledService { get; set; }

protected override void OnInit()
Expand Down
2 changes: 2 additions & 0 deletions src/SampleCore/Pages/Index.razor
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@

<Line />

<a href="/test">Test</a>

<Heading HeadingSize="HeadingSize.H3">Example</Heading>

<div class="@example">
Expand Down
42 changes: 19 additions & 23 deletions src/SampleCore/Pages/Test.razor
Original file line number Diff line number Diff line change
@@ -1,29 +1,25 @@
@page "/test"
@inject IStyled Styled

<Styled @bind-Classname="@bounce" IsKeyframes="true">
from, 20%, 53%, 80%, to {
transform: translate3d(0,0,0);
}

40%, 43% {
transform: translate3d(0, -30px, 0);
}
@code {
protected override void OnInit()
{
Styled.Css(" @media only screen and (max-width:480px)", @"
ul,ol {
margin-left: 0.5em;
}
");

70% {
transform: translate3d(0, -15px, 0);
}
Styled.Css(" @media only screen and (max-width:480px)", @"
blockquote {
padding-left: 0.5em;
}
");

90% {
transform: translate3d(0,-4px,0);
Styled.Css(" @media only screen and (max-width:480px)", @"
h5,h6 {
text-transform: uppercase;
}
");
}
</Styled>

<Styled @bind-Classname="@example">
animation: vlzl-qdd 1s ease infinite;
</Styled>

<div class="@example">Bouncy text!</div>

@code {
private string MyClass1, MyClass2, MyClass3, MyClass4, MyClass5, bounce, example;
}
17 changes: 2 additions & 15 deletions src/SampleCore/SampleCore.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="BlazorPrettyCode" Version="1.0.0-preview7-03" />
<PackageReference Include="BlazorPrettyCode" Version="1.0.0-preview7-05" />
<PackageReference Include="BlazorTypography" Version="1.0.0-preview7-05" />
<PackageReference Include="Polished" Version="1.0.0-preview-02" />
</ItemGroup>

Expand All @@ -20,19 +21,5 @@
<EmbeddedResource Include="wwwroot\**\*.css" LogicalName="blazor:css:%(RecursiveDir)%(Filename)%(Extension)" />
<EmbeddedResource Include="wwwroot\**" Exclude="**\*.js;**\*.css" LogicalName="blazor:file:%(RecursiveDir)%(Filename)%(Extension)" />
</ItemGroup>

<ItemGroup>
<Content Remove="wwwroot\components1.html" />
<Content Remove="wwwroot\components2.html" />
<Content Remove="wwwroot\fonts1.html" />
<Content Remove="wwwroot\googleFont1.html" />
<Content Remove="wwwroot\googleFont2.html" />
<Content Remove="wwwroot\labels1.html" />
<Content Remove="wwwroot\media1.html" />
<Content Remove="wwwroot\media2.html" />
<Content Remove="wwwroot\media3.html" />
<Content Remove="wwwroot\polished1.html" />
<Content Remove="wwwroot\theming1.html" />
</ItemGroup>

</Project>
Loading

0 comments on commit 8c1a6ea

Please sign in to comment.