Skip to content

Commit

Permalink
Fix for google font server side
Browse files Browse the repository at this point in the history
  • Loading branch information
chanan committed Jul 29, 2019
1 parent aea0f3a commit 2ceba53
Show file tree
Hide file tree
Showing 7 changed files with 36 additions and 15 deletions.
7 changes: 6 additions & 1 deletion src/BlazorStyled/ServerSideStyled.razor
Original file line number Diff line number Diff line change
@@ -1,7 +1,12 @@
@inherits StyledBase

@foreach (var href in StyleSheet.GetImportRules())
{
<link href="@href" rel="stylesheet" />
}

<style>
@foreach (var cssClass in StyleSheet)
@foreach (var cssClass in StyleSheet.GetRulesWithoutImport())
{
@cssClass.ToString();
}
Expand Down
2 changes: 2 additions & 0 deletions src/BlazorStyled/Stylesheets/IStyleSheet.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ public interface IStyleSheet
void ClearStyles(string id);
IEnumerator<IRule> GetEnumerator();
string GetHashCodes();
IEnumerable<string> GetImportRules();
IEnumerable<IRule> GetRulesWithoutImport();
IDisposable Subscribe(IObserver<IStyleSheet> observer);
}
}
26 changes: 26 additions & 0 deletions src/BlazorStyled/Stylesheets/StyleSheet.cs
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,32 @@ IEnumerator IEnumerable.GetEnumerator()
return GetEnumerator();
}

public IEnumerable<IRule> GetRulesWithoutImport()
{
IEnumerable<IRule> q = from classes in _classes.Values
from rule in classes.Values
where rule.RuleType != RuleType.Import
select rule;

return q.AsEnumerable();
}

public IEnumerable<string> GetImportRules()
{
List<string> list = new List<string>();
List<IRule> rules = (from classes in _classes.Values
from rule in classes.Values
where rule.RuleType == RuleType.Import
select rule).ToList();

foreach (IRule rule in rules)
{
ImportUri import = (ImportUri)rule;
list.Add(import.Declarations[0].Value);
}
return list.AsEnumerable();
}

public IDisposable Subscribe(IObserver<IStyleSheet> observer)
{
if (!_observers.Contains(observer))
Expand Down
2 changes: 1 addition & 1 deletion src/SampleCore/Pages/GoogleFonts.razor
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
{
Styled.AddGoogleFonts(new List<GoogleFont> { new GoogleFont { Name = "Geostar", Styles = new List<string> { "normal" } }});

Styled.AddGoogleFonts(new List<GoogleFont> { new GoogleFont { Name = "Roboto", Styles = new List<string> { "400" } }});
Styled.AddGoogleFonts(new List<GoogleFont> { new GoogleFont { Name = "Roboto", Styles = new List<string> { "normal" } }});

geostar = Styled.Css("font-family: Geostar;");

Expand Down
11 changes: 1 addition & 10 deletions src/SampleCore/Shared/MainLayout.razor
Original file line number Diff line number Diff line change
Expand Up @@ -29,16 +29,7 @@
{
Styled.Css(Mixins.Normalize());

Styled.Css(Mixins.FontFace(new FontFaceConfiguration {
FontFamily = "Fira Mono",
FontStyle = "normal",
FontWeight = "400",
FontDisplay = "swap",
LocalFonts = new List<string> { "Fira Mono Regular", "FiraMono-Regular" },
FontFilePath = "https://fonts.gstatic.com/s/firamono/v7/N0bX2SlFPv1weGeLZDtgJv7S",
FileFormats = new List<string> { "woff2" },
UnicodeRange = "U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA, U+02DC, U+2000-206F, U+2074, U+20AC, U+2122, U+2191, U+2193, U+2212, U+2215, U+FEFF, U+FFFD"
}));
Styled.AddGoogleFonts(new List<GoogleFont> { new GoogleFont { Name = "Fira Mono", Styles = new List<string> { "400" } } });

Styled.Css("html", @"
height: 100%;
Expand Down
1 change: 0 additions & 1 deletion src/ServerSideSample/Pages/_Host.cshtml
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,5 @@
<app>@(await Html.RenderComponentAsync<SampleCore.App>())</app>

<script src="_framework/blazor.server.js"></script>
<script src="_content/BlazorStyled/styled.js"></script>
</body>
</html>
2 changes: 0 additions & 2 deletions src/ServerSideSample/Startup.cs
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,6 @@ public void ConfigureServices(IServiceCollection services)
});
}

//services.AddBlazorStyled();

services.AddServicesForSampleSites();
}

Expand Down

0 comments on commit 2ceba53

Please sign in to comment.