コード例 #1
0
 public PageModel(AP actionProvider, IRequest request, AppContentResponder appContentResponder) : this(request,
                                                                                                       appContentResponder)
 {
     ViewModel = new ViewModel <AP> {
         ActionProvider = actionProvider
     };
 }
コード例 #2
0
ファイル: HtmlRenderer.cs プロジェクト: ThreeHeadz/Bam.Net
        public override void Render(object toRender, Stream output)
        {
            AppContentResponder appContentResponder = ContentResponder.AppContentResponders[AppName];
            ITemplateRenderer   dustRenderer        = appContentResponder.AppTemplateRenderer;
            string templateName = GetTemplateName(toRender);
            string templates    = dustRenderer.CompiledTemplates;
            string result       = DustScript.Render(templates, templateName, toRender);

            string layout;

            byte[] data;
            if (HttpArgs.Has("layout", out layout))
            {
                string      absolutePath = ExecutionRequest.Request.Url.AbsolutePath;
                string      extension    = Path.GetExtension(absolutePath);
                string      path         = absolutePath.Truncate(extension.Length);
                LayoutModel layoutModel  = appContentResponder.GetLayoutModelForPath(path);
                layoutModel.LayoutName  = layout;
                layoutModel.PageContent = result;
                MemoryStream ms = new MemoryStream();
                appContentResponder.CommonTemplateRenderer.RenderLayout(layoutModel, ms);
                ms.Seek(0, SeekOrigin.Begin);
                data = ms.GetBuffer();
            }
            else
            {
                data = Encoding.UTF8.GetBytes(result);
            }
            output.Write(data, 0, data.Length);
        }
コード例 #3
0
        public void AppContentConfShouldNotBeNull()
        {
            ContentResponder    content    = new ContentResponder(BamConf.Load(), CreateLogger());
            AppContentResponder appContent = new AppContentResponder(content, new AppConf("Monkey"));

            Expect.IsNotNull(appContent.AppConf);
        }
コード例 #4
0
        public void AppContentNameShouldNotBeNull()
        {
            ContentResponder    content    = new ContentResponder(BamConf.Load(), CreateLogger());
            AppContentResponder appContent = new AppContentResponder(content, new AppConf("Monkey"));

            Expect.IsNotNull(appContent.ApplicationName);
            Expect.AreEqual("Monkey", appContent.ApplicationName);
        }
コード例 #5
0
 public ApplicationErrorHandler(AppContentResponder appResponder)
 {
     AppContentResponder = appResponder;
     FileExtensions      = new HashSet <string>()
     {
         ".html"
     };
 }
コード例 #6
0
        public void RegisterApp()
        {
            BamServer     server = new BamServer(BamConf.Load(GetRoot()));
            ConsoleLogger logger = new ConsoleLogger();

            logger.AddDetails = false;
            logger.UseColors  = true;
            server.Subscribe(logger);
            AppContentResponder app = server.CreateApp(GetArgument("appName"));

            app.Subscribe(logger);
            app.Initialize();
        }
コード例 #7
0
        public void ShouldBeAbleToCompileDustDirectory()
        {
            DirectoryInfo          root             = new DirectoryInfo("c:\\temp\\{0}_"._Format(MethodBase.GetCurrentMethod().Name).RandomLetters(5));
            ContentResponder       content          = GetTestContentResponder(root);
            CommonTemplateRenderer templateRenderer = new CommonTemplateRenderer(content);
            TestMonkey             monkey           = new TestMonkey();

            templateRenderer.Render(monkey);
            AppContentResponder appResponder = new AppContentResponder(content, new AppConf("Test"));
            CommonDustRenderer  renderer     = new CommonDustRenderer(appResponder);

            Expect.IsTrue(!string.IsNullOrEmpty(renderer.CombinedCompiledTemplates));
            OutLine(renderer.CombinedCompiledTemplates);
        }
コード例 #8
0
        public void CreateClientApplication()
        {
            BamServer     server = new BamServer(BamConf.Load(GetRoot()));
            ConsoleLogger logger = new ConsoleLogger()
            {
                AddDetails = false,
                UseColors  = true
            };

            server.Subscribe(logger);
            AppContentResponder app = server.CreateApp(GetArgument("appName"));

            app.Subscribe(logger);
            app.Initialize();
        }
コード例 #9
0
ファイル: UnitTests.cs プロジェクト: ThreeHeadz/Bam.Net
        public void AppContentResponderShouldCombineAppScriptsOnInitialize()
        {
            string        testAppName = MethodBase.GetCurrentMethod().Name;
            DirectoryInfo dir         = new DirectoryInfo("C:\\temp\\{0}_"._Format(testAppName).RandomLetters(4));

            CreateTestRootAndSetDefaultConfig(dir);
            BamServer server = CreateServer(dir.FullName);

            server.Initialize();
            AppContentResponder appResponder = server.CreateApp(testAppName, null, 9191);

            appResponder.Logger = new ConsoleLogger();
            appResponder.Logger.StartLoggingThread();
            string jsGuid        = Guid.NewGuid().ToString().Replace("-", "");
            string pageGuid      = Guid.NewGuid().ToString().Replace("-", "");
            string viewModelGuid = Guid.NewGuid().ToString().Replace("-", "");

            string testJsName          = "testScript_{0}.js"._Format(jsGuid);
            string testPageJsName      = "testPageScript_{0}.js"._Format(pageGuid);
            string testViewModelJsName = "testViewModelScript_{0}.js"._Format(viewModelGuid);

            appResponder.AppRoot.WriteFile("~/js/{0}"._Format(testJsName), "function _" + jsGuid + "(){};");
            appResponder.AppRoot.WriteFile("~/pages/{0}"._Format(testPageJsName), "function _" + pageGuid + "(){};");
            appResponder.AppRoot.WriteFile("~/viewModels/{0}"._Format(testViewModelJsName), "function _" + viewModelGuid + "(){};");
            appResponder.Initialize();
            string scriptPath;
            string minAppScriptPath;

            Expect.IsTrue(appResponder.AppRoot.FileExists("~/{0}.js"._Format(testAppName), out scriptPath));
            Expect.IsTrue(appResponder.AppRoot.FileExists("~/{0}.min.js"._Format(testAppName), out minAppScriptPath));
            string script    = File.ReadAllText(scriptPath);
            string minScript = File.ReadAllText(minAppScriptPath);

            Expect.IsTrue(script.Contains(jsGuid), "js guid wasn't in the script");
            Expect.IsTrue(script.Contains(pageGuid), "page guid wasn't in the script");
            Expect.IsTrue(script.Contains(viewModelGuid), "viewModel guid wasn't in the scirpt");

            Expect.IsTrue(minScript.Contains(jsGuid), "js guid wasn't in the script");
            Expect.IsTrue(minScript.Contains(pageGuid), "page guid wasn't in the script");
            Expect.IsTrue(minScript.Contains(viewModelGuid), "viewModel guid wasn't in the scirpt");

            _directoriesToDelete.Add(dir.FullName);
        }
コード例 #10
0
        public void AppContentInitializeShouldSetupFiles()
        {
            BamConf       conf = new BamConf();
            DirectoryInfo root = new DirectoryInfo("c:\\temp\\{0}_"._Format(MethodBase.GetCurrentMethod().Name).RandomLetters(5));

            conf.ContentRoot = root.FullName;
            ContentResponder    content    = new ContentResponder(conf, CreateLogger());
            AppConf             appConf    = new AppConf("monkey");
            AppContentResponder appContent = new AppContentResponder(content, appConf);
            // should create the folder <conf.ContentRoot>\\apps\\monkey
            string appPath = Path.Combine(conf.ContentRoot, "apps", appConf.Name);

            if (Directory.Exists(appPath))
            {
                Directory.Delete(appPath, true);
            }
            Expect.IsFalse(Directory.Exists(appPath));
            appContent.Initialize();
            Expect.IsTrue(Directory.Exists(appPath));
        }
コード例 #11
0
ファイル: UnitTests.cs プロジェクト: ThreeHeadz/Bam.Net
        public void AppContentInitializeShouldCreateAppConfDotJson()
        {
            DirectoryInfo root = new DirectoryInfo("c:\\temp\\{0}_"._Format(MethodBase.GetCurrentMethod().Name).RandomLetters(5));
            BamConf       conf = new BamConf();

            conf.ContentRoot = root.FullName;
            ContentResponder content = new ContentResponder(conf);
            AppConf          appConf = new AppConf("monkey");
            string           layout  = "".RandomLetters(4);

            appConf.DefaultLayout = layout;
            AppContentResponder appContent = new AppContentResponder(content, appConf);
            string appConfPath             = Path.Combine(conf.ContentRoot, "apps", appConf.Name, "appConf.json");

            Expect.IsFalse(File.Exists(appConfPath));

            appContent.Initialize();
            Expect.IsTrue(File.Exists(appConfPath), "appConf.json did not get created");
            AppConf check = appConfPath.FromJsonFile <AppConf>();

            Expect.AreEqual(layout, check.DefaultLayout);
        }
コード例 #12
0
        public override byte[] RenderPage(IRequest request, IResponse response)
        {
            string    path      = request.Url.AbsolutePath;
            RouteInfo routeInfo = GetRouteInfo(request);

            if (routeInfo.IsHomeRequest)
            {
                if (AppRoot.FileExists(DefaultFilePath, out string locatedPath))
                {
                    return(AppContentResponder.GetContent(locatedPath, request, response));
                }
            }
            else
            {
                string absolutePath = AppRoot.GetAbsolutePath(path);
                if (File.Exists(absolutePath))
                {
                    return(AppContentResponder.GetContent(absolutePath, request, response));
                }
            }

            return(RenderNotFound(request, response));
        }
コード例 #13
0
ファイル: HtmlRenderer.cs プロジェクト: ThreeHeadz/Bam.Net
        public string GetTemplateName(object toRender)
        {
            HttpArgs args = HttpArgs;//new HttpArgs(ExecutionRequest.Request.Url.Query);
            string   result;

            args.Has("view", out result);
            if (string.IsNullOrEmpty(result))
            {
                string prefix = string.Empty;
                if (toRender != null)
                {
                    Type typeToRender = toRender.GetType();
                    prefix = "{0}_"._Format(typeToRender.Name);
                    ITemplateRenderer dustRenderer = ContentResponder.AppContentResponders[AppName].AppTemplateRenderer;
                    dustRenderer.EnsureDefaultTemplate(typeToRender);
                }
                AppContentResponder appContentResponder = ContentResponder.AppContentResponders[AppName];
                string domAppName = AppConf.DomApplicationIdFromAppName(appContentResponder.AppConf.Name);

                result = "{0}.{1}default"._Format(domAppName, prefix);
            }

            return(result);
        }
コード例 #14
0
 public StaticContentPageRenderer(AppContentResponder appContentResponder, ITemplateManager commonTemplateManager) : base(appContentResponder, commonTemplateManager)
 {
     FileExtension = ".html";
 }
コード例 #15
0
 public PageModel(IRequest request, AppContentResponder appContentResponder) : base(request, appContentResponder)
 {
     ViewModel = new ViewModel <AP>();
 }
コード例 #16
0
 public PageModel(IEnumerable <object> state, AP actionProvider, IRequest request, AppContentResponder appContentResponder) : this(actionProvider, request, appContentResponder)
 {
     ViewModel.State = state;
 }
コード例 #17
0
 public HandlebarsAppPageRenderer(AppContentResponder appContentResponder, ITemplateManager commonTemplateManager) : base(appContentResponder, commonTemplateManager)
 {
     FileExtension = ".hbs";
 }
コード例 #18
0
ファイル: AppDustRenderer.cs プロジェクト: dekkerb115/Bam.Net
 public AppDustRenderer(AppContentResponder appContent)
     : base(appContent.ContentResponder)
 {
     AppContentResponder = appContent;
     Logger = appContent.Logger;
 }
コード例 #19
0
 public AppTemplateRenderer(AppContentResponder appResponder)
     : base(appResponder.ContentResponder)
 {
     this.AppContentResponder = appResponder;
 }
コード例 #20
0
 public ViewModelRenderer(AppContentResponder appContentResponder, ITemplateManager commonTemplateManager, IApplicationTemplateManager applicationTemplateManager) : base(appContentResponder, commonTemplateManager, applicationTemplateManager)
 {
     this.FileExtension = ".bvm"; // bam view model
     this.Precedence    = 100;
     this.Templates     = new Dictionary <string, Func <object, string> >();
 }
コード例 #21
0
 public HandlebarsAppPageRenderer(AppContentResponder appContentResponder, ITemplateManager commonTemplateManager, IApplicationTemplateManager applicationTemplateManager) : base(appContentResponder, commonTemplateManager, applicationTemplateManager)
 {
     FileExtension    = ".hbs";
     TemplateRenderer = new HandlebarsTemplateRenderer(AppConf.HtmlDir);
 }