public TableOfContentsTag(Topic root, IUrlResolver resolver) : base("ul") { AddClass("table-of-contents"); writeChildNodes(root, root, this, resolver); }
public string Transform(Topic current, string before) { var tokens = Token.FindTokens(before).ToArray(); if (!tokens.Any()) return before; var builder = new StringBuilder(); int position = 0; tokens.Each(token => { if (token.FirstIndex > position) { builder.Append(before.Substring(position, token.FirstIndex - position)); } var handler = _handlers[token.Key]; builder.Append(handler.Transform(current, token.Data)); position = token.LastIndex + 1; }); if (position < before.Length) { builder.Append(before.Substring(position)); } return builder.ToString(); }
public string Transform(Topic current, string data) { var props = data.Split(';'); var key = props.First(); var other = findOther(current, key); if (other == null) return string.Empty; var url = _urls.ToUrl(current, other); var title = other.Title; var template = Template; for (int i = 1; i < props.Length; i++) { if (props[i].StartsWith("title=", StringComparison.InvariantCulture)) { title = props[i].Split('=').Last().Trim(); } else { template = props[i]; } } return template.Replace("{href}", url).Replace("{title}", title); }
public static void WriteToFiles(string directory, Topic topLevel) { if (!FileSystem.DirectoryExists(directory)) { FileSystem.CreateDirectory(directory); } var file = directory.AppendPath("index.md"); WriteTopicFile(file, topLevel); WriteOrderFile(directory, topLevel); topLevel.Children.Each(child => { var key = child.KeyInsideParent(); if (child.Children.Any()) { WriteToFiles(directory.AppendPath(key), child); } else { var childFile = directory.AppendPath(key + ".md"); WriteTopicFile(childFile, child); } }); }
public string Generate(Topic topic) { if (topic.IsSplashPage()) { return _transformer.Transform(topic, new FileSystem().ReadStringFromFile(topic.File)); } try { return generate(topic); } catch (Exception e) { ConsoleWriter.Write(ConsoleColor.Yellow, "Failed to transform topic at " + topic.File); ConsoleWriter.Write(ConsoleColor.Red, e.ToString()); var document = new HtmlDocument { Title = "Error!" }; document.Add("h1").Text("Error!"); document.Add("pre").Text(e.ToString()); return document.ToString(); } }
public void ExportTo(string directory, Topic root, Func<Topic, string> pathing) { var fileSystem = new FileSystem(); string sourceContent = _settings.Root.AppendPath("content"); if (fileSystem.DirectoryExists(sourceContent)) { fileSystem.CopyToDirectory(sourceContent, directory.AppendPath("content")); } root.AllTopicsInOrder().Each(topic => { var path = pathing(topic); var parentDirectory = path.ParentUrl(); if (parentDirectory.IsNotEmpty()) { fileSystem.CreateDirectory(directory.AppendPath(parentDirectory)); } var text = _generator.Generate(topic); // Hoakum topic.Substitutions.Each((key, value) => { text = text.Replace(key, value); }); fileSystem.WriteStringToFile(directory.AppendPath(path), text); }); }
public IGrammar TheTopicsAre() { return this["BuildTopic"].AsTable("The topics in this directory are") .After(() => { _top = TopicLoader.LoadDirectory(_directory); }); }
public void ReadTopics() { _topic = TopicLoader.LoadDirectory(_settings.Root); _topic.ParseAndOrder().Wait(); _topicByUrl.ClearAll(); _topic.AllTopicsInOrder().Each(x => _topicByUrl[x.Url] = x); }
public string Transform(Topic current, string data) { var tag = TagForSample(data); var subject = "<p>" + Guid.NewGuid().ToString() + "</p>"; current.Substitutions[subject] = tag.ToString(); return subject; }
public string Transform(Topic current, string data) { var parts = data.Split('/'); var app = parts.First(); var command = parts.Last(); var report = _cache.ReportFor(app, command); return new CommandSectionTag(app, report).ToString(); }
public string Transform(Topic current, string data) { var sample = _cache.Find(data); var subject = "<p>" + Guid.NewGuid().ToString() + "</p>"; current.Substitutions[subject] = new SampleTag(sample).ToString(); return subject; }
public string Transform(Topic current, string data) { var url = _urls.ToUrl(current, data); return new HtmlTag("link") .Attr("href", url) .Attr("rel", "stylesheet") .Attr("type", "text/css") .ToString(); }
public string Transform(Topic current, string data) { var specData = _specData.DataForPath(data); return new HtmlTag("p") .Attr("data-path", data) .Attr("data-spec", JsonSerialization.ToCleanJson(specData.Specification)) .Attr("data-fixtures", JsonSerialization.ToCleanJson(specData.Fixtures)) .Attr("data-results", JsonSerialization.ToCleanJson(specData.Results.Results)) .AddClass("spec-result").ToString(); }
public static void WriteOrderFile(string directory, Topic parent) { FileSystem.AlterFlatFile(directory.AppendPath("order.txt"), list => { list.Clear(); parent.Children.Each(child => { var key = child.KeyInsideParent(); list.Add(key); }); }); }
public string Transform(Topic current, string data) { var ol = new HtmlTag("ol").AddClass("breadcrumb"); current.Ancestors().Each(x => { ol.Add("li/a").Attr("href", _resolver.ToUrl(current, x)).Text(x.Title); }); ol.Add("li").AddClass("active").Text(current.Title); return ol.ToString(); }
private void readTopic(string line, LightweightCache<string, Topic> cache) { var parts = line.Split(':'); var key = parts[0]; var title = parts.Length > 1 ? parts[1] : key.Split('/').Last().Capitalize(); if (key.Contains("/")) { var parentKey = key.ParentUrl(); var parent = cache[parentKey]; key = key.Split('/').Last(); var urlSegment = parts.Length == 3 ? parts[2] : key; var topic = new Topic(key, "") { Title = title, UrlSegment = urlSegment }; parent.AddChild(topic); cache[topic.Key] = topic; } else if (_top == null) { _top = new Topic("index", "") { Title = title, UrlSegment = "" }; } else { var urlSegment = parts.Length == 3 ? parts[2] : key; var topic = new Topic(key, "") { Title = title, UrlSegment = urlSegment }; _top.AddChild(topic); cache[topic.Key] = topic; } }
public static Topic LoadTopic(string file, bool isRoot) { Debug.WriteLine("Loading topic file " + file.ToFullPath()); if (!File.Exists(file)) { throw new FileNotFoundException("No topic file", file); } var key = Path.GetFileNameWithoutExtension(file).EqualsIgnoreCase("splash") ? "index" : Path.GetFileNameWithoutExtension(file); var topic = new Topic(key.ToLower(), file); return topic; }
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>"); var tag = new HtmlTag("script").Attr("language", "javascript").Attr("src", "/topics.js"); builder.Replace("</head>", tag.ToString() + "\n</head>"); return builder.ToString(); }
private void writeChildNodes(Topic root, Topic parent, HtmlTag tag, IUrlResolver resolver) { parent.Children.Each(childTopic => { var li = tag.Add("li"); li.Add("a").Attr("href", resolver.ToUrl(root, childTopic)).Text(childTopic.Title); if (childTopic.Children.Any()) { var ul = li.Add("ul"); writeChildNodes(root, childTopic, ul, resolver); } }); }
public TopicRegistry(Topic top) { _top = top; Actions.FindBy(_ => _.IncludeTypesNamed(x => x.EndsWith("DocTool"))); Actions.IncludeType<SampleExplorer>(); Actions.IncludeType<TodoExplorer>(); Policies.ChainSource(this); AlterSettings<AssetSettings>(_ => { _.AllowableExtensions.Add(".json"); }); }
public static IEnumerable<TodoTask> ReadTasks(Topic topic) { var i = 0; var regex = @"TODO\((.*?)\)"; using (StreamReader streamReader = new StreamReader(topic.File)) { string text; while ((text = streamReader.ReadLine()) != null) { i++; if (text.Contains("TODO")) { var matches = Regex.Matches(text, regex); foreach (Match match in matches) { var message = match.Groups[1].Value.Trim(); yield return new TodoTask { File = topic.File, Key = topic.Key, Line = i, Message = message }; } if (matches.Count == 0) { var index = text.IndexOf("TODO"); var message = text.Substring(index + 4).Trim(); yield return new TodoTask { File = topic.File, Key = topic.Key, Line = i, Message = message }; } } } } }
private string generate(Topic topic) { try { var template = readTemplate(); return _transformer.Transform(topic, template); } catch (Exception) { Thread.Sleep(100); // One retry because of over-eager file locking var template = readTemplate(); return _transformer.Transform(topic, template); } }
public static void WriteTopicFile(string file, Topic topic) { if (!File.Exists(file)) { Console.WriteLine("Writing topic file " + file); new FileSystem().WriteToFlatFile(file, writer => { writer.WriteLine("<!--Title:{0}-->".ToFormat(topic.Title)); writer.WriteLine("<!--Url:{0}-->".ToFormat(topic.UrlSegment)); writer.WriteLine(""); writer.WriteLine("TODO(Write some content!)"); }); } else { Console.WriteLine("Found {0} and will not overwrite", file); } }
public DocProject(DocSettings settings) { _topic = TopicLoader.LoadDirectory(settings.Root); _settings = settings; _container = new Container(_ => { _.AddRegistry<SampleRegistry>(); _.AddRegistry<TransformationRegistry>(); _.ForSingletonOf<IBrowserRefresher>().Use<BrowserRefresher>(); _.For(typeof(IUrlResolver)).Use(settings.UrlResolverType()); _.ForSingletonOf<ICommandUsageCache>().Use<CommandUsageCache>(); _.For<DocSettings>().Use(settings); _.For<Topic>().Use(_topic); }); }
private Topic findOther(Topic current, string key) { if (key.EqualsIgnoreCase("{next}")) { return current.FindNext(); } if (key.EqualsIgnoreCase("{previous}")) { return current.FindPrevious(); } var topic = _top.FindByKey(key); if (topic == null) { throw new ArgumentOutOfRangeException("key", "Cannot find a topic with key '{0}'".ToFormat(key)); } return topic; }
public string Transform(Topic current, string data) { var text = TopicLoader.FileSystem.ReadStringFromFile(current.File); text = _transformer.Transform(current, text); if (Path.GetExtension(current.File) == ".md") { text = CommonMark.CommonMarkConverter.Convert(text); /* text = text .Replace("<p></code></pre></p>", string.Empty) .Replace("<pre><code>", string.Empty); */ } return text; }
private string transformFromTopic(Topic current, Topic other, string[] props) { var url = _urls.ToUrl(current, other); var title = other.Title; var template = Template; for (int i = 1; i < props.Length; i++) { if (props[i].StartsWith("title=", StringComparison.InvariantCulture)) { title = props[i].Split('=').Last().Trim(); } else { template = props[i]; } } return template.Replace("{href}", url).Replace("{title}", title); }
public string Transform(Topic current, string data) { var parts = data.Split(';'); var url = _urls.ToUrl(current, parts.First()); var image = new HtmlTag("img").Attr("src", url).Style("max-width", "100%"); if (parts.Length == 0) { return image.ToString(); } var header = new HtmlTag("h5", x => { x.Add("strong").Text(parts.Last()); }); return header.ToString() + image.ToString(); }
public string Transform(Topic current, string data) { var props = data.Split(';'); var key = props.First(); try { var other = findOther(current, key); if (other == null) return string.Empty; return transformFromTopic(current, other, props); } catch (ArgumentOutOfRangeException) { var tag = new HtmlTag("p").AddClass("bg-warning").Style("padding", "5px"); tag.Add("b").Text("Unknown topic key '{0}'".ToFormat(key)); tag.Add("small").Text(" -- CTRL+SHIFT+R to force refresh the topic tree"); return tag.ToString(); } }
public LinkToTransformHandler(IUrlResolver urls, Topic top) { _urls = urls; _top = top; }