Skip to content

Commit

Permalink
Revert " Add --canonical-base-url cli option to docs generator (cryst…
Browse files Browse the repository at this point in the history
…al-lang#5990)"

This reverts commit a6d0571.
  • Loading branch information
straight-shoota committed Oct 18, 2019
1 parent 10d92bb commit 320ec1d
Show file tree
Hide file tree
Showing 7 changed files with 18 additions and 29 deletions.
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

.PHONY: crystal
crystal: $(O)/crystal ## Build the compiler
Expand Down
7 changes: 1 addition & 6 deletions src/compiler/crystal/command/docs.cr
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ class Crystal::Command
private def docs
output_format = "html"
output_directory = File.join(".", "docs")
canonical_base_url = nil

compiler = Compiler.new

Expand All @@ -34,10 +33,6 @@ class Crystal::Command
output_format = value
end

opts.on("--canonical-base-url=URL", "-b URL", "Set the canonical base url") do |value|
canonical_base_url = value
end

opts.on("-D FLAG", "--define FLAG", "Define a compile-time flag") do |flag|
compiler.flags << flag
end
Expand Down Expand Up @@ -88,6 +83,6 @@ class Crystal::Command
compiler.wants_doc = true
result = compiler.top_level_semantic sources

Doc::Generator.new(result.program, included_dirs, output_directory, output_format, canonical_base_url).run
Doc::Generator.new(result.program, included_dirs, output_directory, output_format).run
end
end
6 changes: 3 additions & 3 deletions src/compiler/crystal/tools/doc/generator.cr
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ class Crystal::Doc::Generator
},
}

def initialize(@program : Program, @included_dirs : Array(String), @output_dir : String, @output_format : String, @canonical_base_url : String?)
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 = ""
Expand Down Expand Up @@ -89,7 +89,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, @canonical_base_url)
File.write File.join(@output_dir, "index.html"), MainTemplate.new(body, types, repository_name)

main_index = Main.new(raw_body, Type.new(self, @program), repository_name)
File.write File.join(@output_dir, "index.json"), main_index
Expand All @@ -112,7 +112,7 @@ class Crystal::Doc::Generator
filename = File.join(dir, "#{type.name}.html")
end

File.write filename, TypeTemplate.new(type, all_types, @canonical_base_url)
File.write filename, TypeTemplate.new(type, all_types)

next if type.program?

Expand Down
16 changes: 2 additions & 14 deletions src/compiler/crystal/tools/doc/html/_head.html
Original file line number Diff line number Diff line change
@@ -1,18 +1,6 @@
<meta charset="utf-8">
<meta charset="utf-8" />
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="generator" content="Crystal Docs <%= Crystal::VERSION %>">

<%- if base_url = canonical_base_url -%>
<%- if path = type.try(&.path) -%>
<%- base_url = File.join(base_url, path) -%>
<%- end -%>
<link rel="canonical" href="<%= base_url %>">
<% end -%>
<%- base_path = type.try(&.path_to("")) -%>

<link href="<%= base_path %>css/style.css" rel="stylesheet" type="text/css">

<link href="<%= base_path %>css/style.css" rel="stylesheet" type="text/css" />
<script type="text/javascript" src="<%= base_path %>js/doc.js"></script>
<script type="text/javascript">
CrystalDoc.base_path = "<%= base_path %>";
</script>
5 changes: 4 additions & 1 deletion src/compiler/crystal/tools/doc/html/main.html
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
<!DOCTYPE html>
<html lang="en">
<head>
<%= HeadTemplate.new(nil, canonical_base_url) %>
<%= HeadTemplate.new("") %>
<meta id="repository-name" content="<%= repository_name %>">
<title>README - <%= repository_name %></title>
<script type="text/javascript">
CrystalDoc.base_path = "";
</script>
</head>
<body>

Expand Down
5 changes: 4 additions & 1 deletion src/compiler/crystal/tools/doc/html/type.html
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
<!DOCTYPE html>
<html lang="en">
<head>
<%= HeadTemplate.new(type, canonical_base_url) %>
<%= HeadTemplate.new(type.path_to "") %>
<meta id="repository-name" content="<%= type.repository_name %>">
<title><%= type.full_name %> - <%= type.repository_name %></title>
<script type="text/javascript">
CrystalDoc.base_path = "<%= type.path_to "" %>";
</script>
</head>
<body>

Expand Down
6 changes: 3 additions & 3 deletions src/compiler/crystal/tools/doc/templates.cr
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
require "ecr/macros"

module Crystal::Doc
record TypeTemplate, type : Type, types : Array(Type), canonical_base_url : String? do
record TypeTemplate, type : Type, types : Array(Type) do
ECR.def_to_s "#{__DIR__}/html/type.html"
end

Expand All @@ -25,11 +25,11 @@ module Crystal::Doc
ECR.def_to_s "#{__DIR__}/html/_other_types.html"
end

record MainTemplate, body : String, types : Array(Type), repository_name : String, canonical_base_url : String? do
record MainTemplate, body : String, types : Array(Type), repository_name : String do
ECR.def_to_s "#{__DIR__}/html/main.html"
end

record HeadTemplate, type : Type?, canonical_base_url : String? do
record HeadTemplate, base_path : String do
ECR.def_to_s "#{__DIR__}/html/_head.html"
end

Expand Down

0 comments on commit 320ec1d

Please sign in to comment.