Ejemplo n.º 1
0
        public IEnumerable <BreadCrumb> Get(object input)
        {
            var amBreadCrumb = input as IAmBreadCrumb;

            var breadCrumbs = new List <BreadCrumb>();

            if (amBreadCrumb == null)
            {
                return(breadCrumbs);
            }

            var menuContext = new DefaultMenuContext(_fubuRequest, _serviceLocator);

            while (amBreadCrumb != null)
            {
                breadCrumbs.Add(amBreadCrumb.Build(menuContext));

                amBreadCrumb = amBreadCrumb.FindParent() as IAmBreadCrumb;
            }

            breadCrumbs.Reverse();

            breadCrumbs = _cmsContext.Filter(breadCrumbs, _cmsContext.GetCurrentTheme()).ToList();

            return(new ReadOnlyCollection <BreadCrumb>(breadCrumbs));
        }
        protected override object FindParameterValue(Match match, ICmsRenderer cmsRenderer, ICmsContext context, ITheme theme, Func<string, string> recurse)
        {
            var componentNameGroup = match.Groups["componentName"];

            if (componentNameGroup == null)
                return "";

            var componentName = componentNameGroup.Value;

            var component = context.Filter(_components.Where(x => x.GetType().Name == componentName), theme).FirstOrDefault();

            if (component == null)
                return "";

            var settings = component.GetDefaultSettings();

            var settingsGroup = match.Groups["settings"];

            if (!string.IsNullOrEmpty(settingsGroup?.Value))
            {
                var settingsJson = settingsGroup.Value;

                if (!string.IsNullOrEmpty(settingsJson))
                {
                    var parsedSettings = JsonConvert.DeserializeObject<IDictionary<string, object>>(settingsJson);

                    foreach (var item in parsedSettings)
                        settings[item.Key] = item.Value;
                }
            }

            var renderResult = cmsRenderer.RenderComponent(component, settings, context, theme);

            return recurse(renderResult.Read());
        }
Ejemplo n.º 3
0
        protected override object FindParameterValue(Match match, ICmsRenderer cmsRenderer, ICmsContext context, ITheme theme, Func <string, string> recurse)
        {
            var componentNameGroup = match.Groups["componentName"];

            if (componentNameGroup == null)
            {
                return("");
            }

            var componentName = componentNameGroup.Value;

            var component = context.Filter(_components.Where(x => x.GetType().Name == componentName), theme).FirstOrDefault();

            if (component == null)
            {
                return("");
            }

            var settings = component.GetDefaultSettings();

            var settingsGroup = match.Groups["settings"];

            if (!string.IsNullOrEmpty(settingsGroup?.Value))
            {
                var settingsJson = settingsGroup.Value;

                if (!string.IsNullOrEmpty(settingsJson))
                {
                    var parsedSettings = JsonConvert.DeserializeObject <IDictionary <string, object> >(settingsJson);

                    foreach (var item in parsedSettings)
                    {
                        settings[item.Key] = item.Value;
                    }
                }
            }

            var renderResult = cmsRenderer.RenderComponent(component, settings, context, theme);

            return(recurse(renderResult.Read()));
        }
Ejemplo n.º 4
0
        public virtual IRenderResult RenderEndpoint <TInput>(TInput input, ICmsContext context, ITheme theme) where TInput : ICmsEndpointInput
        {
            var themeEndpoint = context
                                .Filter(_themeEndpoints.OfType <ICmsEndpoint <TInput> >(), theme)
                                .FirstOrDefault();

            if (themeEndpoint == null)
            {
                return(new RenderResult("text/plain", x => { }, new Dictionary <Guid, RequestContext>(), context));
            }

            var settings = themeEndpoint.GetDefaultSettings();
            var endpointConfiguration = _endpointConfigurationStorage.Load(theme.GetName(), theme);

            if (endpointConfiguration != null)
            {
                foreach (var item in endpointConfiguration.Settings)
                {
                    settings[item.Key] = item.Value;
                }
            }

            var renderInformation = themeEndpoint.Render(input, context, settings);

            if (renderInformation == null)
            {
                return(new RenderResult("text/plain", x => { }, new Dictionary <Guid, RequestContext>(), context));
            }

            var contexts = renderInformation.Contexts.ToDictionary(x => Guid.NewGuid(), x => x);

            contexts[Guid.NewGuid()] = EndpointSettingsContext.Build(settings);

            return(new RenderResult(renderInformation.ContentType, x =>
            {
                var renderer = (IRenderer)context.Resolve(typeof(Renderer <>).MakeGenericType(renderInformation.GetType()));

                renderer.Render(renderInformation, context, theme, x);
            }, contexts, context));
        }