Created
August 9, 2011 22:35
-
-
Save emiaj/1135388 to your computer and use it in GitHub Desktop.
SparkHtmlTag
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| public class HelloSparkRegistry : FubuRegistry | |
| { | |
| public HelloSparkRegistry() | |
| { | |
| IncludeDiagnostics(true); | |
| Applies | |
| .ToThisAssembly(); | |
| Actions | |
| .IncludeClassesSuffixedWithController(); | |
| Routes | |
| .HomeIs<AirController>(c => c.TakeABreath()) | |
| .IgnoreControllerNamespaceEntirely() | |
| .IgnoreMethodSuffix("Command") | |
| .IgnoreMethodSuffix("Query") | |
| .ConstrainToHttpMethod(action => action.Method.Name.EndsWith("Command"), "POST") | |
| .ConstrainToHttpMethod(action => action.Method.Name.StartsWith("Query"), "GET"); | |
| Policies.Add<AntiForgeryPolicy>(); | |
| this.UseSpark(); | |
| Views | |
| .TryToAttachWithDefaultConventions() | |
| .TryToAttachViewsInPackages(); | |
| HtmlConvention<SampleHtmlConventions>(); | |
| Services(s => s.ReplaceService<IUrlTemplatePattern, JQueryUrlTemplate>()); | |
| Output.To<SparkHtmlTagOutput>().WhenTheOutputModelIs<SparkHtmlTag>(); | |
| } | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| public class SparkHtmlTag | |
| { | |
| public HtmlTag Tag { get; set; } | |
| public override string ToString() | |
| { | |
| return Tag == null ? string.Empty : Tag.ToString(); | |
| } | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| public class SparkHtmlTagOutput : OutputNode<SparkHtmlTagRenderer> | |
| { | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| public class SparkHtmlTagRenderer : IActionBehavior | |
| { | |
| private readonly IOutputWriter _outputWriter; | |
| private readonly NestedOutput _nestedOutput; | |
| private readonly IFubuRequest _request; | |
| public SparkHtmlTagRenderer(IOutputWriter outputWriter, NestedOutput nestedOutput, IFubuRequest request) | |
| { | |
| _outputWriter = outputWriter; | |
| _nestedOutput = nestedOutput; | |
| _request = request; | |
| } | |
| public void Invoke() | |
| { | |
| var tag = _request.Get<SparkHtmlTag>(); | |
| _outputWriter.WriteHtml(tag); | |
| } | |
| public void InvokePartial() | |
| { | |
| var tag = _request.Get<SparkHtmlTag>(); | |
| _nestedOutput.Writer.Write(tag); | |
| } | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| using FubuMVC.Core; | |
| using HtmlTags; | |
| namespace FubuMVC.HelloSpark.Controllers.HtmlTager | |
| { | |
| public class TagController | |
| { | |
| [FubuPartial] | |
| public SparkHtmlTag Go(GoRequest request) | |
| { | |
| var tag = new HtmlTag("h3").Text("I am a go request result tag goodness."); | |
| return new SparkHtmlTag { Tag = tag }; | |
| } | |
| } | |
| public class GoRequest | |
| { | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment