Ejemplo n.º 1
0
        public static ElementGenerator <T> For(Action <ScenarioDefinition> configure)
        {
            var definition = new ScenarioDefinition();

            configure(definition);

            var activators = definition.Activators().ToList();

            activators.Add(new ElementRequestActivator(new InMemoryFubuRequest(), definition.Naming));

            var stringifier = definition.Display.BuildStringifier();

            var formatter = new DisplayFormatter(definition.Services, stringifier);

            definition.Services.Add <IDisplayFormatter>(formatter);

            definition.Library.Import(new DefaultHtmlConventions().Library);


            var generator = ElementGenerator <T> .For(definition.Library, activators);

            generator.Model = definition.Model;

            return(generator);
        }
        private static IElementGenerator <T> GetGenerator <T>(T model) where T : class
        {
            var library =
                StructuremapMvc.StructureMapDependencyScope.CurrentNestedContainer.GetInstance <HtmlConventionLibrary>();

            return(ElementGenerator <T> .For(library, t => StructuremapMvc.StructureMapDependencyScope.CurrentNestedContainer.GetInstance(t), model));
        }
        public static HtmlTag DisplayLabel <T, TMember>(this IHtmlHelper <List <T> > helper, Expression <Func <T, TMember> > expression)
            where T : class
        {
            var library   = helper.ViewContext.HttpContext.RequestServices.GetService <HtmlConventionLibrary>();
            var generator = ElementGenerator <T> .For(library, t => helper.ViewContext.HttpContext.RequestServices.GetService(t));

            return(generator.TagFor(expression, nameof(TagConventions.DisplayLabels)));
        }
Ejemplo n.º 4
0
        public static IElementGenerator <T> GetGenerator <T>(IHtmlHelper <T> helper, params object[] additionalServices) where T : class
        {
            var library = helper.ViewContext.HttpContext.RequestServices.GetService <HtmlConventionLibrary>();

            object ServiceLocator(Type t) => additionalServices.FirstOrDefault(t.IsInstanceOfType) ?? helper.ViewContext.HttpContext.RequestServices.GetService(t);

            return(ElementGenerator <T> .For(library, ServiceLocator, helper.ViewData.Model));
        }
Ejemplo n.º 5
0
        public void Test()
        {
            var library = new HtmlConventionLibrary();

            new DefaultHtmlConventions().Apply(library);
            var generator = ElementGenerator <Foo> .For(library);

            var tag = generator.InputFor(m => m.Value);

            tag = generator.InputFor(m => m.Value);
        }
Ejemplo n.º 6
0
        public IElementGenerator <TModel> GeneratorFor <TModel>(TModel model) where TModel : class
        {
            var htmlConventionLibrary = _sp.GetService <HtmlConventionLibrary>();

            return(ElementGenerator <TModel> .For(htmlConventionLibrary, t => _sp.GetService(t), model));
        }
 private static IElementGenerator <T> GetGenerator <T>(T model) where T : class
 {
     return(ElementGenerator <T> .For(HtmlConventionLibrary, null, model));
 }
Ejemplo n.º 8
0
        public static IElementGenerator <T> GetGenerator <T>(IHtmlHelper <T> helper) where T : class
        {
            var library = helper.ViewContext.HttpContext.RequestServices.GetService <HtmlConventionLibrary>();

            return(ElementGenerator <T> .For(library, t => helper.ViewContext.HttpContext.RequestServices.GetService(t), helper.ViewData.Model));
        }