mirror of
https://github.com/inspec/inspec
synced 2024-11-10 15:14:23 +00:00
introduce separate nav for docs in www/
This commit is contained in:
parent
511b084078
commit
7e7b42735a
7 changed files with 102 additions and 37 deletions
|
@ -12,8 +12,8 @@ page '/*.xml', layout: false
|
|||
page '/*.json', layout: false
|
||||
page '/*.txt', layout: false
|
||||
|
||||
# With alternative layout
|
||||
# page 'docs/*', layout: :sidebar, locals: { sidebar_layout: 'docs' }
|
||||
# With alternative layout: we send the sidebar request to the default layout
|
||||
page 'docs/*', layout: :layout, locals: { sidebar_layout: 'docs' }
|
||||
|
||||
# Proxy pages (http://middlemanapp.com/basics/dynamic-pages/)
|
||||
# proxy '/this-page-has-no-template.html', '/template-file.html', locals: {
|
||||
|
@ -28,6 +28,10 @@ configure :development do
|
|||
activate :livereload
|
||||
end
|
||||
|
||||
# Methods defined in the helpers block are available in templates
|
||||
require 'lib/sidebar_helpers'
|
||||
helpers SidebarHelpers
|
||||
|
||||
# Methods defined in the helpers block are available in templates
|
||||
# helpers do
|
||||
# def some_helper
|
||||
|
|
|
@ -30,7 +30,3 @@ sidebar_links:
|
|||
link: "/docs/reference/shell.html"
|
||||
- title: Ruby usage
|
||||
link: "/docs/reference/ruby_usage.html"
|
||||
- title: Contribute
|
||||
links:
|
||||
- title: Help build InSpec
|
||||
link: "/community"
|
46
www/lib/sidebar_helpers.rb
Normal file
46
www/lib/sidebar_helpers.rb
Normal file
|
@ -0,0 +1,46 @@
|
|||
# encoding: utf-8
|
||||
# helper methods for source/layouts/sidebar.slim
|
||||
module SidebarHelpers
|
||||
SIDEBAR_LAYOUTS = %w{docs}.freeze
|
||||
|
||||
def sidebar_data(sidebar_layout)
|
||||
unless SIDEBAR_LAYOUTS.include?(sidebar_layout)
|
||||
fail "'#{sidebar_layout}' is not a valid sidebar layout type."
|
||||
end
|
||||
|
||||
data.public_send(:"#{sidebar_layout}_sidebar").sidebar_links.dup
|
||||
end
|
||||
|
||||
def link_classes(current_url, item_link)
|
||||
'is-active' if same_link?(current_url, item_link.link)
|
||||
end
|
||||
|
||||
def print_sub_links?(current_url, item_link)
|
||||
return false unless sub_links?(item_link)
|
||||
|
||||
same_link?(item_link.link, current_url) ||
|
||||
active_child?(current_url, item_link)
|
||||
end
|
||||
|
||||
def same_link?(one, two)
|
||||
strip_trailing_slash(one) == strip_trailing_slash(two)
|
||||
end
|
||||
|
||||
def strip_trailing_slash(str)
|
||||
str.end_with?('/') ? str[0..-2] : str
|
||||
end
|
||||
|
||||
def active_child?(current_url, item_link)
|
||||
return false unless sub_links?(item_link)
|
||||
|
||||
sub_link_urls(item_link).include?(strip_trailing_slash(current_url))
|
||||
end
|
||||
|
||||
def sub_links?(item_link)
|
||||
item_link.respond_to?(:sub_links) && item_link.sub_links.count > 0
|
||||
end
|
||||
|
||||
def sub_link_urls(item)
|
||||
item.sub_links.collect { |sub| strip_trailing_slash(sub.link) }
|
||||
end
|
||||
end
|
|
@ -73,6 +73,3 @@ title: InSpec - Audit and Test Framework
|
|||
and configurations.
|
||||
h3.code-snippet--heading Extensible:
|
||||
p.code-snippet--text Easily create custom resources and share them.
|
||||
hr.home-divider
|
||||
h2.main-subhead.text-center The Guiding Principles of InSpec
|
||||
p Lorem ipsum...
|
||||
|
|
|
@ -8,34 +8,37 @@ nav#main-nav
|
|||
li.main-nav--link-ctas
|
||||
a.button.transparent.try-demo href="#" Try the Demo
|
||||
a.button.secondary href="https://downloads.chef.io/inspec" Download
|
||||
li.main-nav--link
|
||||
a href="/"
|
||||
i.main-nav--link-icon.fa.fa-home
|
||||
span.main-nav--link-text Overview
|
||||
li.main-nav--link
|
||||
a href="/tutorials"
|
||||
i.main-nav--link-icon.fa.fa-flask
|
||||
span.main-nav--link-text Tutorials
|
||||
li.main-nav--link
|
||||
a href="/docs"
|
||||
i.main-nav--link-icon.fa.fa-file-text-o
|
||||
span.main-nav--link-text Docs
|
||||
li.main-nav--link
|
||||
a href="/community"
|
||||
i.main-nav--link-icon.fa.fa-group
|
||||
span.main-nav--link-text Community
|
||||
li.main-nav--link
|
||||
a href="https://downloads.chef.io/inspec"
|
||||
i.main-nav--link-icon.fa.fa-download
|
||||
span.main-nav--link-text Downloads
|
||||
li.main-nav--link
|
||||
a href="https://github.com/chef/inspec"
|
||||
i.main-nav--link-icon.fa.fa-github
|
||||
span.main-nav--link-text Github Project
|
||||
li.main-nav--link
|
||||
a href="https://github.com/chef/inspec/blob/master/CONTRIBUTING.md"
|
||||
i.main-nav--link-icon.fa.fa-code-fork
|
||||
span.main-nav--link-text Contribute
|
||||
- if locals[:sidebar_layout] == 'docs'
|
||||
= partial "layouts/sidebar"
|
||||
- else
|
||||
li.main-nav--link
|
||||
a href="/"
|
||||
i.main-nav--link-icon.fa.fa-home
|
||||
span.main-nav--link-text Overview
|
||||
li.main-nav--link
|
||||
a href="/tutorials"
|
||||
i.main-nav--link-icon.fa.fa-flask
|
||||
span.main-nav--link-text Tutorials
|
||||
li.main-nav--link
|
||||
a href="/docs"
|
||||
i.main-nav--link-icon.fa.fa-file-text-o
|
||||
span.main-nav--link-text Docs
|
||||
li.main-nav--link
|
||||
a href="/community"
|
||||
i.main-nav--link-icon.fa.fa-group
|
||||
span.main-nav--link-text Community
|
||||
li.main-nav--link
|
||||
a href="https://downloads.chef.io/inspec"
|
||||
i.main-nav--link-icon.fa.fa-download
|
||||
span.main-nav--link-text Downloads
|
||||
li.main-nav--link
|
||||
a href="https://github.com/chef/inspec"
|
||||
i.main-nav--link-icon.fa.fa-github
|
||||
span.main-nav--link-text Github Project
|
||||
li.main-nav--link
|
||||
a href="https://github.com/chef/inspec/blob/master/CONTRIBUTING.md"
|
||||
i.main-nav--link-icon.fa.fa-code-fork
|
||||
span.main-nav--link-text Contribute
|
||||
|
||||
nav#main-nav-ctas
|
||||
a.button.transparent.try-demo href="#" Try the Demo
|
||||
|
|
19
www/source/layouts/_sidebar.slim
Normal file
19
www/source/layouts/_sidebar.slim
Normal file
|
@ -0,0 +1,19 @@
|
|||
.container__has-sidebar
|
||||
.row
|
||||
.main-sidebar
|
||||
- if locals[:sidebar_layout] == 'docs'
|
||||
form.main-sidebar--search action="/docs/search/" method="get"
|
||||
input type="text" placeholder="Search Documentation" name="q"
|
||||
ul.no-bullet
|
||||
- sidebar_data(sidebar_layout).each do |item|
|
||||
li.main-sidebar--heading
|
||||
h4 = item.title
|
||||
ul.main-sidebar--list.no-bullet
|
||||
- item.links.each do |item_link|
|
||||
li.main-sidebar--list--item class=link_classes(current_resource.url, item_link)
|
||||
= link_to item_link.title, item_link.link
|
||||
- if print_sub_links?(current_resource.url, item_link)
|
||||
ul.main-sidebar--list--item--dropdown.no-bullet
|
||||
- item_link.sub_links.each do |sub_link|
|
||||
li.main-sidebar--list--item class=link_classes(current_resource.url, sub_link)
|
||||
= link_to sub_link.title, sub_link.link
|
Loading…
Reference in a new issue