Skip to content

Commit

Permalink
restructure MicrositeEditButtonSettings
Browse files Browse the repository at this point in the history
  • Loading branch information
britneywright committed Oct 8, 2018
1 parent d55dddc commit be306ca
Show file tree
Hide file tree
Showing 6 changed files with 37 additions and 23 deletions.
9 changes: 7 additions & 2 deletions docs/src/main/tut/docs/settings.md
Original file line number Diff line number Diff line change
Expand Up @@ -328,8 +328,13 @@ micrositeConfigYaml := ConfigYml(
micrositeFooterText := Some("<b>Bob</b> the <i>Builder</i>")
```

- `micrositeEditButtonText`: This setting allows the optional inclusion and configuration of an edit button on pages with the docs layout. By default, it is set to `None` and not visible. If the setting is set to `Some` with given text, that text will appear on the button at the bottom of the page. The button links to the edit view of the page in it's repository. **This string is passed in unsanitized to the templating engine.**
- `micrositeEditButtonText`: This setting allows the optional inclusion and configuration of an edit button on pages
with the docs layout. The button links to the given path of the page in it's repository.
By default, it is set to `None` and not visible. To enable, set the MicrositeEditButton with text
for the button and the basePath for the file. The basePath is comprised of the file URL excluding the top-level
repository URL and should include the dynamic property `{{page.path}}` that will be generated for each page when Jekyll
compiles the site. **The strings are passed in unsanitized to the templating engine.**

```
micrositeEditButtonText := Some("Improve this page")
micrositeEditButton := Some(MicrositeEditButton("Improve this Page", "/edit/master/docs/src/main/tut/{{ page.path }}"))
```
15 changes: 9 additions & 6 deletions src/main/scala/microsites/MicrositeKeys.scala
Original file line number Diff line number Diff line change
Expand Up @@ -152,11 +152,12 @@ trait MicrositeKeys {
"Optional. Customize the second line in the footer."
)

val micrositeEditButtonText: SettingKey[Option[String]] = settingKey[Option[String]](
"Optional. Add a button with given string in DocsLayout pages that links to the file in the repository."
)

val publishMicrositeCommandKey: String = "publishMicrositeCommand"

val micrositeEditButton: SettingKey[Option[MicrositeEditButton]] =
settingKey[Option[MicrositeEditButton]](
"Optional. Add a button in DocsLayout pages that links to the file in the repository."
)
}

object MicrositeKeys extends MicrositeKeys
Expand Down Expand Up @@ -205,8 +206,7 @@ trait MicrositeAutoImportSettings extends MicrositeKeys {
shareOnSocial = micrositeShareOnSocial.value
),
templateTexts = MicrositeTemplateTexts(
footer = micrositeFooterText.value,
editButton = micrositeEditButtonText.value
micrositeFooterText.value
),
configYaml = configWithAllCustomVariables,
fileLocations = MicrositeFileLocations(
Expand Down Expand Up @@ -250,6 +250,9 @@ trait MicrositeAutoImportSettings extends MicrositeKeys {
gitHostingUrl = micrositeGitHostingUrl.value,
gitSidecarChat = micrositeGitterChannel.value,
gitSidecarChatUrl = micrositeGitterChannelUrl.value
),
editButtonSettings = MicrositeEditButtonSettings(
micrositeEditButton.value
)
))
}
Expand Down
2 changes: 1 addition & 1 deletion src/main/scala/microsites/MicrositesPlugin.scala
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ object MicrositesPlugin extends AutoPlugin {
micrositeGitterChannel := true,
micrositeGitterChannelUrl := s"${micrositeGithubOwner.value}/${micrositeGithubRepo.value}",
micrositeFooterText := Some(layouts.Layout.footer.toString),
micrositeEditButtonText := None,
micrositeEditButton := None,
micrositeGithubLinks := true,
includeFilter in makeSite := "*.html" | "*.css" | "*.png" | "*.jpg" | "*.jpeg" | "*.gif" | "*.js" | "*.swf" | "*.md" | "*.webm" | "*.ico" | "CNAME" | "*.yml" | "*.svg" | "*.json",
includeFilter in Jekyll := (includeFilter in makeSite).value,
Expand Down
17 changes: 8 additions & 9 deletions src/main/scala/microsites/layouts/DocsLayout.scala
Original file line number Diff line number Diff line change
Expand Up @@ -157,20 +157,19 @@ class DocsLayout(config: MicrositeSettings) extends Layout(config) {
List(script(src := "{{ site.baseurl }}/js/kazari.js"))
else List.empty[TypedTag[String]])

def editButton: Seq[TypedTag[String]] =
config.templateTexts.editButton match {
case Some(text) =>
Seq(
def editButton: Option[TypedTag[String]] =
config.editButtonSettings.button match {
case Some(button) =>
Some(
div(
cls := "edit-button",
a(
href := config.gitSiteUrl,
href := "/edit/master/modules/docs/src/main/tut/{{ page.path }}",
href := button.basePath,
cls := "btn-sm btn-info",
text
button.text
)
)
)
case None => Nil
))
case _ => None
}
}
7 changes: 6 additions & 1 deletion src/main/scala/microsites/microsites.scala
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,11 @@ case class MicrositeVisualSettings(
favicons: Seq[MicrositeFavicon],
shareOnSocial: Boolean)

case class MicrositeTemplateTexts(footer: Option[String], editButton: Option[String])
case class MicrositeTemplateTexts(footer: Option[String])

case class MicrositeEditButton(text: String, basePath: String)

case class MicrositeEditButtonSettings(button: Option[MicrositeEditButton])

case class MicrositeSettings(
identity: MicrositeIdentitySettings,
Expand All @@ -89,6 +93,7 @@ case class MicrositeSettings(
fileLocations: MicrositeFileLocations,
urlSettings: MicrositeUrlSettings,
gitSettings: MicrositeGitSettings,
editButtonSettings: MicrositeEditButtonSettings,
micrositeKazariSettings: KazariSettings) {

def gitSiteUrl: String = {
Expand Down
10 changes: 6 additions & 4 deletions src/test/scala/microsites/util/Arbitraries.scala
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ package microsites.util

import java.io.File

import microsites.MicrositeKeys._
import microsites.MicrositeKeys.{micrositeEditButton, _}
import microsites._
import org.scalacheck.Arbitrary
import org.scalacheck.Gen._
Expand Down Expand Up @@ -148,7 +148,7 @@ trait Arbitraries {
micrositeKazariDependencies dependenciesListArbitrary.arbitrary
micrositeKazariResolvers Arbitrary.arbitrary[Seq[String]]
micrositeFooterText Arbitrary.arbitrary[Option[String]]
micrositeEditButtonText Arbitrary.arbitrary[Option[String]]
micrositeEditButton Arbitrary.arbitrary[Option[MicrositeEditButton]]
} yield
MicrositeSettings(
MicrositeIdentitySettings(
Expand All @@ -167,8 +167,7 @@ trait Arbitraries {
favicon,
shareOnSocial),
MicrositeTemplateTexts(
micrositeFooterText,
micrositeEditButtonText
micrositeFooterText
),
micrositeConfigYaml,
MicrositeFileLocations(
Expand Down Expand Up @@ -196,6 +195,9 @@ trait Arbitraries {
gitHostingUrl,
gitSidecarChat,
gitSidecarChatUrl),
MicrositeEditButtonSettings(
micrositeEditButton
),
KazariSettings(
micrositeKazariEnabled,
micrositeKazariEvaluatorUrl,
Expand Down

0 comments on commit be306ca

Please sign in to comment.