Skip to content

Commit

Permalink
Merge pull request #439 from alphagov/component-documentation-api
Browse files Browse the repository at this point in the history
Serve govuk-component documentation as JSON
  • Loading branch information
bradwright committed Aug 15, 2014
2 parents 7cc1233 + 5e40135 commit e604489
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 1 deletion.
7 changes: 6 additions & 1 deletion app/controllers/root_controller.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
class RootController < ApplicationController
layout false

before_filter :validate_template_param
before_filter :validate_template_param, :except => [:govuk_component_docs]

rescue_from ActionView::MissingTemplate, :with => :error_404

Expand All @@ -15,6 +15,11 @@ def raw_govuk_component_template
render_raw_template("govuk_component", params[:template])
end

def govuk_component_docs
component_doc = JSON.parse(File.read(File.join(Rails.root, 'app', 'views', 'govuk_component', 'docs.json')))
render :json => component_doc
end

NON_LAYOUT_TEMPLATES = %w(
alpha_label
barclays_epdq
Expand Down
8 changes: 8 additions & 0 deletions app/views/govuk_component/docs.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
[
{
"id": "beta_label",
"name": "Beta Banner",
"description": "A banner than indicates content is in a beta phase",
"fixtures": {}
}
]
1 change: 1 addition & 0 deletions config/routes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
controller "root", :format => false do
get "/templates/:template.raw.html.erb" => :raw_root_template
get "/templates/govuk_component/:template.raw.html.erb" => :raw_govuk_component_template
get "/templates/govuk_component/docs" => :govuk_component_docs
get "/templates/:template.html.erb" => :template
end

Expand Down

0 comments on commit e604489

Please sign in to comment.