/// <summary> /// Invokes a view component, and registeres section handlers /// </summary> /// <param name="componentName">The view component name</param> /// <param name="bodyHandler">Delegate to render the component's body. null if the component does not have a body</param> /// <param name="sectionHandlers">Delegates to render the component's sections, by the delegate names</param> /// <param name="parameters">The parameters to be passed to the component</param> protected void InvokeViewComponent(string componentName, ViewComponentSectionRendereDelegate bodyHandler, IEnumerable <KeyValuePair <string, ViewComponentSectionRendereDelegate> > sectionHandlers, params object[] parameters) { ViewComponentContext viewComponentContext = new ViewComponentContext( this, bodyHandler, componentName, parameters); if (sectionHandlers != null) { foreach (KeyValuePair <string, ViewComponentSectionRendereDelegate> pair in sectionHandlers) { viewComponentContext.RegisterSection(pair.Key, pair.Value); } } ViewComponent viewComponent = ((IViewComponentFactory)Context.GetService(typeof(IViewComponentFactory))).Create(componentName); viewComponent.Init(Context, viewComponentContext); viewComponent.Render(); if (viewComponentContext.ViewToRender != null) { OutputSubView("\\" + viewComponentContext.ViewToRender, viewComponentContext.ContextVars); } }
public override bool render(InternalContextAdapter context, TextWriter writer, INode node) { INode bodyNode = null; IDictionary componentParams = CreateParametersAndFigureOutBlockNode(context, node); if (bodyNodeIndex < node.jjtGetNumChildren()) { bodyNode = node.jjtGetChild(bodyNodeIndex); } NVelocityViewContextAdapter contextAdapter = new NVelocityViewContextAdapter( componentName, context, writer, bodyNode, componentParams); IRailsEngineContext railsContext = (IRailsEngineContext)context.Get("context"); component.Init(railsContext, contextAdapter); component.Render(); if (contextAdapter.ViewToRender != null) { return(RenderComponentView(context, writer, contextAdapter)); } return(true); }
override public int Write(IStringTemplateWriter output) { SetPredefinedAttributes(); SetDefaultArgumentValues(); //IRailsEngineContext context = (IRailsEngineContext) GetAttribute(ConfigConstants.CONTEXT_ATTRIB_KEY); IRailsEngineContext context = MonoRailHttpHandler.CurrentContext; StringWriter writer = new StringWriter(); StringTemplateViewContextAdapter viewComponentContext = new StringTemplateViewContextAdapter(viewComponentName, this); viewComponentContext.TextWriter = writer; viewComponent.Init(context, viewComponentContext); viewComponent.Render(); if (viewComponentContext.ViewToRender != null) { StringTemplate viewST = group.GetEmbeddedInstanceOf(this, viewComponentContext.ViewToRender); writer.Write(viewST.ToString()); } if (viewComponentName.Equals("CaptureFor")) { string keyToSet = (string)GetAttribute("id"); object valToSet = GetAttribute(keyToSet); OutermostEnclosingInstance.RemoveAttribute(keyToSet); OutermostEnclosingInstance.SetAttribute(keyToSet, valToSet); } output.Write(writer.ToString()); // if (LintMode) // { // CheckForTrouble(); // } return(0); }