public void UsingDeepObjectAndDictionaryIntKeys()
            {
                var dict = new Dictionary <int, object>();

                dict.Add(0, "Romeo");
                dict.Add(42, "Tango");
                dict.Add(9, "Foxtrot");
                dict.Add(13, "Mike");
                _vdd.Model = new
                {
                    firstname = "John",
                    lastname  = "Doe",
                    Dict      = dict
                };
                // overwriting the ones set in this test class' constructor
                var funcView = _handlebars.Compile("Hello, {{firstName}} {{Lastname}}!\n{{#each Dict}} {{@value}}{{/each}}");

                _compiledView = new CompiledView(funcView, fileHash: null, layout: null);
                _hbsview      = new HandlebarsView(_controllerContext, _compiledView, layouts: null);
                // end overwriting
                string html = GetHtmlFromView();

                Assert.Equal("Hello, John Doe!\n Romeo Tango Foxtrot Mike", html);
                Assert.Equal(4, dict.Keys.Count);                       // making sure the added properties in HandlebarsView weren't added to the dictionary
            }
            public Models()
            {
                _controllerContext = new ControllerContext();

                _handlebars = HandlebarsDotNet.Handlebars.Create();

                _vdd = new ViewDataDictionary();

                // The view. Note that we're also testing for case-insensitivity (lastname is lowercase here, but not in the models).
                var funcView = _handlebars.Compile("Hello, {{FirstName}} {{lastname}}!");

                _compiledView = new CompiledView(funcView, fileHash: null, layout: null);

                _hbsview = new HandlebarsView(_controllerContext, _compiledView, layouts: null);
            }
Ejemplo n.º 3
0
            public void RenderSection_doesnt_throw_for_undefined_section_when_not_required()
            {
                var hbsve = new HandlebarsViewEngine();

                hbsve.RegisterSectionsHelpers();
                var handlebars = Handlebars.Create(hbsve.HandlebarsConfiguration);

                var view   = new CompiledView(handlebars.Compile("Body not rendered."), null, null);
                var layout = new CompiledView(handlebars.Compile("Name: {{rendersection \"name\" required=false}}."), null, null);

                var controllerContext = new ControllerContext();
                var hbsview           = new HandlebarsView(controllerContext, view, new[] { layout });

                var html = GetHtmlFromView(hbsview);

                Assert.Equal("Name: .", html);
            }
Ejemplo n.º 4
0
            public void Sidebar_not_defined_renders_default_content()
            {
                var hbsve = new HandlebarsViewEngine();

                hbsve.RegisterSectionsHelpers();
                var handlebars = Handlebars.Create(hbsve.HandlebarsConfiguration);

                var view   = new CompiledView(handlebars.Compile("No section here."), null, null);
                var layout = new CompiledView(handlebars.Compile(source), null, null);

                var controllerContext = new ControllerContext();
                var hbsview           = new HandlebarsView(controllerContext, view, new[] { layout });

                var html = GetHtmlFromView(hbsview);

                Assert.Equal("<p>Default sidebar content...</p>", html);
            }
Ejemplo n.º 5
0
            public void Sidebar_defined_renders_content_and_chrome()
            {
                var hbsve = new HandlebarsViewEngine();

                hbsve.RegisterSectionsHelpers();
                var handlebars = Handlebars.Create(hbsve.HandlebarsConfiguration);

                var view   = new CompiledView(handlebars.Compile("{{#definesection \"sidebar\"}}Sidebar{{/definesection}}"), null, null);
                var layout = new CompiledView(handlebars.Compile(source), null, null);

                var controllerContext = new ControllerContext();
                var hbsview           = new HandlebarsView(controllerContext, view, new[] { layout });

                var html = GetHtmlFromView(hbsview);

                Assert.Equal("<div id=\"sidebar\">Sidebar</div>", html);
            }
Ejemplo n.º 6
0
            public void DefineSection_can_append()
            {
                var hbsve = new HandlebarsViewEngine();

                hbsve.RegisterSectionsHelpers();
                var handlebars = Handlebars.Create(hbsve.HandlebarsConfiguration);

                var view    = new CompiledView(handlebars.Compile("{{#definesection \"name\"}}From view.{{/definesection}}"), null, null);
                var layout1 = new CompiledView(handlebars.Compile("{{#definesection \"name\" mode=\"append\"}}Appended.{{/definesection}}"), null, null);
                var layout2 = new CompiledView(handlebars.Compile("{{rendersection \"name\"}}"), null, null);

                var controllerContext = new ControllerContext();
                var hbsview           = new HandlebarsView(controllerContext, view, new[] { layout1, layout2 });

                var html = GetHtmlFromView(hbsview);

                Assert.Equal("From view.Appended.", html);
            }
Ejemplo n.º 7
0
        protected void WriteListItem(HtmlTextWriter output, DataRow dr, bool bUseAlt, IDatasetItem DSI)
        {
            Sitecore.Diagnostics.Assert.ArgumentNotNull(this.DatasetRendererItem, "DatasetRendererItem");

            if (_ItemTemplateView == null && !string.IsNullOrEmpty(this.DatasetRendererItem.ListItemTemplate))
                _ItemTemplateView = DatasetViewEngine.Compile(this.DatasetRendererItem.ListItemTemplate);

            if (_AlternateItemTemplateView == null && !string.IsNullOrEmpty(this.DatasetRendererItem.AltListItemTemplate))
                _AlternateItemTemplateView = DatasetViewEngine.Compile(this.DatasetRendererItem.AltListItemTemplate);

            CompiledView cv = null;
            if (!bUseAlt || String.IsNullOrEmpty(this.DatasetRendererItem.AltListItemTemplate))
                cv = _ItemTemplateView;
            else
                cv = _AlternateItemTemplateView;

            if (cv != null)
            {
                var s = cv.ViewText;
                s = DatasetViewEngine.Render(cv, dr, DSI.GetFieldValue, DSI.GetItemUrl, this.CustomFunctionHandlers);
                output.Write(s);
            }
        }