Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Compiler] Add sitemap to doc generator #8348

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ compiler_spec: $(O)/compiler_spec ## Run compiler specs

.PHONY: docs
docs: ## Generate standard library documentation
$(BUILD_PATH) ./bin/crystal docs -b https://crystal-lang.org/api/latest src/docs_main.cr
$(BUILD_PATH) ./bin/crystal docs src/docs_main.cr $(DOCS_OPTIONS)

.PHONY: crystal
crystal: $(O)/crystal ## Build the compiler
Expand Down
8 changes: 6 additions & 2 deletions man/crystal.1
Original file line number Diff line number Diff line change
Expand Up @@ -175,8 +175,12 @@ Options:
.Pp
.It Fl o Ar DIR, Fl -output Ar DIR
Set the output directory (default: ./docs).
.It Fl b Ar URL, Fl -canonical-base-url Ar URL
Set the canonical base URL.
.It Fl b Ar URL, Fl -sitemap-base-url Ar URL
Set the sitemap base URL. Sitemap will only be generated when this option is set.
.It Fl -sitemap-priority Ar PRIO
Set the priority assigned to sitemap entries (default: 1.0).
.It Fl -sitemap-changefreq Ar FREQ
Set the changefreq assigned to sitemap entries (default: never).
.El
.Pp
.It
Expand Down
56 changes: 37 additions & 19 deletions spec/compiler/crystal/tools/doc/generator_spec.cr
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,15 @@ describe Doc::Generator do
describe "#must_include_toplevel?" do
it "returns false if program has nothing" do
program = Program.new
generator = Doc::Generator.new program, ["foo"], ".", "html", nil
generator = Doc::Generator.new program, ["foo"]
doc_type = Doc::Type.new generator, program

generator.must_include_toplevel?(doc_type).should be_false
end

it "returns true if program has constant" do
program = Program.new
generator = Doc::Generator.new program, ["foo"], ".", "html", nil
generator = Doc::Generator.new program, ["foo"]
doc_type = Doc::Type.new generator, program

constant = Const.new program, program, "Foo", 1.int32
Expand All @@ -24,7 +24,7 @@ describe Doc::Generator do

it "returns false if program has constant which is defined in other place" do
program = Program.new
generator = Doc::Generator.new program, ["foo"], ".", "html", nil
generator = Doc::Generator.new program, ["foo"]
doc_type = Doc::Type.new generator, program

constant = Const.new program, program, "Foo", 1.int32
Expand All @@ -36,7 +36,7 @@ describe Doc::Generator do

it "returns true if program has macro" do
program = Program.new
generator = Doc::Generator.new program, ["foo"], ".", "html", nil
generator = Doc::Generator.new program, ["foo"]
doc_type = Doc::Type.new generator, program

a_macro = Macro.new "foo"
Expand All @@ -48,7 +48,7 @@ describe Doc::Generator do

it "returns false if program has macro which is defined in other place" do
program = Program.new
generator = Doc::Generator.new program, ["foo"], ".", "html", nil
generator = Doc::Generator.new program, ["foo"]
doc_type = Doc::Type.new generator, program

a_macro = Macro.new "foo"
Expand All @@ -60,7 +60,7 @@ describe Doc::Generator do

it "returns true if program has method" do
program = Program.new
generator = Doc::Generator.new program, ["foo"], ".", "html", nil
generator = Doc::Generator.new program, ["foo"]
doc_type = Doc::Type.new generator, program

a_def = Def.new "foo"
Expand All @@ -72,7 +72,7 @@ describe Doc::Generator do

it "returns false if program has method which is defined in other place" do
program = Program.new
generator = Doc::Generator.new program, ["foo"], ".", "html", nil
generator = Doc::Generator.new program, ["foo"]
doc_type = Doc::Type.new generator, program

a_def = Def.new "foo"
Expand All @@ -86,7 +86,7 @@ describe Doc::Generator do
describe "#collect_constants" do
it "returns empty array when constants are private" do
program = Program.new
generator = Doc::Generator.new program, ["foo"], ".", "html", nil
generator = Doc::Generator.new program, ["foo"]
doc_type = Doc::Type.new generator, program

constant = Const.new program, program, "Foo", 1.int32
Expand All @@ -102,7 +102,7 @@ describe Doc::Generator do
describe "with a Deprecated annotation, and no docs" do
it "should generate just the Deprecated tag" do
program = Program.new
generator = Doc::Generator.new program, ["."], ".", "html", nil
generator = Doc::Generator.new program, ["."]
doc_type = Doc::Type.new generator, program

a_def = Def.new "foo"
Expand All @@ -115,7 +115,7 @@ describe Doc::Generator do
describe "with a Deprecated annotation, and docs" do
it "should generate both the docs and Deprecated tag" do
program = Program.new
generator = Doc::Generator.new program, ["."], ".", "html", nil
generator = Doc::Generator.new program, ["."]
doc_type = Doc::Type.new generator, program

a_def = Def.new "foo"
Expand All @@ -129,7 +129,7 @@ describe Doc::Generator do
describe "with no annotation, and no docs" do
it "should generate nothing" do
program = Program.new
generator = Doc::Generator.new program, ["."], ".", "html", nil
generator = Doc::Generator.new program, ["."]
doc_type = Doc::Type.new generator, program

a_def = Def.new "foo"
Expand All @@ -140,7 +140,7 @@ describe Doc::Generator do

it "should generate the first sentence" do
program = Program.new
generator = Doc::Generator.new program, ["."], ".", "html", nil
generator = Doc::Generator.new program, ["."]
doc_type = Doc::Type.new generator, program

a_def = Def.new "foo"
Expand All @@ -151,7 +151,7 @@ describe Doc::Generator do

it "should generate the first line" do
program = Program.new
generator = Doc::Generator.new program, ["."], ".", "html", nil
generator = Doc::Generator.new program, ["."]
doc_type = Doc::Type.new generator, program

a_def = Def.new "foo"
Expand All @@ -165,7 +165,7 @@ describe Doc::Generator do
describe "with a Deprecated annotation, and no docs" do
it "should generate just the Deprecated tag" do
program = Program.new
generator = Doc::Generator.new program, ["."], ".", "html", nil
generator = Doc::Generator.new program, ["."]
doc_type = Doc::Type.new generator, program

a_def = Def.new "foo"
Expand All @@ -178,7 +178,7 @@ describe Doc::Generator do
describe "with a Deprecated annotation, and docs" do
it "should generate both the docs and Deprecated tag" do
program = Program.new
generator = Doc::Generator.new program, ["."], ".", "html", nil
generator = Doc::Generator.new program, ["."]
doc_type = Doc::Type.new generator, program

a_def = Def.new "foo"
Expand All @@ -192,7 +192,7 @@ describe Doc::Generator do
describe "with no annotation, and no docs" do
it "should generate nothing" do
program = Program.new
generator = Doc::Generator.new program, ["."], ".", "html", nil
generator = Doc::Generator.new program, ["."]
doc_type = Doc::Type.new generator, program

a_def = Def.new "foo"
Expand All @@ -203,7 +203,7 @@ describe Doc::Generator do

it "should generate the full document" do
program = Program.new
generator = Doc::Generator.new program, ["."], ".", "html", nil
generator = Doc::Generator.new program, ["."]
doc_type = Doc::Type.new generator, program

a_def = Def.new "foo"
Expand All @@ -214,7 +214,7 @@ describe Doc::Generator do

it "should generate the full document" do
program = Program.new
generator = Doc::Generator.new program, ["."], ".", "html", nil
generator = Doc::Generator.new program, ["."]
doc_type = Doc::Type.new generator, program

a_def = Def.new "foo"
Expand All @@ -227,7 +227,7 @@ describe Doc::Generator do
describe "crystal repo" do
it "inserts pseudo methods" do
program = Program.new
generator = Doc::Generator.new program, ["."], ".", "html", nil
generator = Doc::Generator.new program, ["."]
doc_type = Doc::Type.new generator, program
generator.is_crystal_repo = true

Expand All @@ -244,4 +244,22 @@ describe Doc::Generator do
doc_method.doc.not_nil!.should_not contain %(NOTE: This is a pseudo-method)
end
end

it "generates sitemap" do
program = Program.new
generator = Doc::Generator.new program, ["."]
doc_type = Doc::Type.new generator, program

Doc::SitemapTemplate.new([doc_type], "http://example.com/api/1.0", "0.8", "monthly").to_s.should eq <<-XML
<?xml version="1.0" encoding="UTF-8"?>
<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">
<url>
<loc>http://example.com/api/1.0/toplevel.html</loc>
<priority>0.8</priority>
<changefreq>monthly</changefreq>
</url>
</urlset>

XML
end
end
22 changes: 11 additions & 11 deletions spec/compiler/crystal/tools/doc/macro_spec.cr
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ describe Doc::Macro do
describe "args_to_s" do
it "shows simple args" do
program = Program.new
generator = Doc::Generator.new program, ["."], ".", "html", nil
generator = Doc::Generator.new program, ["."]
doc_type = Doc::Type.new generator, program

a_macro = Macro.new "foo", ["foo".arg, "bar".arg]
Expand All @@ -14,7 +14,7 @@ describe Doc::Macro do

it "shows splat arg" do
program = Program.new
generator = Doc::Generator.new program, ["."], ".", "html", nil
generator = Doc::Generator.new program, ["."]
doc_type = Doc::Type.new generator, program

a_macro = Macro.new "foo", ["foo".arg], splat_index: 0
Expand All @@ -24,7 +24,7 @@ describe Doc::Macro do

it "shows simple arg and splat arg" do
program = Program.new
generator = Doc::Generator.new program, ["."], ".", "html", nil
generator = Doc::Generator.new program, ["."]
doc_type = Doc::Type.new generator, program

a_macro = Macro.new "foo", ["foo".arg, "bar".arg], splat_index: 1
Expand All @@ -34,7 +34,7 @@ describe Doc::Macro do

it "shows double splat arg" do
program = Program.new
generator = Doc::Generator.new program, ["."], ".", "html", nil
generator = Doc::Generator.new program, ["."]
doc_type = Doc::Type.new generator, program

a_macro = Macro.new "foo", double_splat: "foo".arg
Expand All @@ -44,7 +44,7 @@ describe Doc::Macro do

it "shows double splat arg" do
program = Program.new
generator = Doc::Generator.new program, ["."], ".", "html", nil
generator = Doc::Generator.new program, ["."]
doc_type = Doc::Type.new generator, program

a_macro = Macro.new "foo", double_splat: "foo".arg
Expand All @@ -54,7 +54,7 @@ describe Doc::Macro do

it "shows simple arg and double splat arg" do
program = Program.new
generator = Doc::Generator.new program, ["."], ".", "html", nil
generator = Doc::Generator.new program, ["."]
doc_type = Doc::Type.new generator, program

a_macro = Macro.new "foo", ["foo".arg], double_splat: "bar".arg
Expand All @@ -64,7 +64,7 @@ describe Doc::Macro do

it "shows block arg" do
program = Program.new
generator = Doc::Generator.new program, ["."], ".", "html", nil
generator = Doc::Generator.new program, ["."]
doc_type = Doc::Type.new generator, program

a_macro = Macro.new "foo", block_arg: "foo".arg
Expand All @@ -74,7 +74,7 @@ describe Doc::Macro do

it "shows simple arg and block arg" do
program = Program.new
generator = Doc::Generator.new program, ["."], ".", "html", nil
generator = Doc::Generator.new program, ["."]
doc_type = Doc::Type.new generator, program

a_macro = Macro.new "foo", ["foo".arg], block_arg: "bar".arg
Expand All @@ -84,7 +84,7 @@ describe Doc::Macro do

it "shows external name of arg" do
program = Program.new
generator = Doc::Generator.new program, ["."], ".", "html", nil
generator = Doc::Generator.new program, ["."]
doc_type = Doc::Type.new generator, program

a_macro = Macro.new "foo", ["foo".arg(external_name: "bar")]
Expand All @@ -94,7 +94,7 @@ describe Doc::Macro do

it "shows external name of arg with quotes and escaping" do
program = Program.new
generator = Doc::Generator.new program, ["."], ".", "html", nil
generator = Doc::Generator.new program, ["."]
doc_type = Doc::Type.new generator, program

a_macro = Macro.new "foo", ["foo".arg(external_name: "<<-< uouo fish life")]
Expand All @@ -104,7 +104,7 @@ describe Doc::Macro do

it "shows default value with highlighting" do
program = Program.new
generator = Doc::Generator.new program, ["."], ".", "html", nil
generator = Doc::Generator.new program, ["."]
doc_type = Doc::Type.new generator, program

a_macro = Macro.new "foo", ["foo".arg(default_value: 1.int32)]
Expand Down
Loading