diff --git a/Makefile b/Makefile index c86ee5a9d4f7..607dc23c3137 100644 --- a/Makefile +++ b/Makefile @@ -45,6 +45,7 @@ LIB_CRYSTAL_TARGET = src/ext/libcrystal.a DEPS = $(LLVM_EXT_OBJ) $(LIB_CRYSTAL_TARGET) CFLAGS += -fPIC $(if $(debug),-g -O0) CXXFLAGS += $(if $(debug),-g -O0) +CRYSTAL_VERSION ?= $(shell cat src/VERSION) ifeq ($(shell command -v ld.lld >/dev/null && uname -s),Linux) EXPORT_CC ?= CC="cc -fuse-ld=lld" @@ -90,7 +91,7 @@ compiler_spec: $(O)/compiler_spec ## Run compiler specs .PHONY: docs docs: ## Generate standard library documentation - $(BUILD_PATH) ./bin/crystal docs src/docs_main.cr $(DOCS_OPTIONS) + $(BUILD_PATH) ./bin/crystal docs src/docs_main.cr $(DOCS_OPTIONS) --project-name=Crystal --project-version=$(CRYSTAL_VERSION) .PHONY: crystal crystal: $(O)/crystal ## Build the compiler diff --git a/src/compiler/crystal/command/docs.cr b/src/compiler/crystal/command/docs.cr index 2b2f89f11b5d..1682f6327e5c 100644 --- a/src/compiler/crystal/command/docs.cr +++ b/src/compiler/crystal/command/docs.cr @@ -12,6 +12,8 @@ class Crystal::Command sitemap_base_url = nil sitemap_priority = "1.0" sitemap_changefreq = "never" + project_name = nil + project_version = "master" compiler = Compiler.new @@ -24,6 +26,14 @@ class Crystal::Command Options: BANNER + opts.on("--project-name=NAME", "Set project name") do |value| + project_name = value + end + + opts.on("--project-version=VERSION", "Set project version") do |value| + project_version = value + end + opts.on("--output=DIR", "-o DIR", "Set the output directory (default: #{output_directory})") do |value| output_directory = value end @@ -88,6 +98,10 @@ class Crystal::Command setup_compiler_warning_options(opts, compiler) end + unless project_name + abort "missing --project-name" + end + if options.empty? sources = [Compiler::Source.new("require", %(require "./src/**"))] included_dirs = [] of String @@ -103,7 +117,8 @@ 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).run + project_info = Doc::ProjectInfo.new(project_name.not_nil!, project_version) + Doc::Generator.new(result.program, included_dirs, output_directory, output_format, sitemap_base_url, sitemap_priority, sitemap_changefreq, project_info).run report_warnings result exit 1 if warnings_fail_on_exit?(result) diff --git a/src/compiler/crystal/tools/doc/generator.cr b/src/compiler/crystal/tools/doc/generator.cr index b49429ee8889..1818f7d97edb 100644 --- a/src/compiler/crystal/tools/doc/generator.cr +++ b/src/compiler/crystal/tools/doc/generator.cr @@ -1,3 +1,5 @@ +record Crystal::Doc::ProjectInfo, name : String, version : String + class Crystal::Doc::Generator getter program : Program @@ -5,6 +7,7 @@ class Crystal::Doc::Generator property is_crystal_repo : Bool @repository : String? = nil getter repository_name = "" + getter project_info # Adding a flag and associated css class will add support in parser FLAG_COLORS = { @@ -29,13 +32,14 @@ class Crystal::Doc::Generator } def self.new(program : Program, included_dirs : Array(String)) - new(program, included_dirs, ".", "html", nil, "1.0", "never") + new(program, included_dirs, ".", "html", nil, "1.0", "never", ProjectInfo.new("test", "0.0.0-test")) 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) + @sitemap_priority : String, @sitemap_changefreq : String, + @project_info : ProjectInfo) @base_dir = Dir.current.chomp @types = {} of Crystal::Type => Doc::Type @repo_name = "" @@ -95,7 +99,7 @@ class Crystal::Doc::Generator raw_body = read_readme body = doc(program_type, raw_body) - File.write File.join(@output_dir, "index.html"), MainTemplate.new(body, types, repository_name) + File.write File.join(@output_dir, "index.html"), MainTemplate.new(body, types, project_info) main_index = Main.new(raw_body, Type.new(self, @program), repository_name) File.write File.join(@output_dir, "index.json"), main_index @@ -124,7 +128,7 @@ class Crystal::Doc::Generator filename = File.join(dir, "#{type.name}.html") end - File.write filename, TypeTemplate.new(type, all_types) + File.write filename, TypeTemplate.new(type, all_types, project_info) next if type.program? diff --git a/src/compiler/crystal/tools/doc/html/_sidebar.html b/src/compiler/crystal/tools/doc/html/_sidebar.html index bd4005b51978..b255f19856ac 100644 --- a/src/compiler/crystal/tools/doc/html/_sidebar.html +++ b/src/compiler/crystal/tools/doc/html/_sidebar.html @@ -4,6 +4,18 @@ +