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);
        }
Example #2
0
        private Action <IRenderContext> GetHtmlAction(HtmlDefinition 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);
        }
        public ITemplateDefinition AddText(string assetName, string defaultText, bool isPreFormatted)
        {
            BodyActions.Add(r =>
            {
                var html = r.Html;

                var localizedString = _assetManager.GetLocalizedText(r, assetName, defaultText);
                if (html.IncludeComments && !isPreFormatted)
                {
                    localizedString       = localizedString.Replace('\r', '\n');
                    var endsWithLineBreak = localizedString.EndsWith("\n");

                    var lines = localizedString
                                .Split('\n')
                                .Where(s => !string.IsNullOrEmpty(s))
                                .ToList();
                    for (var i = 0; i < lines.Count; i++)
                    {
                        var line = lines[i];
                        if (i < lines.Count - 1 || endsWithLineBreak)
                        {
                            html.WriteTextLine(line);
                        }
                        else
                        {
                            html.WriteText(line);
                        }
                    }
                }
                else
                {
                    if (isPreFormatted)
                    {
                        html.WritePreformatted(localizedString);
                    }
                    else
                    {
                        html.WriteText(localizedString);
                    }
                }
            });
            return(this);
        }