public void should_pull_code_example_from_folder() { var path = Path.GetTempPath() + Guid.NewGuid().ToString(); Directory.CreateDirectory(path); try { File.WriteAllText(Path.Combine(path, "CodeExampleWithCommentsAndTemplate.md"), "*comments*"); File.WriteAllText(Path.Combine(path, "CodeExampleWithCommentsAndTemplate.mustache"), "some<br/>template \r\nyo"); File.WriteAllText(Path.Combine(path, "CodeExampleWithNoTemplate.md"), "*comments*"); File.WriteAllText(Path.Combine(path, "CodeExampleWithNoComments.mustache"), "some<br/>template \r\nyo"); var examples = CodeExample.FromDirectory(path).ToList(); examples[0].Name.ShouldEqual("CodeExampleWithCommentsAndTemplate"); examples[0].Comments.ShouldEqual(CompiledComments); examples[0].Template.ShouldEqual(PreProcessedTemplate); examples[1].Name.ShouldEqual("CodeExampleWithNoComments"); examples[1].Comments.ShouldEqual(null); examples[1].Template.ShouldEqual(PreProcessedTemplate); examples[2].Name.ShouldEqual("CodeExampleWithNoTemplate"); examples[2].Comments.ShouldEqual(CompiledComments); examples[2].Template.ShouldEqual(null); } finally { Directory.Delete(path, true); } }
/// <summary> /// Adds a code examples to the documentation from a folder. /// These are named as [filename].[md] for comments and [filename].[mustache] /// for templates. The name defaults to the filename if not specified. /// </summary> public Swank WithCodeExampleFolder(string path) { _configuration.CodeExamples.AddRange(CodeExample.FromDirectory(HostingEnvironment.MapPath( (!path.StartsWith("\\") && !path.StartsWith("\\") ? "~\\" : "") + path))); return(this); }