Skip to content

Commit 2f45d83

Browse files
committed
Support for Cassette
1 parent a2e8479 commit 2f45d83

26 files changed

+937
-9
lines changed

README.md

+5-3
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,10 @@ Coming soon!**
1010
Features
1111
=========
1212
* On-the-fly **JSX to JavaScript compilation** for development purposes
13-
* JSX to JavaScript precompilation via
14-
[ASP.NET Bundling and Minification](http://www.asp.net/mvc/tutorials/mvc-4/bundling-and-minification)
13+
* JSX to JavaScript compilation via popular minification/combination
14+
libraries:
15+
* [ASP.NET Bundling and Minification](http://www.asp.net/mvc/tutorials/mvc-4/bundling-and-minification)
16+
* [Cassette](http://getcassette.net/)
1517
* **Server-side component rendering** to make your initial render super-fast
1618
(experimental!)
1719

@@ -23,7 +25,7 @@ Requirements
2325
* A JavaScript engine:
2426
* [MsieJavaScriptEngine](https://github.com/Taritsyn/MsieJavaScriptEngine) -
2527
Windows only and requires IE9 or above to be installed on the server
26-
* ~~[Jint](https://github.com/sebastienros/jint) - Slower but cross-platform~~
28+
* Other engines coming soon
2729

2830
Installation
2931
============

build.proj

+1
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ of patent rights can be found in the PATENTS file in the same directory.
2424
<PackageAssemblies Include="React.Web" />
2525
<PackageAssemblies Include="React.Web.Mvc4" />
2626
<PackageAssemblies Include="React.WebOptimization" />
27+
<PackageAssemblies Include="Cassette.React" />
2728
</ItemGroup>
2829

2930
<Import Project="$(MSBuildProjectDirectory)\tools\MSBuildTasks\MSBuild.Community.Tasks.Targets" />
+83
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,83 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<Project ToolsVersion="12.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
3+
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
4+
<PropertyGroup>
5+
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
6+
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
7+
<ProjectGuid>{F591F1E8-3D6B-494A-B72A-152FCCA6210D}</ProjectGuid>
8+
<OutputType>Library</OutputType>
9+
<AppDesignerFolder>Properties</AppDesignerFolder>
10+
<RootNamespace>Cassette.React</RootNamespace>
11+
<AssemblyName>Cassette.React</AssemblyName>
12+
<TargetFrameworkVersion>v4.0</TargetFrameworkVersion>
13+
<FileAlignment>512</FileAlignment>
14+
</PropertyGroup>
15+
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
16+
<DebugSymbols>true</DebugSymbols>
17+
<DebugType>full</DebugType>
18+
<Optimize>false</Optimize>
19+
<OutputPath>..\..\bin\Debug\Cassette.React\</OutputPath>
20+
<DefineConstants>DEBUG;TRACE</DefineConstants>
21+
<ErrorReport>prompt</ErrorReport>
22+
<WarningLevel>4</WarningLevel>
23+
<NoWarn>1607</NoWarn>
24+
<DocumentationFile>..\..\bin\Debug\Cassette.React\Cassette.React.XML</DocumentationFile>
25+
</PropertyGroup>
26+
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
27+
<DebugType>pdbonly</DebugType>
28+
<Optimize>true</Optimize>
29+
<OutputPath>..\..\bin\Release\Cassette.React\</OutputPath>
30+
<DefineConstants>TRACE</DefineConstants>
31+
<ErrorReport>prompt</ErrorReport>
32+
<WarningLevel>4</WarningLevel>
33+
<NoWarn>1607</NoWarn>
34+
<TreatWarningsAsErrors>true</TreatWarningsAsErrors>
35+
<DocumentationFile>..\..\bin\Release\Cassette.React\Cassette.React.XML</DocumentationFile>
36+
</PropertyGroup>
37+
<ItemGroup>
38+
<Reference Include="AjaxMin">
39+
<HintPath>..\packages\AjaxMin.4.84.4790.14417\lib\net40\AjaxMin.dll</HintPath>
40+
</Reference>
41+
<Reference Include="Cassette">
42+
<HintPath>..\packages\Cassette.2.4.1\lib\net40-client\Cassette.dll</HintPath>
43+
</Reference>
44+
<Reference Include="System" />
45+
<Reference Include="System.Core" />
46+
<Reference Include="System.Xml.Linq" />
47+
<Reference Include="System.Data.DataSetExtensions" />
48+
<Reference Include="Microsoft.CSharp" />
49+
<Reference Include="System.Data" />
50+
<Reference Include="System.Xml" />
51+
</ItemGroup>
52+
<ItemGroup>
53+
<Compile Include="..\SharedAssemblyInfo.cs">
54+
<Link>Properties\SharedAssemblyInfo.cs</Link>
55+
</Compile>
56+
<Compile Include="..\SharedAssemblyVersionInfo.cs">
57+
<Link>Properties\SharedAssemblyVersionInfo.cs</Link>
58+
</Compile>
59+
<Compile Include="InsertIntoPipelineJsxBundleProcessor.cs" />
60+
<Compile Include="JsxBundleProcessor.cs" />
61+
<Compile Include="JsxCompiler.cs" />
62+
<Compile Include="JsxFileSearchModifier.cs" />
63+
<Compile Include="Properties\AssemblyInfo.cs" />
64+
</ItemGroup>
65+
<ItemGroup>
66+
<None Include="Cassette.React.nutrans" />
67+
<None Include="packages.config" />
68+
</ItemGroup>
69+
<ItemGroup>
70+
<ProjectReference Include="..\React\React.csproj">
71+
<Project>{d0cc8a22-cee6-485c-924b-1f94426fea59}</Project>
72+
<Name>React</Name>
73+
</ProjectReference>
74+
</ItemGroup>
75+
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
76+
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
77+
Other similar extension points exist, see Microsoft.Common.targets.
78+
<Target Name="BeforeBuild">
79+
</Target>
80+
<Target Name="AfterBuild">
81+
</Target>
82+
-->
83+
</Project>
+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
<?xml version="1.0"?>
2+
<!--
3+
Copyright (c) 2014, Facebook, Inc.
4+
All rights reserved.
5+
6+
This source code is licensed under the BSD-style license found in the
7+
LICENSE file in the root directory of this source tree. An additional grant
8+
of patent rights can be found in the PATENTS file in the same directory.
9+
-->
10+
<package
11+
xmlns="http://schemas.microsoft.com/packaging/2010/07/nuspec.xsd"
12+
xmlns:xdt="http://schemas.microsoft.com/XML-Document-Transform">
13+
<metadata>
14+
<title xdt:Transform="Insert">ReactJS.NET - JSX for Cassette</title>
15+
<description xdt:Transform="Insert">
16+
Allows you to compile JSX to JavaScript using Cassette
17+
</description>
18+
<tags xdt:Transform="Replace">asp.net mvc asp jquery javascript js react facebook reactjs cassette</tags>
19+
</metadata>
20+
21+
</package>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
/*
2+
* Copyright (c) 2014, Facebook, Inc.
3+
* All rights reserved.
4+
*
5+
* This source code is licensed under the BSD-style license found in the
6+
* LICENSE file in the root directory of this source tree. An additional grant
7+
* of patent rights can be found in the PATENTS file in the same directory.
8+
*/
9+
10+
using Cassette.BundleProcessing;
11+
using Cassette.Scripts;
12+
13+
namespace Cassette.React
14+
{
15+
/// <summary>
16+
/// Inserts the <see cref="JsxBundleProcessor" /> into the script bundle pipeline
17+
/// </summary>
18+
public class InsertIntoPipelineJsxBundleProcessor : IBundlePipelineModifier<ScriptBundle>
19+
{
20+
/// <summary>
21+
/// Modifies the specified pipeline.
22+
/// </summary>
23+
/// <param name="pipeline">The pipeline.</param>
24+
/// <returns>The pipeline</returns>
25+
public IBundlePipeline<ScriptBundle> Modify(IBundlePipeline<ScriptBundle> pipeline)
26+
{
27+
var index = pipeline.IndexOf<ParseJavaScriptReferences>();
28+
pipeline.Insert<JsxBundleProcessor>(index + 1);
29+
return pipeline;
30+
}
31+
}
32+
}
+50
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
/*
2+
* Copyright (c) 2014, Facebook, Inc.
3+
* All rights reserved.
4+
*
5+
* This source code is licensed under the BSD-style license found in the
6+
* LICENSE file in the root directory of this source tree. An additional grant
7+
* of patent rights can be found in the PATENTS file in the same directory.
8+
*/
9+
10+
using System;
11+
using Cassette.BundleProcessing;
12+
using Cassette.Scripts;
13+
14+
namespace Cassette.React
15+
{
16+
/// <summary>
17+
/// Handles processing of script bundles in Cassette. Adds a <see cref="JsxCompiler" />
18+
/// for all .jsx files.
19+
/// </summary>
20+
public class JsxBundleProcessor : IBundleProcessor<ScriptBundle>
21+
{
22+
private readonly CassetteSettings _settings;
23+
24+
/// <summary>
25+
/// Initializes a new instance of the <see cref="JsxBundleProcessor"/> class.
26+
/// </summary>
27+
/// <param name="settings">Cassette settings.</param>
28+
public JsxBundleProcessor(CassetteSettings settings)
29+
{
30+
_settings = settings;
31+
}
32+
33+
/// <summary>
34+
/// Processes the specified bundle. Adds a <see cref="JsxCompiler"/> for all .jsx files.
35+
/// </summary>
36+
/// <param name="bundle">The bundle.</param>
37+
public void Process(ScriptBundle bundle)
38+
{
39+
foreach (var asset in bundle.Assets)
40+
{
41+
if (asset.Path.EndsWith(".jsx", StringComparison.InvariantCultureIgnoreCase))
42+
{
43+
asset.AddAssetTransformer(
44+
new CompileAsset(new JsxCompiler(), _settings.SourceDirectory)
45+
);
46+
}
47+
}
48+
}
49+
}
50+
}

src/Cassette.React/JsxCompiler.cs

+33
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
/*
2+
* Copyright (c) 2014, Facebook, Inc.
3+
* All rights reserved.
4+
*
5+
* This source code is licensed under the BSD-style license found in the
6+
* LICENSE file in the root directory of this source tree. An additional grant
7+
* of patent rights can be found in the PATENTS file in the same directory.
8+
*/
9+
10+
using System.Linq;
11+
using React;
12+
13+
namespace Cassette.React
14+
{
15+
/// <summary>
16+
/// Handles compilation of JSX in Cassette
17+
/// </summary>
18+
public class JsxCompiler : ICompiler
19+
{
20+
/// <summary>
21+
/// Compiles the specified JSX file into JavaScript
22+
/// </summary>
23+
/// <param name="source">The source.</param>
24+
/// <param name="context">The context.</param>
25+
/// <returns>JavaScript</returns>
26+
public CompileResult Compile(string source, CompileContext context)
27+
{
28+
var environment = AssemblyRegistration.Container.Resolve<IReactEnvironment>();
29+
var output = environment.TransformJsx(source);
30+
return new CompileResult(output, Enumerable.Empty<string>());
31+
}
32+
}
33+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
/*
2+
* Copyright (c) 2014, Facebook, Inc.
3+
* All rights reserved.
4+
*
5+
* This source code is licensed under the BSD-style license found in the
6+
* LICENSE file in the root directory of this source tree. An additional grant
7+
* of patent rights can be found in the PATENTS file in the same directory.
8+
*/
9+
10+
using Cassette.Scripts;
11+
12+
namespace Cassette.React
13+
{
14+
/// <summary>
15+
/// Adds *.jsx to the file search path for script bundles.
16+
/// </summary>
17+
public class JsxFileSearchModifier : IFileSearchModifier<ScriptBundle>
18+
{
19+
/// <summary>
20+
/// Modifies the specified file search.
21+
/// </summary>
22+
/// <param name="fileSearch">The file search.</param>
23+
public void Modify(FileSearch fileSearch)
24+
{
25+
fileSearch.Pattern += ";*.jsx";
26+
}
27+
}
28+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
/*
2+
* Copyright (c) 2014, Facebook, Inc.
3+
* All rights reserved.
4+
*
5+
* This source code is licensed under the BSD-style license found in the
6+
* LICENSE file in the root directory of this source tree. An additional grant
7+
* of patent rights can be found in the PATENTS file in the same directory.
8+
*/
9+
10+
using System.Reflection;
11+
using System.Runtime.InteropServices;
12+
13+
[assembly: AssemblyTitle("Cassette.React")]
14+
[assembly: AssemblyDescription("Cassette integration for ReactJS.NET")]
15+
[assembly: ComVisible(false)]
16+
[assembly: Guid("06e9b63a-8a35-4eb6-b673-b7805b0dd31c")]

src/Cassette.React/packages.config

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<packages>
3+
<package id="AjaxMin" version="4.84.4790.14417" targetFramework="net40" />
4+
<package id="Cassette" version="2.4.1" targetFramework="net40" />
5+
</packages>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
/*
2+
* Copyright (c) 2014, Facebook, Inc.
3+
* All rights reserved.
4+
*
5+
* This source code is licensed under the BSD-style license found in the
6+
* LICENSE file in the root directory of this source tree. An additional grant
7+
* of patent rights can be found in the PATENTS file in the same directory.
8+
*/
9+
10+
using Cassette;
11+
using Cassette.Scripts;
12+
using Cassette.Stylesheets;
13+
14+
namespace React.Sample.Cassette
15+
{
16+
/// <summary>
17+
/// Configures the Cassette asset bundles for the web application.
18+
/// </summary>
19+
public class CassetteBundleConfiguration : IConfiguration<BundleCollection>
20+
{
21+
public void Configure(BundleCollection bundles)
22+
{
23+
// Configure your bundles here...
24+
// Please read http://getcassette.net/documentation/configuration
25+
26+
bundles.Add<StylesheetBundle>("main.css", "Content/Sample.css");
27+
bundles.Add<ScriptBundle>("main.js", "Content/Sample.jsx");
28+
}
29+
}
30+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
/*
2+
* Copyright (c) 2014, Facebook, Inc.
3+
* All rights reserved.
4+
*
5+
* This source code is licensed under the BSD-style license found in the
6+
* LICENSE file in the root directory of this source tree. An additional grant
7+
* of patent rights can be found in the PATENTS file in the same directory.
8+
*/
9+
10+
body {
11+
font-family: Calibri, Verdana, sans-serif;
12+
}
13+
14+
.commentList {
15+
list-style-type: none;
16+
margin: 0;
17+
padding: 0;
18+
}
19+
20+
.commentList li {
21+
border-bottom: 1px solid #999;
22+
padding: 0.5em 0;
23+
}

0 commit comments

Comments
 (0)