public HandlebarsConfigurationAdapter(HandlebarsConfiguration configuration)
        {
            UnderlingConfiguration = configuration;

            AliasProviders      = new ObservableList <IMemberAliasProvider>(configuration.AliasProviders);
            HelperResolvers     = new ObservableList <IHelperResolver>(configuration.HelperResolvers);
            RegisteredTemplates = new ObservableIndex <string, HandlebarsTemplate <TextWriter, object, object>, StringEqualityComparer>(new StringEqualityComparer(StringComparison.OrdinalIgnoreCase), configuration.RegisteredTemplates);
            AliasProviders      = new ObservableList <IMemberAliasProvider>(configuration.AliasProviders);
            FormatterProviders  = new ObservableList <IFormatterProvider>
            {
                new DefaultFormatterProvider(),
                new CollectionFormatterProvider(),
                new ReadOnlyCollectionFormatterProvider()
            }.AddMany(configuration.FormatterProviders);

            ObjectDescriptorProviders = CreateObjectDescriptorProvider(UnderlingConfiguration.ObjectDescriptorProviders);
            ExpressionMiddlewares     = new ObservableList <IExpressionMiddleware>(configuration.CompileTimeConfiguration.ExpressionMiddleware)
            {
                new ClosureExpressionMiddleware(),
                new ExpressionOptimizerMiddleware()
            };

            Features = UnderlingConfiguration.CompileTimeConfiguration.Features
                       .Select(o => o.CreateFeature())
                       .OrderBy(o => o.GetType().GetTypeInfo().GetCustomAttribute <FeatureOrderAttribute>()?.Order ?? 100)
                       .ToList();

            Helpers      = CreateHelpersSubscription(configuration.Helpers);
            BlockHelpers = CreateHelpersSubscription(configuration.BlockHelpers);
        }
            public HandlebarsEnvironment(HandlebarsConfiguration configuration)
            {
                if (configuration == null)
                {
                    throw new ArgumentNullException("configuration");
                }

                _configuration = configuration;
                _compiler = new HandlebarsCompiler(_configuration);
                RegisterBuiltinHelpers();
            }
Example #3
0
            public HandlebarsEnvironment(HandlebarsConfiguration configuration)
            {
                if (configuration == null)
                {
                    throw new ArgumentNullException("configuration");
                }

                _configuration = configuration;
                _compiler      = new HandlebarsCompiler(_configuration);
                RegisterBuiltinHelpers();
            }
 internal HelperOptions(
     Action <TextWriter, object> template,
     Action <TextWriter, object> inverse,
     BlockParamsValueProvider blockParamsValueProvider,
     HandlebarsConfiguration configuration)
 {
     Template      = template;
     Inverse       = inverse;
     Configuration = configuration;
     BlockParams   = blockParamsValueProvider.Configure;
 }
        public void CanRenderAGlobalVariable()
        {
            //Given a layout in the root which contains an @ variable
            var files = new FakeFileSystem()
            {
                { "views\\someview.hbs", "This is the {{@body.title}}"}
            };

            //When a viewengine renders that view
            var handlebarsConfiguration = new HandlebarsConfiguration() {FileSystem = files};
            var handlebars = Handlebars.Create(handlebarsConfiguration);
            var render = handlebars.CompileView("views\\someview.hbs");
            var output = render(new {@body = new {title = "THING"}});

            //Then the correct output should be rendered
            Assert.AreEqual("This is the THING", output);
        }
        public HandlebarsConfigurationAdapter(HandlebarsConfiguration configuration)
        {
            UnderlingConfiguration = configuration;

            HelperResolvers          = new ObservableList <IHelperResolver>(configuration.HelperResolvers);
            RegisteredTemplates      = new ObservableDictionary <string, Action <TextWriter, object> >(configuration.RegisteredTemplates);
            PathInfoStore            = _pathInfoStore = new PathInfoStore();
            ObjectDescriptorProvider = CreateObjectDescriptorProvider();
            AliasProviders           = new ObservableList <IMemberAliasProvider>(UnderlingConfiguration.AliasProviders);

            ExpressionMiddleware = new ObservableList <IExpressionMiddleware>(UnderlingConfiguration.CompileTimeConfiguration.ExpressionMiddleware);

            Features = UnderlingConfiguration.CompileTimeConfiguration.Features
                       .Select(o => o.CreateFeature())
                       .OrderBy(o => o.GetType().GetTypeInfo().GetCustomAttribute <FeatureOrderAttribute>()?.Order ?? 100)
                       .ToList();

            CreateHelpersSubscription();
            CreateBlockHelpersSubscription();

            AliasProviders.Add(new CollectionMemberAliasProvider(this));
        }
        public HandlebarsConfigurationAdapter(HandlebarsConfiguration configuration)
        {
            UnderlingConfiguration = configuration;

            HelperResolvers          = new ObservableList <IHelperResolver>(configuration.HelperResolvers);
            RegisteredTemplates      = new ObservableDictionary <string, HandlebarsTemplate <TextWriter, object, object> >(configuration.RegisteredTemplates);
            PathInfoStore            = _pathInfoStore = HandlebarsDotNet.PathInfoStore.Shared;
            ObjectDescriptorProvider = CreateObjectDescriptorProvider();
            AliasProviders           = new ObservableList <IMemberAliasProvider>(UnderlingConfiguration.AliasProviders);
            UnresolvedBindingFormat  = configuration.UnresolvedBindingFormat ?? (undefined =>
            {
                var formatter = UnresolvedBindingFormatter;
                if (formatter == null)
                {
                    if (string.IsNullOrEmpty(undefined.Value))
                    {
                        return(string.Empty);
                    }
                    formatter = string.Empty;
                }

                return(string.Format(formatter, undefined.Value));
            });

            ExpressionMiddlewares = new ObservableList <IExpressionMiddleware>(UnderlingConfiguration.CompileTimeConfiguration.ExpressionMiddleware)
            {
                new ExpressionOptimizerMiddleware()
            };

            Features = UnderlingConfiguration.CompileTimeConfiguration.Features
                       .Select(o => o.CreateFeature())
                       .OrderBy(o => o.GetType().GetTypeInfo().GetCustomAttribute <FeatureOrderAttribute>()?.Order ?? 100)
                       .ToList();

            CreateHelpersSubscription();
            CreateBlockHelpersSubscription();
        }
Example #8
0
 public HandlebarsEnvironment(HandlebarsConfiguration configuration)
 {
     Configuration = configuration ?? throw new ArgumentNullException(nameof(configuration));
 }
Example #9
0
 public static IHandlebars Create(HandlebarsConfiguration configuration = null)
 {
     configuration = configuration ?? new HandlebarsConfiguration();
     return(new HandlebarsEnvironment(configuration));
 }
Example #10
0
 public static IHandlebars Create(HandlebarsConfiguration configuration = null)
 {
     configuration = configuration ?? new HandlebarsConfiguration();
     return new HandlebarsEnvironment(configuration);
 }
        /// <summary>
        /// Allows configuration manipulations
        /// </summary>
        /// <param name="configuration"></param>
        /// <param name="config"></param>
        /// <returns></returns>
        public static HandlebarsConfiguration Configure(this HandlebarsConfiguration configuration, Action <HandlebarsConfiguration> config)
        {
            config(configuration);

            return(configuration);
        }