Skip to content

Commit

Permalink
Docs flag to include everything in current project namespace
Browse files Browse the repository at this point in the history
  • Loading branch information
nobodywasishere committed Jul 17, 2024
1 parent 0cef61e commit bf612a7
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 8 deletions.
12 changes: 11 additions & 1 deletion src/compiler/crystal/command/docs.cr
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ class Crystal::Command
sitemap_priority = "1.0"
sitemap_changefreq = "never"
project_info = Doc::ProjectInfo.new
include_all = false

compiler = new_compiler

Expand Down Expand Up @@ -44,6 +45,7 @@ class Crystal::Command
opts.on("--output=DIR", "-o DIR", "Set the output directory (default: #{output_directory})") do |value|
output_directory = value
end

opts.on("--format=FORMAT", "-f FORMAT", "Set the output format [#{VALID_OUTPUT_FORMATS.join(", ")}] (default: #{output_format})") do |value|
if !VALID_OUTPUT_FORMATS.includes? value
STDERR.puts "Invalid format '#{value}'"
Expand Down Expand Up @@ -89,6 +91,10 @@ class Crystal::Command
compiler.prelude = prelude
end

opts.on("--include-all", "Include documentation for entire namespace") do
include_all = true
end

opts.on("-s", "--stats", "Enable statistics output") do
@progress_tracker.stats = true
end
Expand Down Expand Up @@ -138,7 +144,11 @@ class Crystal::Command
compiler.wants_doc = true
result = compiler.top_level_semantic sources

Doc::Generator.new(result.program, included_dirs, output_directory, output_format, sitemap_base_url, sitemap_priority, sitemap_changefreq, project_info).run
Doc::Generator.new(
result.program, included_dirs, output_directory, output_format,
sitemap_base_url, sitemap_priority, sitemap_changefreq,
project_info, include_all
).run

report_warnings
exit 1 if warnings_fail_on_exit?
Expand Down
14 changes: 7 additions & 7 deletions src/compiler/crystal/tools/doc/generator.cr
Original file line number Diff line number Diff line change
Expand Up @@ -21,14 +21,14 @@ class Crystal::Doc::Generator
FLAGS = FLAG_COLORS.keys

def self.new(program : Program, included_dirs : Array(String))
new(program, included_dirs, ".", "html", nil, "1.0", "never", ProjectInfo.new("test", "0.0.0-test"))
new(program, included_dirs, ".", "html", nil, "1.0", "never", ProjectInfo.new("test", "0.0.0-test"), false)
end

def initialize(@program : Program, @included_dirs : Array(String),
@output_dir : String, @output_format : String,
@sitemap_base_url : String?,
@sitemap_priority : String, @sitemap_changefreq : String,
@project_info : ProjectInfo)
def initialize(
@program : Program, @included_dirs : Array(String), @output_dir : String, @output_format : String,
@sitemap_base_url : String?, @sitemap_priority : String, @sitemap_changefreq : String,
@project_info : ProjectInfo, @include_all : Bool
)
@base_dir = Dir.current.chomp
@types = {} of Crystal::Type => Doc::Type
end
Expand Down Expand Up @@ -185,7 +185,7 @@ class Crystal::Doc::Generator
def must_include?(location : Crystal::Location)
case filename = location.filename
when String
@included_dirs.any? { |included_dir| filename.starts_with? included_dir }
@include_all || @included_dirs.any? { |included_dir| filename.starts_with? included_dir }
when VirtualFile
must_include? filename.expanded_location
else
Expand Down

0 comments on commit bf612a7

Please sign in to comment.