Beispiel #1
0
		public void SupportsDynamicModel()
		{
			dynamic person = new { Forename = "Matt", Surname = "Abbott", Age = 30 };
			string template = "{{Forename}} {{Surname}} is {{Age}} years old";
			string expected = "Matt Abbott is 30 years old";

			var service = new HandlebarsService();
			string result = service.CompileAndRun("my-template", template, person);

			Assert.Equal(expected, result);
		}
        /// <summary>
        /// Gets or create the global selection service.
        /// </summary>
        /// <param name="serviceContainer">The service container in which an instance of the selection service will be added (or retrieved).</param>
        /// <returns>An instance of a class implemenaing <see cref="Delta.CertXplorer.Common.Services.ISelectionService"/>.</returns>
        public static ISelectionService GetOrCreateSelectionService(SCD.IServiceContainer serviceContainer)
        {
            if (serviceContainer == null) throw new ArgumentNullException("serviceContainer");

            var selectionService = serviceContainer.GetService<ISelectionService>();
            if (selectionService == null)
            {
                selectionService = new GlobalSelectionService();
                serviceContainer.AddService<ISelectionService>(selectionService);
            }

            return selectionService;
        }
Beispiel #3
0
		public void SupportsRootLookup()
		{
			var service = new HandlebarsService();
			var model = new
			            {
				            property = "Hello",
				            other = new
				                    {
					                    forename = "Matt",
					                    surname = "Abbott",
					                    job = new
					                          {
						                          title = "Developer"
					                          }
				                    }
			            };

			string template = "{{#with other}}{{@root.property}} {{forename}} {{surname}}, {{job.title}}{{/with}}";
			string expected = "Hello Matt Abbott, Developer";

			Assert.Equal(expected, service.CompileAndRun("test", template, model));
		}
Beispiel #4
0
		public void SupportsRootLookupThroughPartial()
		{
			var service = new HandlebarsService();

			string template = "Your name is {{>person_name}}";
			var model = new { world = "World", person = new { forename = "Matthew", surname = "Abbott" } };

			string partial = "{{@root.person.forename}} {{@root.person.surname}}";
			service.RegisterPartial("person_name", partial);

			service.Compile("hello-world", template);
			string result = service.Run("hello-world", model);
			string expected = "Your name is Matthew Abbott";
			
			Assert.Equal(expected, result);
		}
Beispiel #5
0
		public void SupportsRootLookupInParameter()
		{
			var service = new HandlebarsService();
			var model = new
			{
				property = "Hello"
			};

			string template = "{{#with @root.property}}{{this}}{{/with}}";
			string expected = "Hello";

			Assert.Equal(expected, service.CompileAndRun("test", template, model));
		}