terraform/website/config.rb

101 lines
2.2 KiB
Ruby
Raw Normal View History

2014-10-22 05:21:19 +02:00
set :base_url, "https://www.terraform.io/"
2014-10-13 18:44:38 +02:00
activate :hashicorp do |h|
2015-10-26 04:58:36 +01:00
h.name = "terraform"
2017-06-08 02:14:54 +02:00
h.version = "0.9.8"
2015-10-26 04:58:36 +01:00
h.github_slug = "hashicorp/terraform"
end
2016-10-31 23:36:33 +01:00
helpers do
2017-04-05 18:52:21 +02:00
# Returns the FQDN of the image URL.
#
# @param [String] path
#
# @return [String]
def image_url(path)
File.join(base_url, image_path(path))
end
2016-10-31 23:36:33 +01:00
# Get the title for the page.
#
# @param [Middleman::Page] page
#
# @return [String]
def title_for(page)
if page && page.data.page_title
return "#{page.data.page_title} - Terraform by HashiCorp"
end
"Terraform by HashiCorp"
end
# Get the description for the page
#
# @param [Middleman::Page] page
#
# @return [String]
def description_for(page)
2017-04-05 17:28:34 +02:00
description = (page.data.description || "")
.gsub('"', '')
.gsub(/\n+/, ' ')
.squeeze(' ')
return escape_html(description)
2016-10-31 23:36:33 +01:00
end
# This helps by setting the "active" class for sidebar nav elements
# if the YAML frontmatter matches the expected value.
def sidebar_current(expected)
current = current_page.data.sidebar_current || ""
2017-04-05 17:28:34 +02:00
if current.start_with?(expected)
2016-10-31 23:36:33 +01:00
return " class=\"active\""
else
return ""
end
end
2017-04-05 17:28:34 +02:00
# Returns the id for this page.
# @return [String]
def body_id_for(page)
if !(name = page.data.sidebar_current).blank?
return "page-#{name.strip}"
end
if page.url == "/" || page.url == "/index.html"
return "page-home"
end
if !(title = page.data.page_title).blank?
return title
.downcase
.gsub('"', '')
.gsub(/[^\w]+/, '-')
.gsub(/_+/, '-')
.squeeze('-')
.squeeze(' ')
end
return ""
end
# Returns the list of classes for this page.
# @return [String]
def body_classes_for(page)
classes = []
if !(layout = page.data.layout).blank?
classes << "layout-#{page.data.layout}"
end
if !(title = page.data.page_title).blank?
title = title
.downcase
.gsub('"', '')
.gsub(/[^\w]+/, '-')
.gsub(/_+/, '-')
.squeeze('-')
.squeeze(' ')
classes << "page-#{title}"
end
return classes.join(" ")
end
2016-10-31 23:36:33 +01:00
end