Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Got references working for everything again

  • Loading branch information...
commit ea6e6320f2ad3ad1c868de2c599310dcc2acdfb4 1 parent 7afff2a
@jagregory authored
View
12 src/Docu.Console/Documentation/Event.cs
@@ -8,9 +8,13 @@ namespace Docu.Documentation
{
public class Event : BaseDocumentationElement, IReferencable
{
- public Event(EventIdentifier identifier)
+ public DeclaredType Type { get; set; }
+
+ public Event(EventIdentifier identifier, DeclaredType type)
: base(identifier)
- {}
+ {
+ Type = type;
+ }
public string FullName
{
@@ -42,9 +46,9 @@ public void Resolve(IDictionary<Identifier, IReferencable> referencables)
ConvertToExternalReference();
}
- public static Event Unresolved(EventIdentifier eventIdentifier)
+ public static Event Unresolved(EventIdentifier eventIdentifier, DeclaredType type)
{
- return new Event(eventIdentifier) { IsResolved = false };
+ return new Event(eventIdentifier, type) { IsResolved = false };
}
}
}
View
16 src/Docu.Console/Documentation/Field.cs
@@ -8,9 +8,13 @@ namespace Docu.Documentation
{
public class Field : BaseDocumentationElement, IReferencable
{
- public Field(FieldIdentifier identifier)
+ public DeclaredType Type { get; set; }
+
+ public Field(FieldIdentifier identifier, DeclaredType type)
: base(identifier)
- {}
+ {
+ Type = type;
+ }
public string FullName
{
@@ -50,14 +54,14 @@ public void Resolve(IDictionary<Identifier, IReferencable> referencables)
ConvertToExternalReference();
}
- public static Field Unresolved(FieldIdentifier fieldIdentifier)
+ public static Field Unresolved(FieldIdentifier fieldIdentifier, DeclaredType type)
{
- return new Field(fieldIdentifier) { IsResolved = false };
+ return new Field(fieldIdentifier, type) { IsResolved = false };
}
- public static Field Unresolved(FieldIdentifier fieldIdentifier, IReferencable returnType)
+ public static Field Unresolved(FieldIdentifier fieldIdentifier, DeclaredType type, IReferencable returnType)
{
- return new Field(fieldIdentifier) { IsResolved = false, ReturnType = returnType };
+ return new Field(fieldIdentifier, type) { IsResolved = false, ReturnType = returnType };
}
}
}
View
2  src/Docu.Console/Documentation/Generators/EventGenerator.cs
@@ -21,7 +21,7 @@ public void Add(List<Namespace> namespaces, DocumentedEvent association)
var ns = FindNamespace(association, namespaces);
var type = FindType(ns, association);
- var doc = Event.Unresolved(Identifier.FromEvent(association.Event, association.TargetType));
+ var doc = Event.Unresolved(Identifier.FromEvent(association.Event, association.TargetType), type);
ParseSummary(association, doc);
ParseRemarks(association, doc);
View
2  src/Docu.Console/Documentation/Generators/FieldGenerator.cs
@@ -24,7 +24,7 @@ public void Add(List<Namespace> namespaces, DocumentedField association)
association.Field.FieldType,
Namespace.Unresolved(
Identifier.FromNamespace(association.Field.FieldType.Namespace)));
- var doc = Field.Unresolved(Identifier.FromField(association.Field, association.TargetType), returnType);
+ var doc = Field.Unresolved(Identifier.FromField(association.Field, association.TargetType), type, returnType);
ParseSummary(association, doc);
ParseRemarks(association, doc);
View
7 src/Docu.Console/Documentation/Generators/MethodGenerator.cs
@@ -21,12 +21,13 @@ public void Add(List<Namespace> namespaces, DocumentedMethod association)
var ns = FindNamespace(association, namespaces);
var type = FindType(ns, association);
- DeclaredType methodReturnType = DeclaredType.Unresolved(
+ var methodReturnType = DeclaredType.Unresolved(
Identifier.FromType(association.Method.ReturnType),
association.Method.ReturnType,
Namespace.Unresolved(Identifier.FromNamespace(association.Method.ReturnType.Namespace)));
- Method doc = Method.Unresolved(Identifier.FromMethod(association.Method, association.TargetType),
- association.Method, methodReturnType);
+ var doc = Method.Unresolved(
+ Identifier.FromMethod(association.Method, association.TargetType),
+ type, association.Method, methodReturnType);
ParseSummary(association, doc);
ParseRemarks(association, doc);
View
5 src/Docu.Console/Documentation/Generators/PropertyGenerator.cs
@@ -22,13 +22,12 @@ public void Add(List<Namespace> namespaces, DocumentedProperty association)
var ns = FindNamespace(association, namespaces);
var type = FindType(ns, association);
- DeclaredType propertyReturnType =
+ var propertyReturnType =
DeclaredType.Unresolved(Identifier.FromType(association.Property.PropertyType),
association.Property.PropertyType,
Namespace.Unresolved(
Identifier.FromNamespace(association.Property.PropertyType.Namespace)));
- Property doc = Property.Unresolved(Identifier.FromProperty(association.Property, association.TargetType),
- propertyReturnType);
+ var doc = Property.Unresolved(Identifier.FromProperty(association.Property, association.TargetType), type, propertyReturnType);
ParseSummary(association, doc);
ParseValue(association, doc);
View
19 src/Docu.Console/Documentation/Method.cs
@@ -12,9 +12,10 @@ public class Method : BaseDocumentationElement, IReferencable
private readonly IList<MethodParameter> parameters = new List<MethodParameter>();
private MethodInfo representedMethod;
- public Method(MethodIdentifier identifier)
+ public Method(MethodIdentifier identifier, DeclaredType type)
: base(identifier)
{
+ Type = type;
Returns = new Returns();
}
@@ -33,6 +34,7 @@ public bool IsStatic
get { return ((MethodIdentifier)identifier).IsStatic; }
}
+ public DeclaredType Type { get; set; }
public IReferencable ReturnType { get; set; }
public Returns Returns { get; set; }
@@ -85,16 +87,19 @@ internal void AddParameter(MethodParameter parameter)
parameters.Add(parameter);
}
- public static Method Unresolved(MethodIdentifier methodIdentifier)
+ public static Method Unresolved(MethodIdentifier methodIdentifier, DeclaredType type)
{
- return new Method(methodIdentifier) { IsResolved = false };
+ return new Method(methodIdentifier, type) { IsResolved = false };
}
- public static Method Unresolved(MethodIdentifier methodIdentifier, MethodInfo representedMethod,
- IReferencable returnType)
+ public static Method Unresolved(MethodIdentifier methodIdentifier, DeclaredType type, MethodInfo representedMethod, IReferencable returnType)
{
- return new Method(methodIdentifier)
- { IsResolved = false, representedMethod = representedMethod, ReturnType = returnType };
+ return new Method(methodIdentifier, type)
+ {
+ IsResolved = false,
+ representedMethod = representedMethod,
+ ReturnType = returnType
+ };
}
}
}
View
12 src/Docu.Console/Documentation/Property.cs
@@ -8,13 +8,15 @@ namespace Docu.Documentation
{
public class Property : BaseDocumentationElement, IReferencable
{
- public Property(PropertyIdentifier identifier)
+ public Property(PropertyIdentifier identifier, DeclaredType type)
: base(identifier)
{
+ Type = type;
HasGet = identifier.HasGet;
HasSet = identifier.HasSet;
}
+ public DeclaredType Type { get; set; }
public bool HasGet { get; private set; }
public bool HasSet { get; private set; }
@@ -56,14 +58,14 @@ public void Resolve(IDictionary<Identifier, IReferencable> referencables)
ConvertToExternalReference();
}
- public static Property Unresolved(PropertyIdentifier propertyIdentifier)
+ public static Property Unresolved(PropertyIdentifier propertyIdentifier, DeclaredType type)
{
- return new Property(propertyIdentifier) { IsResolved = false };
+ return new Property(propertyIdentifier, type) { IsResolved = false };
}
- public static Property Unresolved(PropertyIdentifier propertyIdentifier, IReferencable returnType)
+ public static Property Unresolved(PropertyIdentifier propertyIdentifier, DeclaredType type, IReferencable returnType)
{
- return new Property(propertyIdentifier) { IsResolved = false, ReturnType = returnType };
+ return new Property(propertyIdentifier, type) { IsResolved = false, ReturnType = returnType };
}
}
}
View
32 src/Docu.Console/Parsing/Comments/SeeCodeCommentParser.cs
@@ -17,13 +17,37 @@ public IComment Parse(XmlNode content)
else if (referenceTarget is TypeIdentifier)
reference = DeclaredType.Unresolved((TypeIdentifier)referenceTarget, Namespace.Unresolved(referenceTarget.CloneAsNamespace()));
else if (referenceTarget is MethodIdentifier)
- reference = Method.Unresolved((MethodIdentifier)referenceTarget);
+ reference = Method.Unresolved(
+ (MethodIdentifier)referenceTarget,
+ DeclaredType.Unresolved(
+ referenceTarget.CloneAsType(),
+ Namespace.Unresolved(referenceTarget.CloneAsNamespace())
+ )
+ );
else if (referenceTarget is PropertyIdentifier)
- reference = Property.Unresolved((PropertyIdentifier)referenceTarget);
+ reference = Property.Unresolved(
+ (PropertyIdentifier)referenceTarget,
+ DeclaredType.Unresolved(
+ referenceTarget.CloneAsType(),
+ Namespace.Unresolved(referenceTarget.CloneAsNamespace())
+ )
+ );
else if (referenceTarget is EventIdentifier)
- reference = Event.Unresolved((EventIdentifier)referenceTarget);
+ reference = Event.Unresolved(
+ (EventIdentifier)referenceTarget,
+ DeclaredType.Unresolved(
+ referenceTarget.CloneAsType(),
+ Namespace.Unresolved(referenceTarget.CloneAsNamespace())
+ )
+ );
else if (referenceTarget is FieldIdentifier)
- reference = Field.Unresolved((FieldIdentifier)referenceTarget);
+ reference = Field.Unresolved(
+ (FieldIdentifier)referenceTarget,
+ DeclaredType.Unresolved(
+ referenceTarget.CloneAsType(),
+ Namespace.Unresolved(referenceTarget.CloneAsNamespace())
+ )
+ );
return new See(reference);
}
View
86 src/Docu.Console/UI/HtmlOutputFormatter.cs
@@ -23,6 +23,10 @@ public HtmlOutputFormatter()
NamespaceUrlFormat = "{namespace}.htm";
TypeUrlFormat = "{type.namespace}/{type}.htm";
+ MethodUrlFormat = "{type.namespace}/{type}.htm#{method}";
+ PropertyUrlFormat = "{type.namespace}/{type}.htm#{property}";
+ FieldUrlFormat = "{type.namespace}/{type}.htm#{field}";
+ EventUrlFormat = "{type.namespace}/{type}.htm#{event}";
}
public string Format(IComment comment)
@@ -65,20 +69,7 @@ private string FormatInlineText(InlineText comment)
private string FormatSee(See block)
{
- string url = "";
-
- if (block.Reference is Namespace)
- url = Format(NamespaceUrlFormat,
- new Dictionary<string, string> { { "namespace", block.Reference.Name } });
- else if (block.Reference is DeclaredType)
- url = Format(TypeUrlFormat,
- new Dictionary<string, string>
- {
- { "type.namespace", ((DeclaredType)block.Reference).Namespace.Name },
- { "type", block.Reference.Name }
- });
-
- return "<a href=\"" + url + "\">" + block.Reference.Name + "</a>";
+ return FormatReferencable(block.Reference);
}
public string FormatReferencable(IReferencable reference)
@@ -87,14 +78,47 @@ public string FormatReferencable(IReferencable reference)
string name = reference.PrettyName;
if (reference is Namespace)
- url = Format(NamespaceUrlFormat, new Dictionary<string, string> { { "namespace", reference.Name } });
+ url = Format(NamespaceUrlFormat, new Replacement("namespace", reference.Name));
else if (reference is DeclaredType)
url = Format(TypeUrlFormat,
- new Dictionary<string, string>
- {
- { "type.namespace", ((DeclaredType)reference).Namespace.Name },
- { "type", reference.Name }
- });
+ new Replacement("type.namespace", ((DeclaredType)reference).Namespace.Name),
+ new Replacement("type", reference.Name));
+ else if (reference is Method)
+ {
+ var type = ((Method)reference).Type;
+
+ url = Format(MethodUrlFormat,
+ new Replacement("type.namespace", type.Namespace.Name),
+ new Replacement("type", type.Name),
+ new Replacement("method", reference.Name));
+ }
+ else if (reference is Property)
+ {
+ var type = ((Property)reference).Type;
+
+ url = Format(PropertyUrlFormat,
+ new Replacement("type.namespace", type.Namespace.Name),
+ new Replacement("type", type.Name),
+ new Replacement("property", reference.Name));
+ }
+ else if (reference is Field)
+ {
+ var type = ((Field)reference).Type;
+
+ url = Format(FieldUrlFormat,
+ new Replacement("type.namespace", type.Namespace.Name),
+ new Replacement("type", type.Name),
+ new Replacement("field", reference.Name));
+ }
+ else if (reference is Event)
+ {
+ var type = ((Event)reference).Type;
+
+ url = Format(EventUrlFormat,
+ new Replacement("type.namespace", type.Namespace.Name),
+ new Replacement("type", type.Name),
+ new Replacement("event", reference.Name));
+ }
if (reference.IsExternal)
return "<span title=\"" + reference.FullName + "\">" + Escape(reference.PrettyName) + "</span>";
@@ -114,17 +138,33 @@ private string FormatInlineCode(InlineCode block)
public string NamespaceUrlFormat { get; set; }
public string TypeUrlFormat { get; set; }
+ public string MethodUrlFormat { get; set; }
+ public string PropertyUrlFormat { get; set; }
+ public string FieldUrlFormat { get; set; }
+ public string EventUrlFormat { get; set; }
- private string Format(string pattern, IDictionary<string, string> pairs)
+ private string Format(string pattern, params Replacement[] replacements)
{
string output = pattern;
- foreach (var pair in pairs)
+ foreach (var replacement in replacements)
{
- output = output.Replace("{" + pair.Key + "}", pair.Value);
+ output = output.Replace("{" + replacement.Key + "}", replacement.Value);
}
return output;
}
+
+ private class Replacement
+ {
+ public string Key { get; private set; }
+ public string Value { get; private set; }
+
+ public Replacement(string key, string value)
+ {
+ Key = key;
+ Value = value;
+ }
+ }
}
}
View
4 src/Docu.Console/UI/IOutputFormatter.cs
@@ -8,6 +8,10 @@ public interface IOutputFormatter
{
string NamespaceUrlFormat { get; set; }
string TypeUrlFormat { get; set; }
+ string MethodUrlFormat { get; set; }
+ string PropertyUrlFormat { get; set; }
+ string FieldUrlFormat { get; set; }
+ string EventUrlFormat { get; set; }
string Format(IComment comment);
string FormatReferencable(IReferencable referencable);
string Escape(string value);
View
7 src/Docu.Console/templates/!namespace/!type.htm.spark
@@ -1,5 +1,10 @@
-# Formatter.NamespaceUrlFormat = "../{namespace}.htm";
+# // overrides for paths - this should be handled better
+# Formatter.NamespaceUrlFormat = "../{namespace}.htm";
# Formatter.TypeUrlFormat = "../{type.namespace}/{type}.htm";
+# Formatter.MethodUrlFormat = "../{type.namespace}/{type}.htm#{method}";
+# Formatter.PropertyUrlFormat = "../{type.namespace}/{type}.htm#{property}";
+# Formatter.FieldUrlFormat = "../{type.namespace}/{type}.htm#{field}";
+# Formatter.EventUrlFormat = "../{type.namespace}/{type}.htm#{event}";
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Frameset//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-frameset.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
View
4 src/Docu.Console/templates/!namespace/_value.spark
@@ -1,3 +1,3 @@
-<blockquote class="value" if="content.Count > 0">
- <strong>Value: </strong>${WriteSummary(content)}
+<blockquote class="value" if="content.Children.Count() > 0">
+ <strong>Value: </strong>${Format(content)}
</blockquote>
View
3  src/Docu.Tests/Docu.Tests.csproj
@@ -3,7 +3,7 @@
<PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
- <ProductVersion>9.0.21022</ProductVersion>
+ <ProductVersion>9.0.30729</ProductVersion>
<SchemaVersion>2.0</SchemaVersion>
<ProjectGuid>{76E3611F-A908-4A1B-8673-A221DD8C5301}</ProjectGuid>
<OutputType>Library</OutputType>
@@ -82,6 +82,7 @@
<Compile Include="Generation\PatternTemplateResolverTests\type_template_in_namespace.cs" />
<Compile Include="Generation\PatternTemplateResolverTests\type_template.cs" />
<Compile Include="Generation\TemplateTransformerTests.cs" />
+ <Compile Include="UI\HtmlOutputFormatterTests.cs" />
<Compile Include="Utils\TestTemplateAttribute.cs" />
<Compile Include="Generation\UntransformableResourceManagerTests.cs" />
<Compile Include="Generation\UntransformableResourceManagerTestsBase.cs" />
View
2  src/Docu.Tests/Documentation/DocumentModelGeneratorTests/Values.cs
@@ -16,7 +16,7 @@ public void ShouldHaveValueForProperty()
var model = new DocumentModel(new CommentParser(), StubEventAggregator);
var properties = new[]
{
- Property<Second>(@"<member name=""M:Example.Second.SecondProperty""><summary>Second method</summary><value>The string representation.</value></member>", x => x.SecondProperty)
+ Property<Second>(@"<member name=""P:Example.Second.SecondProperty""><value>The string representation.</value></member>", x => x.SecondProperty)
};
var namespaces = model.Create(properties);
View
8 src/Docu.Tests/Generation/HtmlGenerationTests.cs
@@ -85,8 +85,8 @@ public void ShouldOutputOverloadedMethods()
var type = Type<ClassWithOverload>(ns);
var parameterType = DeclaredType.Unresolved(Identifier.FromType(typeof(string)), typeof(string), Namespace("System"));
- type.Methods.Add(new Method(Identifier.FromMethod(Method<ClassWithOverload>(x => x.Method()), typeof(ClassWithOverload))));
- type.Methods.Add(new Method(Identifier.FromMethod(Method<ClassWithOverload>(x => x.Method(null)), typeof(ClassWithOverload))));
+ type.Methods.Add(new Method(Identifier.FromMethod(Method<ClassWithOverload>(x => x.Method()), typeof(ClassWithOverload)), null));
+ type.Methods.Add(new Method(Identifier.FromMethod(Method<ClassWithOverload>(x => x.Method(null)), typeof(ClassWithOverload)), null));
type.Methods[1].Parameters.Add(new MethodParameter("one", parameterType));
Convert(new ViewData { Type = type })
@@ -100,7 +100,7 @@ public void ShouldOutputMethodReturnType()
var type = Type<ReturnMethodClass>(ns);
var returnType = DeclaredType.Unresolved(Identifier.FromType(typeof(string)), typeof(string), Namespace("System"));
- type.Methods.Add(new Method(Identifier.FromMethod(Method<ReturnMethodClass>(x => x.Method()), typeof(ReturnMethodClass))));
+ type.Methods.Add(new Method(Identifier.FromMethod(Method<ReturnMethodClass>(x => x.Method()), typeof(ReturnMethodClass)), null));
type.Methods[0].ReturnType = returnType;
Convert(new ViewData { Type = type })
@@ -114,7 +114,7 @@ public void ShouldOutputPropertyReturnType()
var type = Type<PropertyType>(ns);
var returnType = DeclaredType.Unresolved(Identifier.FromType(typeof(string)), typeof(string), Namespace("System"));
- type.Properties.Add(new Property(Identifier.FromProperty(Property<PropertyType>(x => x.Property), typeof(PropertyType))));
+ type.Properties.Add(new Property(Identifier.FromProperty(Property<PropertyType>(x => x.Property), typeof(PropertyType)), null));
type.Properties[0].ReturnType = returnType;
Convert(new ViewData { Type = type })
View
91 src/Docu.Tests/UI/HtmlOutputFormatterTests.cs
@@ -0,0 +1,91 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using Docu.Documentation;
+using Docu.Parsing.Model;
+using Docu.UI;
+using Example;
+using NUnit.Framework;
+
+namespace Docu.Tests.UI
+{
+ [TestFixture]
+ public class HtmlOutputFormatterTests
+ {
+ [Test]
+ public void OutputsTypeReferenceLink()
+ {
+ var formatter = new HtmlOutputFormatter();
+ var type = Type<First>();
+
+ formatter.FormatReferencable(type)
+ .ShouldEqual("<a href=\"Example/First.htm\">First</a>");
+ }
+
+ [Test]
+ public void OutputsMethodReferenceLink()
+ {
+ var formatter = new HtmlOutputFormatter();
+ var method = Method<Second>("SecondMethod");
+
+ formatter.FormatReferencable(method)
+ .ShouldEqual("<a href=\"Example/Second.htm#SecondMethod\">SecondMethod</a>");
+ }
+
+ [Test]
+ public void OutputsPropertyReferenceLink()
+ {
+ var formatter = new HtmlOutputFormatter();
+ var method = Property<Second>("SecondProperty");
+
+ formatter.FormatReferencable(method)
+ .ShouldEqual("<a href=\"Example/Second.htm#SecondProperty\">SecondProperty</a>");
+ }
+
+ [Test]
+ public void OutputsFieldReferenceLink()
+ {
+ var formatter = new HtmlOutputFormatter();
+ var method = Field<Second>("aField");
+
+ formatter.FormatReferencable(method)
+ .ShouldEqual("<a href=\"Example/Second.htm#aField\">aField</a>");
+ }
+
+ [Test]
+ public void OutputsEventReferenceLink()
+ {
+ var formatter = new HtmlOutputFormatter();
+ var method = Event<Second>("AnEvent");
+
+ formatter.FormatReferencable(method)
+ .ShouldEqual("<a href=\"Example/Second.htm#AnEvent\">AnEvent</a>");
+ }
+
+ private DeclaredType Type<T>()
+ {
+ return new DeclaredType(Identifier.FromType(typeof(T)), Namespace.Unresolved(Identifier.FromNamespace(typeof(T).Namespace)));
+ }
+
+ private Method Method<T>(string name)
+ {
+ return new Method(Identifier.FromMethod(typeof(T).GetMethod(name), typeof(T)), Type<T>());
+ }
+
+ private Property Property<T>(string name)
+ {
+ return new Property(Identifier.FromProperty(typeof(T).GetProperty(name), typeof(T)), Type<T>());
+ }
+
+ private Field Field<T>(string name)
+ {
+ return new Field(Identifier.FromField(typeof(T).GetField(name), typeof(T)), Type<T>());
+ }
+
+ private Event Event<T>(string name)
+ {
+ return new Event(Identifier.FromEvent(typeof(T).GetEvent(name), typeof(T)), Type<T>());
+ }
+ }
+}
Please sign in to comment.
Something went wrong with that request. Please try again.