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();
            }
Exemplo n.º 3
0
            public HandlebarsEnvironment(HandlebarsConfiguration configuration)
            {
                if (configuration == null)
                {
                    throw new ArgumentNullException("configuration");
                }

                _configuration = configuration;
                _compiler      = new HandlebarsCompiler(_configuration);
                RegisterBuiltinHelpers();
            }
Exemplo n.º 4
0
 internal HelperOptions(
     Action <TextWriter, object> template,
     Action <TextWriter, object> inverse,
     BlockParamsValueProvider blockParamsValueProvider,
     HandlebarsConfiguration configuration)
 {
     Template      = template;
     Inverse       = inverse;
     Configuration = configuration;
     BlockParams   = blockParamsValueProvider.Configure;
 }
Exemplo n.º 5
0
        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();
        }
Exemplo n.º 8
0
 public HandlebarsEnvironment(HandlebarsConfiguration configuration)
 {
     Configuration = configuration ?? throw new ArgumentNullException(nameof(configuration));
 }
Exemplo n.º 9
0
 public static IHandlebars Create(HandlebarsConfiguration configuration = null)
 {
     configuration = configuration ?? new HandlebarsConfiguration();
     return(new HandlebarsEnvironment(configuration));
 }
Exemplo n.º 10
0
 public static IHandlebars Create(HandlebarsConfiguration configuration = null)
 {
     configuration = configuration ?? new HandlebarsConfiguration();
     return new HandlebarsEnvironment(configuration);
 }
Exemplo n.º 11
0
        /// <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);
        }