Skip to content

Commit

Permalink
Emit badge when DeprecatedAnnotation is applied
Browse files Browse the repository at this point in the history
  • Loading branch information
bcardiff committed Apr 8, 2019
1 parent eb325dc commit 14c1722
Show file tree
Hide file tree
Showing 5 changed files with 31 additions and 0 deletions.
4 changes: 4 additions & 0 deletions src/compiler/crystal/tools/doc/constant.cr
Original file line number Diff line number Diff line change
Expand Up @@ -38,4 +38,8 @@ class Crystal::Doc::Constant
builder.field "summary", formatted_summary
end
end

def annotations(annotation_type)
@const.annotations(annotation_type)
end
end
14 changes: 14 additions & 0 deletions src/compiler/crystal/tools/doc/generator.cr
Original file line number Diff line number Diff line change
Expand Up @@ -300,6 +300,7 @@ class Crystal::Doc::Generator

def doc(context, string)
string = isolate_flag_lines string
string += build_flag_lines_from_annotations context
markdown = String.build do |io|
Markdown.parse string, MarkdownDocRenderer.new(context, io)
end
Expand Down Expand Up @@ -343,6 +344,19 @@ class Crystal::Doc::Generator
end
end

def build_flag_lines_from_annotations(context)
first = true
String.build do |io|
if anns = context.annotations(@program.deprecated_annotation)
anns.each do |ann|
io << "\n\n" if first
first = false
io << "DEPRECATED: #{DeprecatedAnnotation.from(ann).message}\n\n"
end
end
end
end

def compute_repository
# check whether inside git work-tree
`git rev-parse --is-inside-work-tree >/dev/null 2>&1`
Expand Down
5 changes: 5 additions & 0 deletions src/compiler/crystal/tools/doc/macro.cr
Original file line number Diff line number Diff line change
Expand Up @@ -139,4 +139,9 @@ class Crystal::Doc::Macro
builder.field "def", self.macro
end
end

def annotations(annotation_type)
# macros does not support annotations
nil
end
end
4 changes: 4 additions & 0 deletions src/compiler/crystal/tools/doc/method.cr
Original file line number Diff line number Diff line change
Expand Up @@ -223,4 +223,8 @@ class Crystal::Doc::Method
builder.field "def", self.def
end
end

def annotations(annotation_type)
@def.annotations(annotation_type)
end
end
4 changes: 4 additions & 0 deletions src/compiler/crystal/tools/doc/type.cr
Original file line number Diff line number Diff line change
Expand Up @@ -837,4 +837,8 @@ class Crystal::Doc::Type
builder.field "name", name
end
end

def annotations(annotation_type)
@type.annotations(annotation_type)
end
end

0 comments on commit 14c1722

Please sign in to comment.