diff --git a/spec/compiler/crystal/tools/doc/generator_spec.cr b/spec/compiler/crystal/tools/doc/generator_spec.cr index 37c56d6450cb..ae419946eed3 100644 --- a/spec/compiler/crystal/tools/doc/generator_spec.cr +++ b/spec/compiler/crystal/tools/doc/generator_spec.cr @@ -4,7 +4,7 @@ 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 @@ -12,7 +12,7 @@ describe Doc::Generator do 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 @@ -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 @@ -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" @@ -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" @@ -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" @@ -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" @@ -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 @@ -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" @@ -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" @@ -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" @@ -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" @@ -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" @@ -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" @@ -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" @@ -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" @@ -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" @@ -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" @@ -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 diff --git a/spec/compiler/crystal/tools/doc/macro_spec.cr b/spec/compiler/crystal/tools/doc/macro_spec.cr index 533f0e6570f2..545dc9019cd8 100644 --- a/spec/compiler/crystal/tools/doc/macro_spec.cr +++ b/spec/compiler/crystal/tools/doc/macro_spec.cr @@ -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] @@ -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 @@ -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 @@ -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 @@ -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 @@ -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 @@ -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 @@ -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 @@ -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")] @@ -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")] @@ -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)] diff --git a/spec/compiler/crystal/tools/doc/method_spec.cr b/spec/compiler/crystal/tools/doc/method_spec.cr index 321cf0229bb4..b30a4b686419 100644 --- a/spec/compiler/crystal/tools/doc/method_spec.cr +++ b/spec/compiler/crystal/tools/doc/method_spec.cr @@ -4,7 +4,7 @@ describe Doc::Method 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_def = Def.new "foo", ["foo".arg, "bar".arg] @@ -14,7 +14,7 @@ describe Doc::Method do it "shows splat 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_def = Def.new "foo", ["foo".arg], splat_index: 0 @@ -24,7 +24,7 @@ describe Doc::Method do it "shows underscore restriction" 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", ["foo".arg(restriction: Crystal::Underscore.new)], splat_index: 0 @@ -34,7 +34,7 @@ describe Doc::Method do it "shows double splat 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_def = Def.new "foo", double_splat: "foo".arg @@ -44,7 +44,7 @@ describe Doc::Method do it "shows block 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_def = Def.new "foo", block_arg: "foo".arg @@ -54,7 +54,7 @@ describe Doc::Method do it "shows block args with underscore" 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", block_arg: "foo".arg(restriction: Crystal::ProcNotation.new(([Crystal::Underscore.new] of Crystal::ASTNode), Crystal::Underscore.new)) @@ -64,7 +64,7 @@ describe Doc::Method do it "shows block args if a def has `yield`" 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", yields: 1 @@ -74,7 +74,7 @@ describe Doc::Method do it "shows return type restriction" 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", return_type: "Foo".path @@ -84,7 +84,7 @@ describe Doc::Method do it "shows args and return type restriction" 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", ["foo".arg], return_type: "Foo".path @@ -94,7 +94,7 @@ describe Doc::Method 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_def = Def.new "foo", ["foo".arg(external_name: "bar")] @@ -104,7 +104,7 @@ describe Doc::Method 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_def = Def.new "foo", ["foo".arg(external_name: "<<-< uouo fish life")] @@ -114,7 +114,7 @@ describe Doc::Method do it "shows typeof restriction of arg 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_def = Def.new "foo", ["foo".arg(restriction: TypeOf.new([1.int32] of ASTNode))] @@ -124,7 +124,7 @@ describe Doc::Method do it "shows default value of arg 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_def = Def.new "foo", ["foo".arg(default_value: 1.int32)] @@ -142,7 +142,7 @@ describe Doc::Method do end end ", wants_doc: true).program - generator = Doc::Generator.new program, [""], ".", "html", nil + generator = Doc::Generator.new program, [""] method = generator.type(program.types["Foo"]).lookup_method("foo").not_nil! method.doc.should eq("Some docs") method.doc_copied_from.should be_nil @@ -162,7 +162,7 @@ describe Doc::Method do end end ", wants_doc: true).program - generator = Doc::Generator.new program, [""], ".", "html", nil + generator = Doc::Generator.new program, [""] method = generator.type(program.types["Bar"]).lookup_method("foo").not_nil! method.doc.should eq("Some docs") method.doc_copied_from.should eq(generator.type(program.types["Foo"])) @@ -180,7 +180,7 @@ describe Doc::Method do end end ", wants_doc: true).program - generator = Doc::Generator.new program, [""], ".", "html", nil + generator = Doc::Generator.new program, [""] method = generator.type(program.types["Foo"]).lookup_method("foo").not_nil! method.doc.should eq("Some docs") method.doc_copied_from.should be_nil @@ -201,7 +201,7 @@ describe Doc::Method do end end ", wants_doc: true).program - generator = Doc::Generator.new program, [""], ".", "html", nil + generator = Doc::Generator.new program, [""] method = generator.type(program.types["Bar"]).lookup_method("foo").not_nil! method.doc.should eq("Some docs") method.doc_copied_from.should be_nil @@ -226,7 +226,7 @@ describe Doc::Method do end end ", wants_doc: true).program - generator = Doc::Generator.new program, [""], ".", "html", nil + generator = Doc::Generator.new program, [""] method = generator.type(program.types["Bar"]).lookup_method("foo").not_nil! method.doc.should eq("Before\n\nSome docs\n\nAfter") method.doc_copied_from.should be_nil diff --git a/spec/compiler/crystal/tools/doc/type_spec.cr b/spec/compiler/crystal/tools/doc/type_spec.cr index f40549dd992b..f9651b4632c7 100644 --- a/spec/compiler/crystal/tools/doc/type_spec.cr +++ b/spec/compiler/crystal/tools/doc/type_spec.cr @@ -23,7 +23,7 @@ describe Doc::Type do alias_type = program.types["Alias"] alias_type.add_location(Location.new("./foo.cr", 1, 1)) - generator = Doc::Generator.new program, ["."], ".", "html", nil + generator = Doc::Generator.new program, ["."] doc_alias_type = generator.type(alias_type) doc_alias_type.types.size.should eq(0) @@ -39,7 +39,7 @@ describe Doc::Type do program = result.program - generator = Doc::Generator.new program, [""], ".", "html", nil + generator = Doc::Generator.new program, [""] foo = generator.type(program.types["Foo"]) foo.lookup_class_method("new").should_not be_nil foo.lookup_class_method("new", 1).should_not be_nil diff --git a/src/compiler/crystal/tools/doc/generator.cr b/src/compiler/crystal/tools/doc/generator.cr index 79418412fbf7..c1fe38752198 100644 --- a/src/compiler/crystal/tools/doc/generator.cr +++ b/src/compiler/crystal/tools/doc/generator.cr @@ -28,7 +28,12 @@ class Crystal::Doc::Generator }, } - def initialize(@program : Program, @included_dirs : Array(String), @output_dir : String, @output_format : String) + def self.new(program : Program, included_dirs : Array(String)) + new(program, included_dirs, ".", "html", nil) + end + + def initialize(@program : Program, @included_dirs : Array(String), + @output_dir : String, @output_format : String) @base_dir = Dir.current.chomp @types = {} of Crystal::Type => Doc::Type @repo_name = ""