Exemple #1
0
        public override IPackage Build(IFluentBuilder fluentBuilder)
        {
            // This is an example of how to define a new region that is like an
            // existing one but with a different name and has different properties.
            //
            // The new region will be registered with the fluent builder and its name
            // will be resolvable by other elements in the solution.
            //
            // This technique will work for any of the RegionExample1..RegionExample4
            // above, but will not work for RegionExample5
            fluentBuilder.BuildUpRegion(new RegionExample2(Dependencies.RegionDependenciesFactory))
            .Name("region2a")
            .BindTo <NewsItem>("breaking-news")
            .ClassNames("news", "breaking")
            .Build();

            // This is an example of how you can construct and register a fully custom
            // implementation of IRegion with the fluent builder
            var regionExample5 = new RegionExample5() as IRegion;

            regionExample5.Name = "region5";
            fluentBuilder.Register(regionExample5);

            return(this);
        }
        public IComponent Build()
        {
            _nameManager.AddResolutionHandler(
                NameResolutionPhase.ResolveAssetNames,
                () =>
            {
                _component.CssRules = _cssDefinitions
                                      .Select(d =>
                {
                    d.Selector = _htmlHelper.NamespaceCssSelector(d.Selector, _component.Package);
                    return(d);
                })
                                      .Select(d =>
                {
                    Action <ICssWriter> writeAction = w => w.WriteRule(d.Selector, d.Style);
                    return(writeAction);
                })
                                      .ToArray();

                _component.JavascriptFunctions = _functionDefinitions
                                                 .Select(d =>
                {
                    Action <IJavascriptWriter> writeAction = w => w.WriteFunction(
                        d.FunctionName, d.Parameters, d.Body, d.ReturnType, _component.Package, d.IsPublic);
                    return(writeAction);
                })
                                                 .ToArray();

                _component.HtmlWriters = _htmlToRender
                                         .Select(d =>
                {
                    Action <IRenderContext> action;

                    if (_component.Package == null)
                    {
                        action = rc =>
                        {
                            var localizedText = _assetManager.GetLocalizedText(rc, d.AssetName, d.DefaultHtml);
                            localizedText     = localizedText.Replace("{ns}_", "");
                            rc.Html.WriteLine(localizedText);
                        };
                    }
                    else
                    {
                        action = rc =>
                        {
                            var localizedText = _assetManager.GetLocalizedText(rc, d.AssetName, d.DefaultHtml);
                            localizedText     = localizedText.Replace("{ns}", _component.Package.NamespaceName);
                            rc.Html.WriteLine(localizedText);
                        };
                    }
                    return(action);
                })
                                         .ToArray();
            });

            _fluentBuilder.Register(_component);
            return(_component);
        }
Exemple #3
0
        ILayout ILayoutDefinition.Build()
        {
            _nameManager.AddResolutionHandler(
                NameResolutionPhase.ResolveElementReferences,
                nm =>
            {
                var regionComponentKeys = _regionComponents.Keys.ToList();
                foreach (var zoneName in regionComponentKeys)
                {
                    var componentRef  = _regionComponents[zoneName];
                    var componentName = componentRef as string;
                    var component     = componentRef as IComponent;

                    if (componentName != null)
                    {
                        component = nm.ResolveComponent(componentName, _layout.Package);
                    }

                    _regionComponents[zoneName] = component;
                }

                var regionLayoutKeys = _regionLayouts.Keys.ToList();
                foreach (var zoneName in regionLayoutKeys)
                {
                    var layoutRef  = _regionLayouts[zoneName];
                    var layoutName = layoutRef as string;
                    var layout     = layoutRef as ILayout;

                    if (layoutName != null)
                    {
                        layout = nm.ResolveLayout(layoutName, _layout.Package);
                    }

                    _regionLayouts[zoneName] = layout;
                }

                ResolveZoneNames(_zoneSet, nm);

                WriteOpeningTag();
                WriteRegions(_zoneSet);
                WriteClosingTag();
            });

            _nameManager.AddResolutionHandler(
                NameResolutionPhase.CreateInstances,
                () => SetRegionInstances(_zoneSet));

            _fluentBuilder.Register(_layout);
            return(_layout);
        }
        IRegion IRegionDefinition.Build()
        {
            _nameManager.AddResolutionHandler(
                NameResolutionPhase.ResolveElementReferences,
                nm =>
            {
                if (!string.IsNullOrEmpty(_tagName))
                {
                    var attributes     = _htmlHelper.StyleAttributes(_style, _classNames, _region.Package);
                    _region.WriteOpen  = w => w.WriteOpenTag(_tagName, attributes);
                    _region.WriteClose = w => w.WriteCloseTag(_tagName);
                }

                if (!string.IsNullOrEmpty(_childTagName))
                {
                    var attributes          = _htmlHelper.StyleAttributes(_childStyle, _childClassNames, _region.Package);
                    _region.WriteChildOpen  = w => w.WriteOpenTag(_childTagName, attributes);
                    _region.WriteChildClose = w => w.WriteCloseTag(_childTagName);
                }
            });

            _fluentBuilder.Register(_region);
            return(_region);
        }
 IPackage IPackageDefinition.Build()
 {
     _builder.Register(_package);
     return(_package);
 }
 public IModule Build()
 {
     _fluentBuilder.Register(_module);
     return(_module);
 }
Exemple #7
0
        IRegion IRegionDefinition.Build()
        {
            if (_cssDefinitions.Count > 0)
            {
                _nameManager.AddResolutionHandler(
                    NameResolutionPhase.ResolveAssetNames,
                    () =>
                {
                    _region.CssRules = _cssDefinitions
                                       .Select(d =>
                    {
                        d.Selector = _htmlHelper.NamespaceCssSelector(d.Selector, _region.Package);
                        return(d);
                    })
                                       .Select(d =>
                    {
                        Action <ICssWriter> writeAction = w => w.WriteRule(d.Selector, d.Style);
                        return(writeAction);
                    })
                                       .ToArray();
                });
            }

            if (_functionDefinitions.Count > 0)
            {
                _nameManager.AddResolutionHandler(
                    NameResolutionPhase.ResolveAssetNames,
                    () =>
                {
                    _region.JavascriptFunctions = _functionDefinitions
                                                  .Select(d =>
                    {
                        Action <IJavascriptWriter> writeAction = w => w.WriteFunction(
                            d.FunctionName, d.Parameters, d.Body, d.ReturnType, _region.Package, d.IsPublic);
                        return(writeAction);
                    })
                                                  .ToArray();
                });
            }

            if (!string.IsNullOrEmpty(_tagName))
            {
                _nameManager.AddResolutionHandler(
                    NameResolutionPhase.ResolveElementReferences,
                    nm =>
                {
                    var attributes     = _htmlHelper.StyleAttributes(_style, _classNames, _region.Package);
                    _region.WriteOpen  = w => { w.WriteOpenTag(_tagName, attributes); w.WriteLine(); };
                    _region.WriteClose = w => { w.WriteCloseTag(_tagName); w.WriteLine(); };
                });
            }

            if (!string.IsNullOrEmpty(_childTagName))
            {
                _nameManager.AddResolutionHandler(
                    NameResolutionPhase.ResolveElementReferences,
                    nm =>
                {
                    var attributes          = _htmlHelper.StyleAttributes(_childStyle, _childClassNames, _region.Package);
                    _region.WriteChildOpen  = w => { w.WriteOpenTag(_childTagName, attributes); w.WriteLine(); };
                    _region.WriteChildClose = w => { w.WriteCloseTag(_childTagName); w.WriteLine(); };
                });
            }

            _fluentBuilder.Register(_region);
            return(_region);
        }
Exemple #8
0
 IDataProvider IDataProviderDefinition.Build()
 {
     _builder.Register(_dataProvider);
     return(_dataProvider);
 }
 IPage IPageDefinition.Build()
 {
     _fluentBuilder.Register(_page);
     _nameManager.AddResolutionHandler(NameResolutionPhase.InitializeRunables, () => _page.Initialize());
     return(_page);
 }
Exemple #10
0
        IComponent IComponentDefinition.Build()
        {
            _nameManager.AddResolutionHandler(
                NameResolutionPhase.ResolveAssetNames,
                () =>
            {
                var css = new List <Action <ICssWriter> >();

                if (_lessDefinitions != null && _lessDefinitions.Count > 0)
                {
                    var aggregate     = _lessDefinitions.Aggregate(string.Empty, (a, s) => a + _htmlHelper.NamespaceCssSelector(s.LessStyles, _component.Package) + '\n');
                    var dotlessConfig = new DotlessConfiguration {
                        MinifyOutput = true
                    };
                    var less = dotless.Core.Less.Parse(aggregate, dotlessConfig);

                    foreach (var line in less.Replace("\r", "").Split('\n'))
                    {
                        var trimmed = line.Trim();
                        if (trimmed.Length > 0)
                        {
                            Action <ICssWriter> writeAction = w => w.WriteLineRaw(trimmed);
                            css.Add(writeAction);
                        }
                    }
                }

                if (_cssDefinitions != null && _cssDefinitions.Count > 0)
                {
                    css.AddRange(_cssDefinitions
                                 .Select(d =>
                    {
                        d.Selector = _htmlHelper.NamespaceCssSelector(d.Selector, _component.Package);
                        Action <ICssWriter> writeAction = w => w.WriteRule(d.Selector, d.Style);
                        return(writeAction);
                    }));
                }

                _component.CssRules = css.ToArray();

                var javascriptWriters = new List <Action <IJavascriptWriter> >();

                if (!string.IsNullOrEmpty(_javaScript))
                {
                    javascriptWriters.Add(w => w.WriteLineRaw(_javaScript, _component.Package));
                }

                if (_functionDefinitions != null && _functionDefinitions.Count > 0)
                {
                    javascriptWriters.AddRange(_functionDefinitions
                                               .Select(d =>
                    {
                        Action <IJavascriptWriter> writeAction = w => w.WriteFunction(
                            d.FunctionName, d.Parameters, d.Body, d.ReturnType, _component.Package, d.IsPublic);
                        return(writeAction);
                    }));
                }

                _component.JavascriptFunctions = javascriptWriters.ToArray();

                if (_headHtmlToRender.Count > 0)
                {
                    _component.HeadWriters = _headHtmlToRender
                                             .Select(GetHtmlAction)
                                             .ToArray();
                }

                if (_bodyHtmlToRender.Count > 0)
                {
                    _component.BodyWriters = _bodyHtmlToRender
                                             .Select(GetHtmlAction)
                                             .ToArray();
                }

                if (_initializationHtmlToRender.Count > 0)
                {
                    _component.InitializationWriters = _initializationHtmlToRender
                                                       .Select(GetHtmlAction)
                                                       .ToArray();
                }
            });

            _fluentBuilder.Register(_component);
            return(_component);
        }