Skip to content

Commit

Permalink
RAML now has trailing slashes manually appended to all paths
Browse files Browse the repository at this point in the history
Signed-off-by: Bill Robinson <dseevr@users.noreply.github.com>
  • Loading branch information
dseevr committed Mar 22, 2017
1 parent 9e817dc commit ce1f8e4
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 1 deletion.
19 changes: 18 additions & 1 deletion scripts/build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,24 @@ docker run --rm \
mv spec/netmaster.raml ./spec/contiv/libraries/netmaster.raml

# run the raml2html tool to generate docs under spec/docs
cd spec
pushd spec
make docs
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"

if [[ "$(docker images -q $IMAGE_NAME:latest 2>/dev/null)" == "" ]]; then
docker build -t $IMAGE_NAME -f spec/Dockerfile.raml_trailing_slashes .
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
5 changes: 5 additions & 0 deletions spec/Dockerfile.raml_trailing_slashes
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
FROM ruby:2.4.0-slim

ENV DEBIAN_FRONTEND=noninteractive

RUN apt-get update && apt-get -y install build-essential && gem install nokogiri
19 changes: 19 additions & 0 deletions spec/raml_trailing_slashes.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
#!/usr/bin/env ruby
# encoding: utf-8

require "nokogiri"

FILENAME = "docs/contiv.html"

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

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

File.write(FILENAME, doc.to_html)

0 comments on commit ce1f8e4

Please sign in to comment.