-
Notifications
You must be signed in to change notification settings - Fork 53
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
New OWIN middleware to show topics in doc-run instead of TopicChain's
- Loading branch information
1 parent
8bc6058
commit 6964d53
Showing
12 changed files
with
1,275 additions
and
1,296 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains 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
This file contains 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
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Reflection; | ||
using System.Text; | ||
using System.Threading.Tasks; | ||
using FubuCore; | ||
using FubuMVC.Core.Http.Owin; | ||
using FubuMVC.Core.Http.Owin.Middleware; | ||
using ST.Docs.Topics; | ||
using ST.Docs.Transformation; | ||
|
||
namespace ST.Docs.Runner | ||
{ | ||
public class TopicMiddleware : IOwinMiddleware | ||
{ | ||
private readonly Func<IDictionary<string, object>, Task> _inner; | ||
private readonly DocProject _project; | ||
private readonly IHtmlGenerator _generator; | ||
private readonly DocSettings _settings; | ||
private readonly string _webSocketScript; | ||
|
||
|
||
public TopicMiddleware(Func<IDictionary<string, object>, Task> inner, DocProject project, IHtmlGenerator generator, DocSettings settings) | ||
{ | ||
_inner = inner; | ||
_project = project; | ||
_generator = generator; | ||
_settings = settings; | ||
|
||
var stream = Assembly.GetExecutingAssembly() | ||
.GetManifestResourceStream(typeof(TopicMiddleware), "WebsocketsRefresh.txt"); | ||
|
||
_webSocketScript = stream.ReadAllText(); | ||
} | ||
|
||
public Task Invoke(IDictionary<string, object> environment) | ||
{ | ||
var path = environment[OwinConstants.RequestPathKey].As<string>().TrimStart('/'); | ||
|
||
|
||
var topic = _project.FindTopicByUrl(path); | ||
if (topic == null) | ||
{ | ||
return _inner(environment); | ||
} | ||
|
||
return Task.Factory.StartNew(() => | ||
{ | ||
var response = new OwinHttpResponse(environment); | ||
response.WriteContentType("text/html"); | ||
var html = GenerateHtml(topic); | ||
response.Write(html); | ||
response.Flush(); | ||
}); | ||
|
||
} | ||
|
||
public string GenerateHtml(Topic topic) | ||
{ | ||
var html = _generator.Generate(topic); | ||
|
||
var builder = new StringBuilder(html); | ||
topic.Substitutions.Each((key, value) => { builder.Replace(key, value); }); | ||
|
||
var script = _webSocketScript.Replace("%WEB_SOCKET_ADDRESS%", _settings.WebsocketAddress); | ||
builder.Replace("</head>", script + "\n</head>"); | ||
|
||
return builder.ToString(); | ||
} | ||
} | ||
} |
This file was deleted.
Oops, something went wrong.
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,49 +1,23 @@ | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Threading.Tasks; | ||
using FubuMVC.Core; | ||
using FubuMVC.Core.Assets; | ||
using FubuMVC.Core.Diagnostics.Packaging; | ||
using FubuMVC.Core.Http.Hosting; | ||
using FubuMVC.Core.Registration; | ||
using FubuMVC.Core.Registration.Nodes; | ||
using ST.Docs.Samples; | ||
using ST.Docs.Todos; | ||
using ST.Docs.Topics; | ||
|
||
namespace ST.Docs.Runner | ||
{ | ||
public class TopicRegistry : FubuRegistry, IChainSource | ||
{ | ||
private readonly Topic _top; | ||
|
||
public TopicRegistry(Topic top) | ||
{ | ||
_top = top; | ||
|
||
HostWith<NOWIN>(); | ||
|
||
|
||
namespace ST.Docs.Runner | ||
{ | ||
public class TopicRegistry : FubuRegistry | ||
{ | ||
public TopicRegistry() | ||
{ | ||
HostWith<NOWIN>(); | ||
|
||
Actions.FindBy(_ => _.IncludeTypesNamed(x => x.EndsWith("DocTool"))); | ||
Actions.IncludeType<SampleExplorer>(); | ||
Actions.IncludeType<SampleExplorer>(); | ||
Actions.IncludeType<TodoExplorer>(); | ||
Actions.DisableDefaultActionSource(); | ||
|
||
Policies.ChainSource(this); | ||
|
||
AlterSettings<AssetSettings>(_ => | ||
{ | ||
_.AllowableExtensions.Add(".json"); | ||
}); | ||
} | ||
Actions.DisableDefaultActionSource(); | ||
|
||
public Task<BehaviorChain[]> BuildChains(BehaviorGraph graph, IPerfTimer timer) | ||
{ | ||
return Task.FromResult(BuildChains(graph).ToArray()); | ||
AlterSettings<AssetSettings>(_ => _.AllowableExtensions.Add(".json")); | ||
} | ||
|
||
public IEnumerable<BehaviorChain> BuildChains(BehaviorGraph graph) | ||
{ | ||
return _top.AllTopicsInOrder().Select(x => new TopicChain(x)); | ||
} | ||
} | ||
} | ||
} |
This file contains 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
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,4 +5,5 @@ Newtonsoft.Json | |
HtmlTags | ||
Fleck | ||
Fixie | ||
RhinoMocks | ||
RhinoMocks | ||
Nowin |