Skip to content

Commit

Permalink
Contiv nav header is now automatically added to API documentation whe…
Browse files Browse the repository at this point in the history
…n generated

Signed-off-by: Bill Robinson <dseevr@users.noreply.github.com>
  • Loading branch information
dseevr committed Mar 22, 2017
1 parent 5f39b12 commit b65f0b8
Show file tree
Hide file tree
Showing 7 changed files with 97 additions and 28 deletions.
13 changes: 6 additions & 7 deletions scripts/build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -21,18 +21,17 @@ mkdir -p docs
mv contiv.html docs/
popd

# RAML doesn't currently support trailing slashes so we add them manually here

# altering the HTML requires a gem called Nokogiri
# create a tiny docker image so we don't have to reinstall Nokogiri every time
IMAGE_NAME="raml_trailing_slashes"
# because we have to do some tidying up of the output HTML and it requires some
# external dependencies, we use a small Docker image to do it.
# this image uses the same ruby:2.4.0-slim base as above.
IMAGE_NAME="contiv_api_documentation_cleanup"

if [[ "$(docker images -q $IMAGE_NAME:latest 2>/dev/null)" == "" ]]; then
docker build -t $IMAGE_NAME -f spec/Dockerfile.raml_trailing_slashes .
docker build -t $IMAGE_NAME -f spec/Dockerfile.cleanup .
fi

docker run --rm \
-u $(id -u):$(id -g) \
-v $(pwd):/files \
-w /files/spec \
$IMAGE_NAME /usr/local/bin/ruby raml_trailing_slashes.rb
$IMAGE_NAME /usr/local/bin/ruby cleanup.rb
File renamed without changes.
31 changes: 31 additions & 0 deletions spec/cleanup.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
#!/usr/bin/env ruby
# encoding: utf-8

require "nokogiri"

FILENAME = "docs/contiv.html"

doc = Nokogiri::HTML(File.read(FILENAME))

# add trailing slashes to all paths

node_groups = [
doc.css(".panel-title a").select { |n| n.text.start_with?("/") },
doc.css(".modal-title"),
]

node_groups.flatten.each do |node|
node.children.last.content = node.children.last.text + "/"
end

# insert additional <head> tag requirements for the contiv header

doc.at("head") << Nokogiri::HTML::DocumentFragment.parse(File.read("docs/head.html"))

# insert the contiv header html into the top of the <body>

doc.at("body").prepend_child(Nokogiri::HTML::DocumentFragment.parse(File.read("docs/body.html")))

# overwrite the original HTML file

File.write(FILENAME, doc.to_html)
26 changes: 26 additions & 0 deletions spec/docs/body.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
<div class="navbar-jumbotron">
<nav class="navbar navbar-inverse navbar-static-top" role="navigation">
<div class="container">
<div class="navbar-header">
<button type="button" class="navbar-toggle collapsed" data-toggle="collapse" data-target="#navbar" aria-expanded="false" aria-controls="navbar">
<span class="sr-only">Toggle navigation</span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
</button>
<a class="navbar-brand" href="/" style="color:$white"> Contiv </a>
</div>
<div class="collapse navbar-collapse" id="navbar">
<ul class="nav navbar-nav navbar-right main-nav">
<li><a href="/documents/">Docs</a></li>
<li><a href="https://github.com/contiv/install/releases">Download</a></li>
<li><a href="/documents/support/index.html">Support</a></li>
<li><a href="http://blogs.cisco.com/contiv">Blog</a></li>

<li><a href="https://github.com/contiv"target="_blank"><i class="fa fa-github" style="color:$white"></i></a></li>
<li><a href="https://contiv.herokuapp.com" target="_blank"><i class="fa fa-slack"style="color:$white"></i></a></li>
</ul>
</div>
</div>
</nav>
</div>
34 changes: 32 additions & 2 deletions spec/docs/contiv.html
Original file line number Diff line number Diff line change
Expand Up @@ -176,8 +176,37 @@
margin-bottom: 1em;
}
</style>
<link rel="shortcut icon" href="/assets/images/favicon.png">
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/font-awesome/4.5.0/css/font-awesome.min.css">
</head>
<body data-spy="scroll" data-target="#sidebar"><div class="container"><div class="row">
<body data-spy="scroll" data-target="#sidebar">
<div class="navbar-jumbotron">
<nav class="navbar navbar-inverse navbar-static-top" role="navigation">
<div class="container">
<div class="navbar-header">
<button type="button" class="navbar-toggle collapsed" data-toggle="collapse" data-target="#navbar" aria-expanded="false" aria-controls="navbar">
<span class="sr-only">Toggle navigation</span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
</button>
<a class="navbar-brand" href="/" style="color:$white"> Contiv </a>
</div>
<div class="collapse navbar-collapse" id="navbar">
<ul class="nav navbar-nav navbar-right main-nav">
<li><a href="/documents/">Docs</a></li>
<li><a href="https://github.com/contiv/install/releases">Download</a></li>
<li><a href="/documents/support/index.html">Support</a></li>
<li><a href="http://blogs.cisco.com/contiv">Blog</a></li>

<li><a href="https://github.com/contiv" target="_blank"><i class="fa fa-github" style="color:$white"></i></a></li>
<li><a href="https://contiv.herokuapp.com" target="_blank"><i class="fa fa-slack" style="color:$white"></i></a></li>
</ul>
</div>
</div>
</nav>
</div>
<div class="container"><div class="row">
<div class="col-md-9" role="main">
<div class="page-header">
<h1>Contiv API documentation <small>version v1</small>
Expand Down Expand Up @@ -9774,5 +9803,6 @@ <h3>Headers</h3>
<li><a href="#servicelbs">Service Load Balancers</a></li>
<li><a href="#tenants">Tenants</a></li>
</ul></div></div>
</div></div></body>
</div></div>
</body>
</html>
2 changes: 2 additions & 0 deletions spec/docs/head.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
<link rel="shortcut icon" href="/assets/images/favicon.png">
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/font-awesome/4.5.0/css/font-awesome.min.css">
19 changes: 0 additions & 19 deletions spec/raml_trailing_slashes.rb

This file was deleted.

0 comments on commit b65f0b8

Please sign in to comment.