Exemplo n.º 1
0
        public KnapsackHttpHandler_tests()
        {
            var coffeeScriptCompiler = new CoffeeScriptCompiler(File.ReadAllText);

            storage       = IsolatedStorageFile.GetUserStoreForAssembly();
            rootDirectory = Path.GetFullPath(Guid.NewGuid().ToString());

            // Create a fake set of scripts in modules.
            Directory.CreateDirectory(Path.Combine(rootDirectory, "lib"));
            File.WriteAllText(Path.Combine(rootDirectory, "lib", "jquery.js"),
                              "function jQuery(){}");
            File.WriteAllText(Path.Combine(rootDirectory, "lib", "knockout.js"),
                              "function knockout(){}");

            Directory.CreateDirectory(Path.Combine(rootDirectory, "app"));
            File.WriteAllText(Path.Combine(rootDirectory, "app", "widgets.js"),
                              "/// <reference path=\"../lib/jquery.js\"/>\r\n/// <reference path=\"../lib/knockout.js\"/>\r\nfunction widgets(){}");
            File.WriteAllText(Path.Combine(rootDirectory, "app", "main.js"),
                              "/// <reference path=\"widgets.js\"/>\r\nfunction main() {}");
            File.WriteAllText(Path.Combine(rootDirectory, "app", "test.coffee"),
                              "x = 1");

            var builder = new ScriptModuleContainerBuilder(storage, rootDirectory, coffeeScriptCompiler);

            builder.AddModule("lib", null);
            builder.AddModule("app", null);
            scriptModuleContainer = builder.Build();
            scriptModuleContainer.UpdateStorage("scripts.xml");

            var styleBuilder = new StylesheetModuleContainerBuilder(storage, rootDirectory, "/");

            handler = new KnapsackHttpHandler(() => scriptModuleContainer, () => stylesheetModuleContainer, coffeeScriptCompiler);

            httpContext          = new Mock <HttpContextBase>();
            httpRequest          = new Mock <HttpRequestBase>();
            requestHeaders       = new NameValueCollection();
            responseHeaders      = new NameValueCollection();
            httpResponse         = new Mock <HttpResponseBase>();
            responseOutputStream = new MemoryStream();
            cache  = new Mock <HttpCachePolicyBase>();
            server = new Mock <HttpServerUtilityBase>();

            httpRequest.SetupGet(r => r.Headers).Returns(requestHeaders);
            httpResponse.SetupGet(r => r.Headers).Returns(responseHeaders);
            httpResponse.SetupGet(r => r.OutputStream).Returns(responseOutputStream);
            httpResponse.SetupGet(r => r.Cache).Returns(cache.Object);
            httpContext.SetupGet(c => c.Request).Returns(httpRequest.Object);
            httpContext.SetupGet(c => c.Response).Returns(httpResponse.Object);
            httpContext.SetupGet(c => c.Server).Returns(server.Object);

            httpResponse.Setup(r => r.Write(It.IsAny <string>())).Callback <string>(data =>
            {
                var writer = new StreamWriter(responseOutputStream);
                writer.Write(data);
                writer.Flush();
            });
        }
Exemplo n.º 2
0
        static void Main(string[] args)
        {
            if (args.Length == 0)
            {
                Console.WriteLine("Usage: knapsack {path} {output-directory}");
                return;
            }
            var path = args[0];

            if (path.EndsWith("*"))
            {
                path = Path.GetFullPath(path.Substring(0, path.Length - 2)) + "\\";
                var builder = new ScriptModuleContainerBuilder(null, path, new CoffeeScriptCompiler(File.ReadAllText));
                builder.AddModuleForEachSubdirectoryOf("", "");
                var container = builder.Build();
                foreach (var module in container)
                {
                    var outputFilename = Path.GetFullPath(Path.Combine(args[1], module.Path + ".js"));
                    using (var file = new StreamWriter(outputFilename))
                    {
                        var writer = new ScriptModuleWriter(file, path, File.ReadAllText, new CoffeeScriptCompiler(File.ReadAllText));
                        writer.Write(module);
                        file.Flush();
                    }
                }
            }
            else
            {
                path = Path.GetFullPath(path);
                var builder          = new UnresolvedScriptModuleBuilder(path);
                var unresolvedModule = builder.Build("", null); // path is the module, so no extra path is required.
                var module           = UnresolvedModule.ResolveAll(new[] { unresolvedModule }).First();

                var writer = new ScriptModuleWriter(Console.Out, path, File.ReadAllText, new CoffeeScriptCompiler(File.ReadAllText));
                writer.Write(module);
            }
        }
Exemplo n.º 3
0
        static void Main(string[] args)
        {
            if (args.Length == 0)
            {
                Console.WriteLine("Usage: cassette {path} {output-directory}");
                return;
            }
            var path = args[0];
            if (path.EndsWith("*"))
            {
                path = Path.GetFullPath(path.Substring(0, path.Length - 2)) + "\\";
                var builder = new ScriptModuleContainerBuilder(null, path, new CoffeeScriptCompiler(File.ReadAllText));
                builder.AddModuleForEachSubdirectoryOf("", "");
                var container = builder.Build();
                foreach (var module in container)
                {
                    var outputFilename = Path.GetFullPath(Path.Combine(args[1], module.Path + ".js"));
                    using (var file = new StreamWriter(outputFilename))
                    {
                        var writer = new ScriptModuleWriter(file, path, File.ReadAllText, new CoffeeScriptCompiler(File.ReadAllText));
                        writer.Write(module);
                        file.Flush();
                    }
                }
            }
            else
            {
                path = Path.GetFullPath(path);
                var builder = new UnresolvedScriptModuleBuilder(path);
                var unresolvedModule = builder.Build("", null); // path is the module, so no extra path is required.
                var module = UnresolvedModule.ResolveAll(new[] { unresolvedModule }).First();

                var writer = new ScriptModuleWriter(Console.Out, path, File.ReadAllText, new CoffeeScriptCompiler(File.ReadAllText));
                writer.Write(module);
            }
        }
Exemplo n.º 4
0
        ModuleContainer BuildScriptModuleContainer(IsolatedStorageFile storage, KnapsackSection config)
        {
            var builder = new ScriptModuleContainerBuilder(storage, HttpRuntime.AppDomainAppPath, coffeeScriptCompiler);

            return(BuildModuleContainer(builder, config.Scripts, "scripts"));
        }
Exemplo n.º 5
0
 ModuleContainer BuildScriptModuleContainer(IsolatedStorageFile storage, KnapsackSection config)
 {
     var builder = new ScriptModuleContainerBuilder(storage, HttpRuntime.AppDomainAppPath, coffeeScriptCompiler);
     return BuildModuleContainer(builder, config.Scripts, "scripts");
 }