Skip to content

Commit

Permalink
Add options to customize docs title
Browse files Browse the repository at this point in the history
  • Loading branch information
johnfairh committed Jun 22, 2019
1 parent c01a0ed commit 0da9fc8
Show file tree
Hide file tree
Showing 8 changed files with 37 additions and 9 deletions.
8 changes: 8 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,14 @@
* Show the extension declaration when documenting Swift extensions.
[John Fairhurst](https://github.com/johnfairh)

* Allow docs title customization. Include `--module-version` when it is set
and support `--title` to fully customize the title. Pass `{{module_version}}`
and `{{docs_title}}` to templates.
[Maximilian Alexander](https://github.com/mbalex99)
[John Fairhurst](https://github.com/johnfairh)
[#666](https://github.com/realm/jazzy/issues/666)
[#411](https://github.com/realm/jazzy/issues/411)

##### Bug Fixes

* Unfold member documentation when linked to from current web page.
Expand Down
10 changes: 8 additions & 2 deletions lib/jazzy/config.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
require 'pathname'
require 'uri'

require 'jazzy/doc'
require 'jazzy/podspec_documenter'
require 'jazzy/source_declaration/access_control_level'

Expand Down Expand Up @@ -213,9 +212,16 @@ def expand_path(path)

config_attr :version,
command_line: '--module-version VERSION',
description: 'module version. will be used when generating docset',
description: 'Version string to use as part of the the default docs '\
'title and inside the docset.',
default: '1.0'

config_attr :title,
command_line: '--title TITLE',
description: 'Title to display at the top of each page, overriding the '\
'default generated from module name and version.',
default: ''

config_attr :copyright,
command_line: '--copyright COPYRIGHT_MARKDOWN',
description: 'copyright markdown rendered at the bottom of the docs pages'
Expand Down
19 changes: 16 additions & 3 deletions lib/jazzy/doc.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,11 @@

module Jazzy
class Doc < Mustache
include Config::Mixin

self.template_name = 'doc'

def copyright
config = Config.instance
copyright = config.copyright || (
# Fake date is used to keep integration tests consistent
date = ENV['JAZZY_FAKE_DATE'] || DateTime.now.strftime('%Y-%m-%d')
Expand All @@ -28,7 +29,7 @@ def jazzy_version
end

def objc_first?
Config.instance.objc_mode && Config.instance.hide_declarations != 'objc'
config.objc_mode && config.hide_declarations != 'objc'
end

def language
Expand All @@ -40,7 +41,19 @@ def language_stub
end

def module_version
Config.instance.version
config.version
end

def docs_title
if config.title_configured
config.title
elsif config.version_configured
# Fake version for integration tests
version = ENV['JAZZY_FAKE_MODULE_VERSION'] || config.version
"#{config.module_name} #{version} Docs"
else
"#{config.module_name} Docs"
end
end
end
end
2 changes: 1 addition & 1 deletion lib/jazzy/themes/apple/templates/header.mustache
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<header>
<div class="content-wrapper">
<p><a href="{{path_to_root}}index.html">{{module_name}} version {{module_version}} Docs</a>{{#doc_coverage}} ({{doc_coverage}}% documented){{/doc_coverage}}</p>
<p><a href="{{path_to_root}}index.html">{{docs_title}}</a>{{#doc_coverage}} ({{doc_coverage}}% documented){{/doc_coverage}}</p>
{{#github_url}}
<p class="header-right"><a href="{{github_url}}"><img src="{{path_to_root}}img/gh.png"/>View on GitHub</a></p>
{{/github_url}}
Expand Down
2 changes: 1 addition & 1 deletion lib/jazzy/themes/fullwidth/templates/header.mustache
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<header class="header">
<p class="header-col header-col--primary">
<a class="header-link" href="{{path_to_root}}index.html">
{{module_name}} version {{module_version}} Docs
{{docs_title}}
</a>
{{#doc_coverage}} ({{doc_coverage}}% documented){{/doc_coverage}}
</p>
Expand Down
2 changes: 1 addition & 1 deletion lib/jazzy/themes/jony/templates/header.mustache
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<header>
<div class="content-wrapper">
<p>
<a href="{{path_to_root}}index.html">{{module_name}} version {{module_version}} Docs</a>
<a href="{{path_to_root}}index.html">{{docs_title}}</a>
<span class="no-mobile">{{#doc_coverage}} ({{doc_coverage}}% documented){{/doc_coverage}}</span>
</p>

Expand Down
1 change: 1 addition & 0 deletions spec/integration_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,7 @@ def configure_cocoapods
'JAZZY_FAKE_VERSION' => 'X.X.X',
'COCOAPODS_SKIP_UPDATE_MESSAGE' => 'TRUE',
'JAZZY_INTEGRATION_SPECS' => 'TRUE',
'JAZZY_FAKE_MODULE_VERSION' => 'Y.Y.Y',
}
s.default_args = []
s.replace_path ROOT.to_s, 'ROOT'
Expand Down
2 changes: 1 addition & 1 deletion spec/integration_specs
Submodule integration_specs updated 303 files

0 comments on commit 0da9fc8

Please sign in to comment.