Skip to content

Commit

Permalink
Full port is done
Browse files Browse the repository at this point in the history
  • Loading branch information
chanan committed Jun 6, 2019
1 parent a9a894b commit 641937a
Show file tree
Hide file tree
Showing 16 changed files with 1,124 additions and 6 deletions.
7 changes: 6 additions & 1 deletion Polished.net.sln
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,12 @@ VisualStudioVersion = 16.0.28917.182
MinimumVisualStudioVersion = 10.0.40219.1
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Polished.net", "src\Polished.net\Polished.net.csproj", "{837A1FFD-D7C5-4EF4-BCA4-91CCB228201B}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Polished.net.tests", "src\Polished.net.tests\Polished.net.tests.csproj", "{53BA05F1-DDC6-4C6D-BF43-125E2F2CAC01}"
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Polished.net.tests", "src\Polished.net.tests\Polished.net.tests.csproj", "{53BA05F1-DDC6-4C6D-BF43-125E2F2CAC01}"
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution Items", "{7D0A702B-44A7-4929-AE59-78EBC74F7686}"
ProjectSection(SolutionItems) = preProject
readme.md = readme.md
EndProjectSection
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Expand Down
11 changes: 11 additions & 0 deletions readme.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
Polished.net
============

_A lightweight toolset for writing styles in C#_

Polished.net is a port of https://github.com/styled-components/polished (version 3.4.0) to C#.

Docs
====

There are no docs yet for this version but the polished js docs maybe helpful: https://polished.js.org/
17 changes: 17 additions & 0 deletions src/Polished.net.tests/Mixins/LinearGradient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -31,5 +31,22 @@ public void Fallback()
string expected = "background-color:#FFF;background-image:linear-gradient(to top right, #00FFFF 0%, rgba(0, 0, 255, 0) 50%, #0000FF 95%);";
Assert.AreEqual(expected, actual);
}

[TestMethod]
public void ThrowsIfColorStopsAreNull()
{
Assert.ThrowsException<PolishedException>(
() => _mixins.LinearGradient(null, "#FFF")
);

}

[TestMethod]
public void ThrowsIfColorStopsAreLessThan2()
{
Assert.ThrowsException<PolishedException>(
() => _mixins.LinearGradient(new List<string> { "#fff" }, "#fff")
);
}
}
}
18 changes: 18 additions & 0 deletions src/Polished.net.tests/Mixins/Normalize.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
using Microsoft.VisualStudio.TestTools.UnitTesting;

namespace Polished.Tests.Mixins
{
[TestClass]
public class Normalize
{
private readonly IMixins _mixins = new Polished.Mixins();

[TestMethod]
public void NormalizeCss()
{
string actual = _mixins.Normalize();
string expected = @"html { line-height: 1.15; -webkit-text-size-adjust: 100%; } body { margin: 0; } main { display: block; } h1 { font-size: 2em; margin: 0.67em 0; } hr { box-sizing: content-box; height: 0; overflow: visible; } pre { font-family: monospace, monospace; font-size: 1em; } a { background-color: transparent; } abbr[title] { border-bottom: none; text-decoration: underline; text-decoration: underline dotted; } b, strong { font-weight: bolder; } code, kbd, samp { font-family: monospace, monospace; font-size: 1em; } small { font-size: 80%; } sub, sup { font-size: 75%; line-height: 0; position: relative; vertical-align: baseline; } sub { bottom: -0.25em; } sup { top: -0.5em; } img { border-style: none; } button, input, optgroup, select, textarea { font-family: inherit; font-size: 100%; line-height: 1.15; margin: 0; } button, input { overflow: visible; } button, select { text-transform: none; } button, [type=""button""], [type=""reset""], [type=""submit""] { -webkit-appearance: button; } button::-moz-focus-inner, [type=""button""]::-moz-focus-inner, [type=""reset""]::-moz-focus-inner, [type=""submit""]::-moz-focus-inner { border-style: none; padding: 0; } button:-moz-focusring, [type=""button""]:-moz-focusring, [type=""reset""]:-moz-focusring, [type=""submit""]:-moz-focusring { outline: 1px dotted ButtonText; } fieldset { padding: 0.35em 0.75em 0.625em; } legend { box-sizing: border-box; color: inherit; display: table; max-width: 100%; padding: 0; white-space: normal; } progress { vertical-align: baseline; } textarea { overflow: auto; } [type=""checkbox""], [type=""radio""] { box-sizing: border-box; padding: 0; } [type=""number""]::-webkit-inner-spin-button, [type=""number""]::-webkit-outer-spin-button { height: auto; } [type=""search""] { -webkit-appearance: textfield; outline-offset: -2px; } [type=""search""]::-webkit-search-decoration { -webkit-appearance: none; } ::-webkit-file-upload-button { -webkit-appearance: button; font: inherit; } details { display: block; } summary { display: list-item; } template { display: none; } [hidden] { display: none; } ";
Assert.AreEqual(expected, actual);
}
}
}
88 changes: 88 additions & 0 deletions src/Polished.net.tests/Mixins/RadialGradient.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
using Microsoft.VisualStudio.TestTools.UnitTesting;
using System.Collections.Generic;

namespace Polished.Tests.Mixins
{
[TestClass]
public class RadialGradient
{
private readonly IMixins _mixins = new Polished.Mixins();

[TestMethod]
public void TwoColorStops()
{
string actual = _mixins.RadialGradient(new RadialGradientConfiguration { ColorStops = new List<string> { "#fff", "#000" } });
string expected = "background-color:#fff;background-image:radial-gradient(#fff, #000);";
Assert.AreEqual(expected, actual);
}

[TestMethod]
public void ExtentShapeAndPosition()
{
string actual = _mixins.RadialGradient(new RadialGradientConfiguration
{
ColorStops = new List<string> { "#00FFFF 0%", "rgba(0, 0, 255, 0) 50%", "#0000FF 95%" },
Extent = "farthest-corner at 45px 45px",
Position = "center",
Shape = "ellipse"
});
string expected = "background-color:#00FFFF;background-image:radial-gradient(center ellipse farthest-corner at 45px 45px, #00FFFF 0%, rgba(0, 0, 255, 0) 50%, #0000FF 95%);";
Assert.AreEqual(expected, actual);
}

[TestMethod]
public void ExtentAndShape()
{
string actual = _mixins.RadialGradient(new RadialGradientConfiguration
{
ColorStops = new List<string> { "#00FFFF 0%", "rgba(0, 0, 255, 0) 50%", "#0000FF 95%" },
Extent = "farthest-corner at 45px 45px",
Shape = "ellipse"
});
string expected = "background-color:#00FFFF;background-image:radial-gradient(ellipse farthest-corner at 45px 45px, #00FFFF 0%, rgba(0, 0, 255, 0) 50%, #0000FF 95%);";
Assert.AreEqual(expected, actual);
}

[TestMethod]
public void Extent()
{
string actual = _mixins.RadialGradient(new RadialGradientConfiguration
{
ColorStops = new List<string> { "#00FFFF 0%", "rgba(0, 0, 255, 0) 50%", "#0000FF 95%" },
Extent = "farthest-corner at 45px 45px"
});
string expected = "background-color:#00FFFF;background-image:radial-gradient(farthest-corner at 45px 45px, #00FFFF 0%, rgba(0, 0, 255, 0) 50%, #0000FF 95%);";
Assert.AreEqual(expected, actual);
}

[TestMethod]
public void ExtentAndFallback()
{
string actual = _mixins.RadialGradient(new RadialGradientConfiguration
{
ColorStops = new List<string> { "#00FFFF 0%", "rgba(0, 0, 255, 0) 50%", "#0000FF 95%" },
Extent = "farthest-corner at 45px 45px",
Fallback = "#FFF"
});
string expected = "background-color:#FFF;background-image:radial-gradient(farthest-corner at 45px 45px, #00FFFF 0%, rgba(0, 0, 255, 0) 50%, #0000FF 95%);";
Assert.AreEqual(expected, actual);
}

[TestMethod]
public void ThrowsIfColorStopsAreNull()
{
Assert.ThrowsException<PolishedException>(
() => _mixins.RadialGradient(null, null, null, null, null)
);

}

[TestMethod]
public void ThrowsIfColorStopsAreLessThan2()
{
Assert.ThrowsException<PolishedException>(
() => _mixins.RadialGradient(new List<string> { "#fff" }, null, null, null, null)
);
}
}
}
58 changes: 58 additions & 0 deletions src/Polished.net.tests/Mixins/RetinaImage.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
using Microsoft.VisualStudio.TestTools.UnitTesting;

namespace Polished.Tests.Mixins
{
[TestClass]
public class RetinaImage
{
private readonly IMixins _mixins = new Polished.Mixins();

[TestMethod]
public void ShowThrowIfNoFilename()
{
Assert.ThrowsException<PolishedException>(
() => _mixins.RetinaImage(null, null)
);
}

[TestMethod]
public void Filename()
{
string actual = _mixins.RetinaImage("img", null);
string expected = "background-image:url(img.png);@media only screen and (-webkit-min-device-pixel-ratio: 1.3),only screen and (min--moz-device-pixel-ratio: 1.3),only screen and (-o-min-device-pixel-ratio: 1.3/1),only screen and (min-resolution: 125dpi),only screen and (min-resolution: 1.3dppx){background-image:url(img_2x.png);}";
Assert.AreEqual(expected, actual);
}

[TestMethod]
public void FilenameAndCover()
{
string actual = _mixins.RetinaImage("img", "cover");
string expected = "background-image:url(img.png);@media only screen and (-webkit-min-device-pixel-ratio: 1.3),only screen and (min--moz-device-pixel-ratio: 1.3),only screen and (-o-min-device-pixel-ratio: 1.3/1),only screen and (min-resolution: 125dpi),only screen and (min-resolution: 1.3dppx){background-image:url(img_2x.png);background-size:cover;}";
Assert.AreEqual(expected, actual);
}

[TestMethod]
public void FilenameAndExtension()
{
string actual = _mixins.RetinaImage("img", null, "jpg");
string expected = "background-image:url(img.jpg);@media only screen and (-webkit-min-device-pixel-ratio: 1.3),only screen and (min--moz-device-pixel-ratio: 1.3),only screen and (-o-min-device-pixel-ratio: 1.3/1),only screen and (min-resolution: 125dpi),only screen and (min-resolution: 1.3dppx){background-image:url(img_2x.jpg);}";
Assert.AreEqual(expected, actual);
}

[TestMethod]
public void FilenameAndRetinaFilename()
{
string actual = _mixins.RetinaImage("img", null, null, "retina_img");
string expected = "background-image:url(img.png);@media only screen and (-webkit-min-device-pixel-ratio: 1.3),only screen and (min--moz-device-pixel-ratio: 1.3),only screen and (-o-min-device-pixel-ratio: 1.3/1),only screen and (min-resolution: 125dpi),only screen and (min-resolution: 1.3dppx){background-image:url(retina_img.png);}";
Assert.AreEqual(expected, actual);
}

[TestMethod]
public void FilenameAndSuffix()
{
string actual = _mixins.RetinaImage("img", null, null, null, "_5x");
string expected = "background-image:url(img.png);@media only screen and (-webkit-min-device-pixel-ratio: 1.3),only screen and (min--moz-device-pixel-ratio: 1.3),only screen and (-o-min-device-pixel-ratio: 1.3/1),only screen and (min-resolution: 125dpi),only screen and (min-resolution: 1.3dppx){background-image:url(img_5x.png);}";
Assert.AreEqual(expected, actual);
}
}
}
Loading

0 comments on commit 641937a

Please sign in to comment.