Skip to content

Create SIL.ExCSS nuget package #1

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -158,3 +158,7 @@ $RECYCLE.BIN/
# Mac desktop service store files
.DS_Store
/packages
.idea/
.vs/
.vscode/
nuget.exe
Binary file removed .nuget/ExCSS.nupkg
Binary file not shown.
Binary file removed .nuget/NuGet.exe
Binary file not shown.
59 changes: 56 additions & 3 deletions .nuget/NuGet.targets
Original file line number Diff line number Diff line change
@@ -32,13 +32,33 @@
$(BuildDependsOn);
BuildPackage;
</BuildDependsOn>

<!-- Download NuGet.exe if it does not already exist -->
<DownloadNuGetExe Condition=" '$(DownloadNuGetExe)' == '' ">true</DownloadNuGetExe>
<NuGetExeUrl>https://dist.nuget.org/win-x86-commandline/latest/nuget.exe</NuGetExeUrl>
</PropertyGroup>

<Target Name="CheckPrerequisites">
<!-- Raise an error if we're unable to locate nuget.exe -->
<Error Condition="!Exists('$(NuGetExePath)')" Text="Unable to locate '$(NuGetExePath)'" />
<Error Condition="'$(DownloadNuGetExe)' != 'true' AND !Exists('$(NuGetExePath)')"
Text="Unable to locate '$(NuGetExePath)'" />
<!--
Take advantage of MsBuild's build dependency tracking to make sure that we only ever download nuget.exe once.
This effectively acts as a lock that makes sure that the download operation will only happen once and all
parallel builds will have to wait for it to complete.
-->
<MsBuild Targets="_DownloadNuGet" Projects="$(MSBuildThisFileFullPath)"
Properties="Configuration=NOT_IMPORTANT;DownloadNuGetExe=$(DownloadNuGetExe)" />
</Target>

<Target Name="_DownloadNuGet" Condition=" '$(DownloadNuGetExe)' == 'true' AND !Exists('$(NuGetExePath)')">
<DownloadNuGet OutputFilename="$(NuGetExePath)"
Condition="'$(OS)' == 'Windows_NT'" />
<Exec Command="wget $(NuGetExeUrl) || curl -O -L $(NuGetExeUrl)"
WorkingDirectory="$(NuGetToolsPath)"
Condition="'$(OS)' != 'Windows_NT'" />
</Target>

<Target Name="RestorePackages" DependsOnTargets="CheckPrerequisites">
<Exec Command="$(RestoreCommand)"
LogStandardErrorAsError="true"
@@ -49,4 +69,37 @@
<Exec Command="$(BuildCommand)"
LogStandardErrorAsError="true" />
</Target>

<UsingTask TaskName="DownloadNuGet" TaskFactory="CodeTaskFactory"
AssemblyFile="$(MSBuildToolsPath)\Microsoft.Build.Tasks.v4.0.dll"
Condition=" '$(OS)' == 'Windows_NT' ">
<ParameterGroup>
<OutputFilename ParameterType="System.String" Required="true" />
</ParameterGroup>
<Task>
<Reference Include="System.Core" />
<Using Namespace="System" />
<Using Namespace="System.IO" />
<Using Namespace="System.Net" />
<Using Namespace="Microsoft.Build.Framework" />
<Using Namespace="Microsoft.Build.Utilities" />
<Code Type="Fragment" Language="cs">
<![CDATA[
try {
OutputFilename = Path.GetFullPath(OutputFilename);

Log.LogMessage("Downloading latest version of NuGet.exe...");
WebClient webClient = new WebClient();
webClient.DownloadFile("$(NuGetExeUrl)", OutputFilename);

return true;
}
catch (Exception ex) {
Log.LogErrorFromException(ex);
return false;
}
]]>
</Code>
</Task>
</UsingTask>
</Project>
4 changes: 4 additions & 0 deletions ExCSS.sln
Original file line number Diff line number Diff line change
@@ -2,6 +2,10 @@
Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio 2012
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution Items", "{ED10223D-313C-4760-B378-2B3C7DCE3B94}"
ProjectSection(SolutionItems) = preProject
.nuget\NuGet.Config = .nuget\NuGet.Config
.nuget\NuGet.targets = .nuget\NuGet.targets
EndProjectSection
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ExCSS.Tests", "ExCSS.Tests\ExCSS.Tests.csproj", "{5FBCD1EE-C5B6-4734-9FE0-3BA2CD14E85A}"
EndProject
5 changes: 3 additions & 2 deletions ExCSS/ExCSS.csproj
Original file line number Diff line number Diff line change
@@ -34,6 +34,7 @@
<TargetFrameworkProfile />
<SolutionDir Condition="$(SolutionDir) == '' Or $(SolutionDir) == '*Undefined*'">..\..\ExCSS\</SolutionDir>
<RestorePackages>true</RestorePackages>
<SignAssembly>true</SignAssembly>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<DebugSymbols>true</DebugSymbols>
@@ -190,7 +191,7 @@
<PropertyGroup>
<ExCSSSemVer>$(ExCSSAssemblyVersion.SubString(0, $(ExCSSAssemblyVersion.LastIndexOf('.'))))</ExCSSSemVer>
</PropertyGroup>
<Exec Command="$(SolutionDir).nuget\nuget pack $(SolutionDir)\NuSpec\ExCSS.nuspec -Version $(ExCSSSemVer) -o $(SolutionDir)\NuSpec" />
<Message Text="$(SolutionDir).nuget\nuget pack $(SolutionDir)\NuSpec\ExCSS.nuspec -Version $(ExCSSSemVer)" Importance="high" />
<Exec Command="$(SolutionDir).nuget\nuget pack $(SolutionDir)\NuSpec\SIL.ExCSS.nuspec -Version $(ExCSSSemVer) -OutputDirectory $(SolutionDir)\NuSpec" />
<Message Text="$(SolutionDir).nuget\nuget pack $(SolutionDir)\NuSpec\SIL.ExCSS.nuspec -Version $(ExCSSSemVer)" Importance="high" />
</Target>
</Project>
6 changes: 3 additions & 3 deletions NuSpec/ExCSS.nuspec → NuSpec/SIL.ExCSS.nuspec
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
<?xml version="1.0" encoding="utf-8"?>
<package xmlns="http://schemas.microsoft.com/packaging/2010/07/nuspec.xsd">
<metadata>
<id>ExCSS</id>
<id>SIL.ExCSS</id>
<version>$version$</version>
<title>ExCSS Stylesheet Parser</title>
<authors>Tyler Brinks</authors>
<owners>Tyler Brinks</owners>
<projectUrl>https://github.com/TylerBrinks/ExCSS</projectUrl>
<iconUrl>https://github.com/TylerBrinks/ExCSS/raw/master/ExCSS.png</iconUrl>
<projectUrl>https://github.com/jasonleenaylor/ExCSS</projectUrl>
<license type="expression">MIT</license>
<requireLicenseAcceptance>false</requireLicenseAcceptance>
<description>ExCSS reads and parses stylesheets using CSS 3 and CSS 2 selector specifications, and is easily queryable from LINQ using its simple and readable object model.</description>
<summary>Parse CSS 3 and CSS 2 stylesheets into an easily usable and LINQ-friendly object model. It's #BADA55!</summary>
37 changes: 19 additions & 18 deletions readme.md
Original file line number Diff line number Diff line change
@@ -1,39 +1,40 @@
#ExCSS StyleSheet Parser for .NET - It's \#BADA55!#
# ExCSS StyleSheet Parser for .NET - It's _BADA55!_

ExCSS (Pronoundec Excess) is a CSS 2.1 and CSS 3 parser for .NET.

The goal of ExCSS is to make it easy to read and parse stylesheets into a friendly object model with full LINQ support.

#Version 2.0#
Version 2 has been rewritten from the ground up! Unlike v1 which used Coco/r to generate a lexer and parser, version 2 is
## Version 2.0

Version 2 has been rewritten from the ground up! Unlike v1 which used Coco/r to generate a lexer and parser, version 2 is
written entirely by hand. This gives the new parser an incredibly fine grained level of detail when parsing some of the more
unusual edge cases for CSS 3 selectors.

#NuGet#
## NuGet

Install the pagckage from the NuGet Package Manager or via command line

Install-Package ExCSS
Install-Package SIL.ExCSS

## Lexing and Parsing - How it all Works

#Lexing and Parsing - How it all Works#
ExCSS uses a Lexer and a Parser based on a CSS3-specific grammar. The Lexer and Parser read CSS text and parse each
character as individual tokens run against a complex set of rules that define what CSS segment each token represents.
ExCSS uses a Lexer and a Parser based on a CSS3-specific grammar. The Lexer and Parser read CSS text and parse each
character as individual tokens run against a complex set of rules that define what CSS segment each token represents.
Once parsed, the input styles sheet is turned into a standard .NET object model. That means it's
fully queryable using Linq to objects.

##A basic example:##
### A basic example

var parser = Parser();
var stylesheet = parser.Parse(".someClass{color: red; background-image: url('/images/logo.png')");
var imageUrl = stylesheet.Rulesets
var parser = Parser();
var stylesheet = parser.Parse(".someClass{color: red; background-image: url('/images/logo.png')");

var imageUrl = stylesheet.Rulesets
.SelectMany(r => r.Declarations)
.FirstOrDefault(d => d.Name.Equals("background-image", StringComparison.InvariantCultureIgnoreCase))
.Term
.ToString(); // Finds the url('/images/logo.png') image url

##CSS 3 Compatible##
The project has a growing suite of tests. Currently the tests account for and pass all CSS Level 3 selector definitions
found in [the W3 CSS 3 Release Candidate documentation](http://www.w3.org/TR/2001/CR-css3-selectors-20011113/)


## CSS 3 Compatible

The project has a growing suite of tests. Currently the tests account for and pass all CSS Level 3 selector definitions
found in [the W3 CSS 3 Release Candidate documentation](http://www.w3.org/TR/2001/CR-css3-selectors-20011113/)