Skip to content

Commit

Permalink
Add docs for publishing-api
Browse files Browse the repository at this point in the history
This adds the documentation for the publishing-api docs.

The list of pages to import is hard coded. I've considered using the
GitHub API to fetch everything in the `/doc` directory. The downside to
that is that if pages are renamed, we'll inadvertently break the pages
here. Having a local list here allows us to set up redirects.
  • Loading branch information
tijmenb committed Dec 9, 2016
1 parent cfc5bff commit 7e5ac51
Show file tree
Hide file tree
Showing 11 changed files with 99 additions and 7 deletions.
14 changes: 14 additions & 0 deletions config.rb
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,23 @@

require_relative './lib/dashboard/dashboard'
require_relative './lib/external_doc'
require_relative './lib/publishing_api_docs'

helpers do
def dashboard
Dashboard.new
end

def publishing_api_pages
PublishingApiDocs.pages
end
end

ignore 'publishing_api_template.html.md.erb'

PublishingApiDocs.pages.each do |page|
proxy "/apis/publishing-api/#{page.filename}.html", "publishing_api_template.html", locals: {
page_title: page.title,
page: page,
}
end
5 changes: 5 additions & 0 deletions helpers/navigation_helpers.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
module NavigationHelpers
def active_page?(page_path)
current_page.path.start_with?(page_path) || current_page.data.parent == page_path
end
end
3 changes: 3 additions & 0 deletions lib/external_doc.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@ def self.fetch(url_to_markdown)
# remove the own title of the page
markdown = markdown.lines[2..-1].join.strip

# Make sure we link to the pages hosted here
markdown = markdown.gsub('.md', '.html')

markdown
end
end
35 changes: 35 additions & 0 deletions lib/publishing_api_docs.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
class PublishingApiDocs
PAGES = {
"api" => "API docs",
"dependency-resolution" => "Dependency resolution",
"link-expansion" => "Link expansion",
"model" => "Model",
"publishing-application-examples" => "Examples",
"rabbitmq" => "Message queue",
}

def self.pages
PAGES.map { |k, v| Page.new(k, v) }
end

class Page
attr_reader :filename, :title

def initialize(filename, title)
@filename = filename
@title = title
end

def source_url
"https://github.com/alphagov/publishing-api/blob/master/doc/#{filename}.md"
end

def edit_url
"https://github.com/alphagov/publishing-api/edit/master/doc/#{filename}.md"
end

def raw_source
"https://raw.githubusercontent.com/alphagov/publishing-api/master/doc/#{filename}.md"
end
end
end
14 changes: 14 additions & 0 deletions source/apis/publishing-api.html.md.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
---
layout: api_layout
title: Publishing API
navigation_weight: 15
---

The [Publishing API][repo] is the central
application for publishing to GOV.UK.

The docs here are imported from the [docs directory][docs-directory]
in the [publishing-api repo][repo].

[docs-directory]: https://github.com/alphagov/publishing-api/tree/master/doc
[repo]: https://github.com/alphagov/publishing-api
2 changes: 1 addition & 1 deletion source/index.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,6 @@ edit_url: https://github.com/alphagov/govuk-developers/edit/master/data/dashboar
<% end %>
<% end %>

<%= partial 'partials/source' %>
<%= partial 'partials/source', locals: { page: current_page.data } %>
</div>
</div>
17 changes: 16 additions & 1 deletion source/layouts/api_layout.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,30 @@
<nav class="toc">
<ul>
<li><%= link_to 'Search API', '/apis/search-api.html' %></li>
<li>
<%= link_to 'Publishing API', '/apis/publishing-api.html' %>
<ul>
<% publishing_api_pages.each do |page| %>
<li><%= link_to page.title, "/apis/publishing-api/#{page.filename}.html" %></li>
<% end %>
</ul>
</li>
</ul>
</nav>
</div>

<div class="app-pane__content">
<div id="content" class="technical-documentation">
<%= partial 'partials/header' %>
<% if locals.key?(:page) %>
<%= partial 'partials/source', page: page %>
<% end %>

<%= yield %>
<%= partial 'partials/source' %>

<% if locals.key?(:page) %>
<%= partial 'partials/source', page: page %>
<% end %>
</div>
</div>
<% end %>
4 changes: 2 additions & 2 deletions source/layouts/default.erb
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
<meta name="viewport" content="width=device-width">

<title>
<%= current_page.data.title %> - GOV.UK Developers Documentation
<%= locals.key?(:page_title) ? page_title : current_page.data.title %> - GOV.UK Developer Documentation
</title>

<link rel="stylesheet" href="/assets/css/stolen-from-docs.css">
Expand Down Expand Up @@ -41,7 +41,7 @@
<nav id="navigation" class="header__navigation">
<ul>
<% sitemap.resources.select { |p| p.data.navigation_weight }.sort_by { |p| p.data.navigation_weight }.each do |page| %>
<li class="<%= current_page.path.start_with?(page.path) ? "active" : "" %>">
<li class="<%= active_page?(page.path) ? "active" : "" %>">
<a href="<%= page.url %>">
<%= page.data.title %>
</a>
Expand Down
2 changes: 1 addition & 1 deletion source/partials/_header.html.erb
Original file line number Diff line number Diff line change
@@ -1 +1 @@
<h1 class="page-title"><%= current_page.data.title %></h1>
<h1 class="page-title"><%= locals.key?(:page_title) ? page_title : current_page.data.title %></h1>
4 changes: 2 additions & 2 deletions source/partials/_source.html.erb
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<div class="edit-links">
Something wrong? Something to add?
<%= link_to "View source on GitHub", current_page.data.source_url %> or
<%= link_to "edit directly on GitHub", current_page.data.edit_url %>.
<%= link_to "View source on GitHub", page.source_url %> or
<%= link_to "edit directly on GitHub", page.edit_url %>.
</div>
6 changes: 6 additions & 0 deletions source/publishing_api_template.html.md.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
layout: api_layout
parent: apis/publishing-api.html
---

<%= ExternalDoc.fetch(page.raw_source) %>

0 comments on commit 7e5ac51

Please sign in to comment.