Skip to content
Browse files

Removed custom pipeline and used the InsertBefore method. Also remove…

…d some unused code
  • Loading branch information...
1 parent adc01b6 commit 8310cb5a2e096a64ddfd43a9ede2390b0920e48e @nathanpalmer committed
View
169 CassetteStitch/CassetteConfiguration.cs
@@ -1,6 +1,5 @@
using System;
using System.Collections.Generic;
-using System.IO;
using System.Text.RegularExpressions;
using Cassette;
using Cassette.BundleProcessing;
@@ -29,11 +28,7 @@ public void Configure(BundleCollection bundles, CassetteSettings settings)
// {
// //x.Processor = new CommonJSScriptPipeline();
// });
- bundles.Add<ScriptBundle>("Scripts/internal", null, x =>
- {
- x.Processor = new CommonJSScriptPipeline();
- });
-
+ bundles.Add<ScriptBundle>("Scripts/internal", b => b.Processor = new ScriptPipeline().InsertBefore<SortAssetsByDependency>(new StitchProcessor()));
settings.IsDebuggingEnabled = true;
//settings.UrlModifier = new FileExtensionUrlModifier();
@@ -51,166 +46,4 @@ public void Configure(BundleCollection bundles, CassetteSettings settings)
// Cassette minifies scripts for you. So those files are never used.
}
}
-
- public class CommonJSScriptPipeline : ScriptPipeline
- {
- public CommonJSScriptPipeline()
- {
- CompileCoffeeScript = false;
- }
-
- protected override IEnumerable<IBundleProcessor<ScriptBundle>> CreatePipeline(ScriptBundle bundle, CassetteSettings settings)
- {
- yield return new AssignScriptRenderer();
- ////if (bundle.IsFromCache) yield break;
-
- //yield return new ParseJavaScriptReferences();
- //if (CompileCoffeeScript)
- //{
- // yield return new ParseCoffeeScriptReferences();
- // yield return new CompileCoffeeScript(CoffeeScriptCompiler);
- //}
- yield return new StitchProcessor();
- //yield return new SortAssetsByDependency();
- //if (!settings.IsDebuggingEnabled)
- //{
- // yield return new ConcatenateAssets();
- // yield return new MinifyAssets(Minifier);
- //}
- }
- }
-
- public class StitchProcessor : IBundleProcessor<Bundle>
- {
- public void Process(Bundle bundle, CassetteSettings settings)
- {
- foreach(var asset in bundle.Assets)
- {
- if (asset.SourceFile.FullPath.EndsWith(".js", StringComparison.OrdinalIgnoreCase))
- {
- asset.AddAssetTransformer(new StitchTransformer());
- //var result = asset.OpenStream();
- //using (var input = new StreamReader(result))
- //{
- // var x = input.ReadToEnd();
- //}
- }
- }
- }
- }
-
- public class StitchTransformer : IAssetTransformer
- {
- public Func<Stream> Transform(Func<Stream> openSourceStream, IAsset asset)
- {
- const string Identifier = "require";
-
- return delegate
- {
- using (var input = new StreamReader(openSourceStream()))
- {
- var result = @"
-(function(/*! Stitch !*/) {
- if (!this." + Identifier + @") {
- var modules = {}, cache = {}, require = function(name, root) {
- var module = cache[name], path = expand(root, name), fn;
- if (module) {
- return module;
- } else if (fn = modules[path] || modules[path = expand(path, './index')]) {
- module = {id: name, exports: {}};
- try {
- cache[name] = module.exports;
- fn(module.exports, function(name) {
- return require(name, dirname(path));
- }, module);
- return cache[name] = module.exports;
- } catch (err) {
- delete cache[name];
- throw err;
- }
- } else {
- throw 'module \'' + name + '\' not found';
- }
- }, expand = function(root, name) {
- var results = [], parts, part;
- if (/^\.\.?(\/|$)/.test(name)) {
- parts = [root, name].join('/').split('/');
- } else {
- parts = name.split('/');
- }
- for (var i = 0, length = parts.length; i < length; i++) {
- part = parts[i];
- if (part == '..') {
- results.pop();
- } else if (part != '.' && part != '') {
- results.push(part);
- }
- }
- return results.join('/');
- }, dirname = function(path) {
- return path.split('/').slice(0, -1).join('/');
- };
- this." + Identifier + @" = function(name) {
- return require(name, '');
- }
- this." + Identifier + @".define = function(bundle) {
- for (var key in bundle)
- modules[key] = bundle[key];
- };
- }
- return this." + Identifier + @".define;
-}).call(this)({
-" + input.ReadToEnd() + @"
-});";
-
- return AsStream(result);
- }
- };
- }
-
- static Stream AsStream(string s)
- {
- var source = new MemoryStream();
- var writer = new StreamWriter(source);
- writer.Write(s);
- writer.Flush();
- source.Position = 0;
- return source;
- }
- }
-
- public class FileExtensionUrlModifier : IUrlModifier
- {
- public string Modify(string url)
- {
- var uri = new Uri("http://localhost/"+url);
- var name = uri.Segments[uri.Segments.Length - 1];
- var path = uri.LocalPath.Replace(name, "");
- var extension = name.LastIndexOf(".") >= 0 ? name.Substring(name.LastIndexOf(".")) : "";
- name = name.Replace(extension, "");
- var hash = uri.Query.Substring(1);
- var filename = string.Format("{1}-{0}{2}", name, hash, extension);
- var modified = string.Format("{0}{1}", path, filename);
-
- return modified;
- }
- }
-
- public class FileExtensionUrlGenerator : IUrlGenerator
- {
- public string CreateBundleUrl(Bundle bundle)
- {
- throw new NotImplementedException();
- }
-
- public string CreateAssetUrl(IAsset asset)
- {
- throw new NotImplementedException();
- }
-
- public string CreateRawFileUrl(string filename, string hash)
- {
- throw new NotImplementedException();
- }
- }
}
View
2 CassetteStitch/CassetteStitch.csproj
@@ -93,6 +93,8 @@
<DependentUpon>Global.asax</DependentUpon>
</Compile>
<Compile Include="Properties\AssemblyInfo.cs" />
+ <Compile Include="StitchProcessor.cs" />
+ <Compile Include="StitchTransformer.cs" />
</ItemGroup>
<ItemGroup>
<Content Include="Content\themes\base\images\ui-bg_flat_0_aaaaaa_40x100.png" />
View
26 CassetteStitch/StitchProcessor.cs
@@ -0,0 +1,26 @@
+using System;
+using Cassette;
+using Cassette.BundleProcessing;
+using Cassette.Configuration;
+
+namespace CassetteStitch
+{
+ public class StitchProcessor : IBundleProcessor<Bundle>
+ {
+ public void Process(Bundle bundle, CassetteSettings settings)
+ {
+ foreach(var asset in bundle.Assets)
+ {
+ if (asset.SourceFile.FullPath.EndsWith(".js", StringComparison.OrdinalIgnoreCase))
+ {
+ asset.AddAssetTransformer(new StitchTransformer());
+ //var result = asset.OpenStream();
+ //using (var input = new StreamReader(result))
+ //{
+ // var x = input.ReadToEnd();
+ //}
+ }
+ }
+ }
+ }
+}
View
86 CassetteStitch/StitchTransformer.cs
@@ -0,0 +1,86 @@
+using System;
+using System.IO;
+using Cassette;
+
+namespace CassetteStitch
+{
+ public class StitchTransformer : IAssetTransformer
+ {
+ public Func<Stream> Transform(Func<Stream> openSourceStream, IAsset asset)
+ {
+ const string Identifier = "require";
+
+ return delegate
+ {
+ using (var input = new StreamReader(openSourceStream()))
+ {
+ var result = @"
+(function(/*! Stitch !*/) {
+ if (!this." + Identifier + @") {
+ var modules = {}, cache = {}, require = function(name, root) {
+ var module = cache[name], path = expand(root, name), fn;
+ if (module) {
+ return module;
+ } else if (fn = modules[path] || modules[path = expand(path, './index')]) {
+ module = {id: name, exports: {}};
+ try {
+ cache[name] = module.exports;
+ fn(module.exports, function(name) {
+ return require(name, dirname(path));
+ }, module);
+ return cache[name] = module.exports;
+ } catch (err) {
+ delete cache[name];
+ throw err;
+ }
+ } else {
+ throw 'module \'' + name + '\' not found';
+ }
+ }, expand = function(root, name) {
+ var results = [], parts, part;
+ if (/^\.\.?(\/|$)/.test(name)) {
+ parts = [root, name].join('/').split('/');
+ } else {
+ parts = name.split('/');
+ }
+ for (var i = 0, length = parts.length; i < length; i++) {
+ part = parts[i];
+ if (part == '..') {
+ results.pop();
+ } else if (part != '.' && part != '') {
+ results.push(part);
+ }
+ }
+ return results.join('/');
+ }, dirname = function(path) {
+ return path.split('/').slice(0, -1).join('/');
+ };
+ this." + Identifier + @" = function(name) {
+ return require(name, '');
+ }
+ this." + Identifier + @".define = function(bundle) {
+ for (var key in bundle)
+ modules[key] = bundle[key];
+ };
+ }
+ return this." + Identifier + @".define;
+}).call(this)({
+" + input.ReadToEnd() + @"
+});";
+
+ return AsStream(result);
+ }
+ };
+ }
+
+ static Stream AsStream(string s)
+ {
+ var source = new MemoryStream();
+ var writer = new StreamWriter(source);
+ writer.Write(s);
+ writer.Flush();
+ source.Position = 0;
+ return source;
+ }
+ }
+}

0 comments on commit 8310cb5

Please sign in to comment.
Something went wrong with that request. Please try again.