Example #1
0
        public static void AddConventions(this HtmlTagsConfiguration configuration, Action <HtmlConventionRegistry> conventionRegsitryConfigurator)
        {
            var conventionRegistry = new HtmlConventionRegistry();

            conventionRegsitryConfigurator(conventionRegistry);
            configuration.AddConventions(conventionRegistry);
        }
        public static HtmlConventionRegistry ModelState(this HtmlConventionRegistry registry)
        {
            registry.ValidationMessages.Always.BuildBy <DefaultValidationMessageBuilder>();
            registry.ValidationMessages.NamingConvention(new DotNotationElementNamingConvention());

            return(registry);
        }
 public ValidationHtmlConvention(IFieldValidationQuery fieldValidationQuery,
                                 HtmlConventionRegistry htmlConvention,
                                 IEnumerable <IHtmlValidationConvention> conventions)
 {
     _fieldValidationQuery = fieldValidationQuery;
     _htmlConvention       = htmlConvention;
     _conventions          = conventions;
 }
Example #4
0
            /// <summary>
            ///   Use an HtmlConventionRegistry to add new html convention builders and modifiers
            /// </summary>
            /// <param name = "configure"></param>
            public void Configure(Action <HtmlConventionRegistry> configure)
            {
                var registry = new HtmlConventionRegistry();

                configure(registry);

                Library.Import(registry.Library);
            }
        /// <summary>
        /// Configures HtmlTags with ASP.NET Core defaults
        /// </summary>
        /// <param name="services">Service collection</param>
        /// <param name="config">Additional configuration callback</param>
        /// <returns>Service collection</returns>
        public static IServiceCollection AddHtmlTags(this IServiceCollection services, Action <HtmlConventionRegistry> config)
        {
            var registry = new HtmlConventionRegistry();

            config(registry);

            return(services.AddHtmlTags(registry));
        }
        public void HtmlConvention(Action <HtmlConventionRegistry> configure)
        {
            var conventions = new HtmlConventionRegistry();

            configure(conventions);

            HtmlConvention(conventions);
        }
        public void fill_service_with_nothing_should_add_the_service()
        {
            var registry1 = new HtmlConventionRegistry();

            var services = new ServiceRegistry();

            services.SetServiceIfNone(registry1);

            services.FindAllValues <HtmlConventionRegistry>().ShouldHaveTheSameElementsAs(registry1);
        }
        public static void AddHtmlTags(this IServiceCollection services, Action <HtmlConventionRegistry> config)
        {
            var registry = new HtmlConventionRegistry();

            config(registry);

            registry.Defaults();

            services.AddHtmlTags(registry);
        }
        public static void AddHtmlTags(this IServiceCollection services, Action<HtmlConventionRegistry> config)
        {
            var registry = new HtmlConventionRegistry();

            config(registry);

            registry.Defaults();

            services.AddHtmlTags(registry);
        }
Example #10
0
        public static HtmlConventionRegistry ModelMetadata(this HtmlConventionRegistry registry)
        {
            registry.Labels.Modifier <DisplayNameElementModifier>();
            registry.Displays.Modifier <MetadataModelDisplayModifier>();
            registry.Editors.Modifier <MetadataModelEditModifier>();
            registry.Editors.Modifier <PlaceholderElementModifier>();
            registry.Editors.Modifier <ModelStateErrorsModifier>();
            registry.Editors.Modifier <ClientSideValidationModifier>();

            return(registry);
        }
 public void SetUp()
 {
     theTarget   = new ConventionTarget();
     theRegistry = new HtmlConventionRegistry();
     _generator  = new Lazy <IElementGenerator <ConventionTarget> >(() =>
     {
         return(HtmlElementScenario <ConventionTarget> .For(x =>
         {
             x.Library.Import(theRegistry.Library);
             x.Model = theTarget;
         }));
     });
 }
Example #12
0
        public void fill_service_that_has_something_already_does_not_add_values()
        {
            var registry1 = new HtmlConventionRegistry();
            var registry2 = new HtmlConventionRegistry();

            var services = new ServiceRegistry();

            services.AddService(registry1);

            services.SetServiceIfNone(registry2);

            services.FindAllValues <HtmlConventionRegistry>().ShouldHaveTheSameElementsAs(registry1);
        }
Example #13
0
        public void should_add_object_def_directly()
        {
            var registry1 = new HtmlConventionRegistry();

            var services  = new ServiceRegistry();
            var objectDef = new ObjectDef(typeof(HtmlConventionRegistry))
            {
                Value = registry1
            };

            services.AddService(typeof(HtmlConventionRegistry), objectDef);

            services.DefaultServiceFor <HtmlConventionRegistry>().ShouldEqual(objectDef);
        }
Example #14
0
        private static void htmlConventions(HtmlConventionRegistry x)
        {
            x.Editors
            .Always
            .Modify((e, tag) => tag.Attr("placeholder", e.Accessor.Name));

            x.Editors
            .If(p => p.Accessor.InnerProperty.Name.Equals("Description"))
            .Modify((e, tag) => tag.TagName("textarea").RemoveAttr("value").Text(e.Value <string>()));

            x.Editors
            .If(p => p.Accessor.InnerProperty.Name.Equals("Quantity"))
            .Modify((e, tag) => tag.AddClass("mini"));
        }
        public void SetUp()
        {
            theTarget = new ConventionTarget();
            theRegistry = new HtmlConventionRegistry();
            _generator = new Lazy<IElementGenerator<ConventionTarget>>(() =>
            {
                return HtmlElementScenario<ConventionTarget>.For(x =>
                {
                    x.Library.Import(theRegistry.Library);
                    x.Model = theTarget;
                });
            });


        }
Example #16
0
        protected void Application_Start()
        {
            RouteRegistry.RegisterRoutes(RouteTable.Routes);
            ViewEngineRegistry.SetViewEngines();

            if (!WindsorContainerSetup.InitializeContainer())
            {
                return;
            }

            WebRegistry.Register(WindsorContainerSetup.Container);
            HtmlConventionRegistry.Register(WindsorContainerSetup.Container);
            DynamicRegistry.Register(WindsorContainerSetup.Container);
            DynamicServicesRegistry.RegisterConventions();
            DynamicServicesRegistry.Bootstrap(WindsorContainerSetup.Container);
        }
        /// <summary>
        /// Configures HtmlTags with ASP.NET Core defaults
        /// </summary>
        /// <param name="services">Service collection</param>
        /// <param name="registries">Custom convention registries</param>
        /// <returns>Service collection</returns>
        public static IServiceCollection AddHtmlTags(this IServiceCollection services, params HtmlConventionRegistry[] registries)
        {
            var library         = new HtmlConventionLibrary();
            var defaultRegistry = new HtmlConventionRegistry()
                                  .Defaults()
                                  .ModelMetadata()
                                  .ModelState();

            defaultRegistry.Apply(library);

            foreach (var registry in registries)
            {
                registry.Apply(library);
            }

            return(services.AddHtmlTags(library));
        }
Example #18
0
        public void ClearAll()
        {
            var registry1 = new HtmlConventionRegistry();
            var registry2 = new HtmlConventionRegistry();
            var registry3 = new HtmlConventionRegistry();
            var registry4 = new HtmlConventionRegistry();

            var services = new ServiceRegistry();

            services.AddService(registry1);
            services.AddService(registry2);
            services.AddService(registry3);
            services.AddService(registry4);

            services.ClearAll <HtmlConventionRegistry>();

            services.FindAllValues <HtmlConventionRegistry>().Any().ShouldBeFalse();
        }
Example #19
0
        public void GetAllValues()
        {
            var registry1 = new HtmlConventionRegistry();
            var registry2 = new HtmlConventionRegistry();
            var registry3 = new HtmlConventionRegistry();
            var registry4 = new HtmlConventionRegistry();

            var services = new ServiceRegistry();

            services.AddService(registry1);
            services.AddService(registry2);
            services.AddService(registry3);
            services.AddService(registry4);

            services.AddService <HtmlConventionRegistry, HtmlConventionRegistry>();

            services.FindAllValues <HtmlConventionRegistry>()
            .ShouldHaveTheSameElementsAs(registry1, registry2, registry3, registry4);
        }
Example #20
0
        public static IServiceCollection AddMiruHtml(this IServiceCollection services, params HtmlConventionRegistry[] registries)
        {
            services.AddSingleton <HtmlGenerator>();

            services.AddSingleton <ElementNaming>();
            services.AddSingleton <IElementNamingConvention, DotNotationElementNamingConvention>();

            services.AddSingleton <HtmlGenerator, HtmlGenerator>();

            services.AddTransient <IAntiforgeryAccessor, AntiForgeryAccessor>();

            var library = new HtmlConventionLibrary();

            var defaultRegistry = new HtmlConventionRegistry()
                                  .DefaultModifiers();

            defaultRegistry.Apply(library);

            if (registries.Length > 0)
            {
                foreach (var registry in registries)
                {
                    registry.Apply(library);
                }
            }
            else
            {
                new HtmlConfiguration().Apply(library);
            }

            var defaultBuilders = new HtmlConventionRegistry();

            // defaultBuilders.Editors.BuilderPolicy<CheckboxBuilder>();
            defaultBuilders.Editors.Always.BuildBy <TextboxBuilder>();
            defaultBuilders.Labels.Always.BuildBy <DefaultLabelBuilder>();
            defaultBuilders.DefaultNamingConvention();
            defaultBuilders.Displays.Always.BuildBy <SpanDisplayBuilder>();
            defaultBuilders.Displays.NamingConvention(new DotNotationElementNamingConvention());

            defaultBuilders.Apply(library);

            return(services.AddHtmlTags(library));
        }
 public void HtmlConvention(HtmlConventionRegistry conventions)
 {
     Services(x => x.AddService(conventions));
 }
Example #22
0
        public CoreRegistry()
        {
            Applies.ToThisAssembly();
            //IncludeDiagnostics(true);

            Actions.IncludeTypesNamed(x => x.EndsWith("Handler"));

            Routes
            .ConstrainToHttpMethod(x => x.Method.Name.EndsWith("Query"), "GET")
            .ConstrainToHttpMethod(x => x.Method.Name.EndsWith("Command"), "POST");

            Routes
            .IgnoreNamespaceText(typeof(CoreRegistry).Namespace)
            .IgnoreNamespaceText("Handlers")
            .IgnoreMethodsNamed("Query")
            .IgnoreMethodsNamed("Command")
            .IgnoreClassSuffix("Handler");

            Routes.HomeIs <HomeHandler>(x => x.Query(new HomeQueryModel()));
            Views.TryToAttachWithDefaultConventions()
            .RegisterActionLessViews(t => t.ViewModelType == typeof(Notification));

            this.UseSpark();

            Policies.ConditionallyWrapBehaviorChainsWith <HandlerAssetConvention>(x => x.HandlerType.Namespace.Contains("Products"));

            Policies.Add(new ProductNotFoundPolicy <EditHandler>(h => h.Query(null)));
            Policies.Add(new ProductNotFoundPolicy <DeleteHandler>(h => h.Query(null)));

            Output.ToJson.WhenCallMatches(x => x.Method.Name.Equals("Data"));

            Import <BasicLocalizationSupport>(x =>
            {
                x.LocalizationStorageIs <InMemoryLocalizationStorage>();
                x.LoadLocalizationWith <LocalizationActivator>();
                x.DefaultCulture = Thread.CurrentThread.CurrentUICulture;
            });


            var validationRulesHtmlConventionActivator = ObjectDef.ForType <ValidationHtmlConvention>();
            var validationRulesHtmlConvention          = new HtmlConventionRegistry();

            validationRulesHtmlConventionActivator.DependencyByValue(validationRulesHtmlConvention);

            Services(cfg =>
            {
                cfg.SetServiceIfNone <IProductService, InMemoryProductService>();
                cfg.SetServiceIfNone(Mapper.Engine);
                cfg.SetServiceIfNone(Mapper.Configuration);
                cfg.SetServiceIfNone <ILocaleCacheFactory, LocaleCacheFactory>();
                cfg.SetServiceIfNone <IValidationDescriptorProvider>(new ValidationDescriptorProvider());
                cfg.AddService <IHtmlValidationConvention, LocalizedNameConvention>();
                cfg.AddService <IHtmlValidationConvention, RequiredHtmlValidationConvention>();
                cfg.AddService <IHtmlValidationConvention, GreaterOrEqualToZeroHtmlValidationConvention>();
                cfg.AddService <IHtmlValidationConvention, MaximumLengthHtmlValidationConvention>();
                cfg.AddService <IFieldValidationSource, AddProductModelValidationSource>();
                cfg.AddService <IActivator, AutoMapperActivator>();
                cfg.AddService <IActivator, ValidationDescriptorProviderFiller>();
                cfg.AddService(typeof(IActivator), validationRulesHtmlConventionActivator);
            });

            HtmlConvention(htmlConventions);
            HtmlConvention(validationRulesHtmlConvention);

            this.Validation(validation =>
            {
                validation.Actions.Include(call => call.HasInput && call.Method.Name.Equals("Command"));
                validation.Failures
                .IfModelIs <EditProductCommandModel>().TransferBy <ValidationDescriptor>();
            });

            Models.BindPropertiesWith <OriginalModelBinder>();
        }
Example #23
0
 public static void AddConventions(this HtmlTagsConfiguration configuration, HtmlConventionRegistry conventionRegistry)
 {
     configuration.Conventions.Import(conventionRegistry.Library);
 }
Example #24
0
 public void ImportRegistry(HtmlConventionRegistry registry)
 {
     registry.Profiles.Each(ImportProfile);
 }
Example #25
0
        public static IServiceCollection AddMiruMvc(
            this IServiceCollection services,
            HtmlConventionRegistry html         = null,
            Action <MvcOptions> mvc             = null,
            Action <MiruMvcOptions> setupAction = null)
        {
            var miruOptions = new MiruMvcOptions();

            setupAction?.Invoke(miruOptions);

            services.Configure <RazorViewEngineOptions>(o =>
            {
                // {2} is area, {1} is controller,{0} is the action
                // the component's path "Components/{ViewComponentName}/{ViewComponentViewName}" is in the action {0}
                o.ViewLocationFormats.Add("/{0}" + RazorViewEngine.ViewExtension);
            });

            var mvcCoreBuilder = services.AddMvcCore(options =>
            {
                options.Filters.Add(typeof(AutoValidateAntiforgeryTokenAttribute));
                options.Filters.Add(typeof(ExceptionFilter));
                options.Filters.Add(typeof(ViewDataFilter));

                var index = options.ValueProviderFactories
                            .IndexOf(options.ValueProviderFactories.OfType <QueryStringValueProviderFactory>().Single());

                options.ValueProviderFactories[index] = new CulturedQueryStringValueProviderFactory();

                mvc?.Invoke(options);
            })
                                 .AddMiruActionResult()
                                 // .AddRazorRuntimeCompilation()
                                 .AddMiruNestedControllers();

            if (miruOptions.EnableFeatureFolders)
            {
                mvcCoreBuilder.AddFeatureFolders();
                mvcCoreBuilder.AddAreaFeatureFolders();
            }

            services.AddAntiforgery(options =>
            {
                options.HeaderName = "X-CSRF-Token";
            });

            services.Configure <RouteOptions>(options =>
            {
                // options.LowercaseUrls = true;
                // options.LowercaseQueryStrings = true;
            });

            if (html != null)
            {
                services.AddMiruHtml(html);
            }
            else
            {
                services.AddMiruHtml(new HtmlConfiguration());
            }

            services.AddHttpContextAccessor();

            services.AddSingleton <AssetsMap>();

            services.AddSingleton <IActionResultExecutor <HtmlTagResult>, ContentResultExecutor>();

            return(services);
        }
        public static HtmlConventionRegistry ModelStateNamingConvention(this HtmlConventionRegistry registry)
        {
            registry.ValidationMessages.NamingConvention(new DotNotationElementNamingConvention());

            return(registry);
        }
Example #27
0
 public static HtmlConventionLibrary AddConvention(this HtmlConventionLibrary library, HtmlConventionRegistry convention)
 {
     convention.Apply(library);
     return(library);
 }
        public static HtmlConventionRegistry ModelStateBuilders(this HtmlConventionRegistry registry)
        {
            registry.ValidationMessages.Always.BuildBy <DefaultValidationMessageBuilder>();

            return(registry);
        }
 public static HtmlConventionRegistry ModelState(this HtmlConventionRegistry registry)
 => registry.ModelStateBuilders().ModelStateNamingConvention();
Example #30
0
 public void ImportRegistry(HtmlConventionRegistry registry)
 {
     registry.Profiles.Each(ImportProfile);
 }
 public void HtmlConvention(HtmlConventionRegistry conventions)
 {
     conventions.As <IFubuRegistryExtension>().Configure(this);
 }