Skip to content

Commit

Permalink
add 'Edit Page' feature to doc pages
Browse files Browse the repository at this point in the history
  • Loading branch information
britneywright committed Oct 5, 2018
1 parent 9c06a5a commit d55dddc
Show file tree
Hide file tree
Showing 7 changed files with 42 additions and 4 deletions.
6 changes: 6 additions & 0 deletions docs/src/main/tut/docs/settings.md
Original file line number Diff line number Diff line change
Expand Up @@ -327,3 +327,9 @@ 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 := Some("Improve this page")
```
4 changes: 4 additions & 0 deletions src/main/resources/_sass/_docs.scss
Original file line number Diff line number Diff line change
Expand Up @@ -198,6 +198,10 @@
}
}

.edit-button {
padding: 0 30px 10px;
}

@media (min-width: 768px) {
#wrapper {
padding-left: 250px;
Expand Down
7 changes: 6 additions & 1 deletion src/main/scala/microsites/MicrositeKeys.scala
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,10 @@ 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"
}

Expand Down Expand Up @@ -201,7 +205,8 @@ trait MicrositeAutoImportSettings extends MicrositeKeys {
shareOnSocial = micrositeShareOnSocial.value
),
templateTexts = MicrositeTemplateTexts(
footer = micrositeFooterText.value
footer = micrositeFooterText.value,
editButton = micrositeEditButtonText.value
),
configYaml = configWithAllCustomVariables,
fileLocations = MicrositeFileLocations(
Expand Down
1 change: 1 addition & 0 deletions src/main/scala/microsites/MicrositesPlugin.scala
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,7 @@ object MicrositesPlugin extends AutoPlugin {
micrositeGitterChannel := true,
micrositeGitterChannelUrl := s"${micrositeGithubOwner.value}/${micrositeGithubRepo.value}",
micrositeFooterText := Some(layouts.Layout.footer.toString),
micrositeEditButtonText := 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
20 changes: 19 additions & 1 deletion src/main/scala/microsites/layouts/DocsLayout.scala
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,8 @@ class DocsLayout(config: MicrositeSettings) extends Layout(config) {
),
div(id := "content", data("github-owner") := config.gitSettings.githubOwner, data("github-repo") := config.gitSettings.githubRepo,
div(cls := "content-wrapper",
section("{{ content }}")
section("{{ content }}"),
editButton
)
)
)
Expand Down Expand Up @@ -155,4 +156,21 @@ class DocsLayout(config: MicrositeSettings) extends Layout(config) {
(if (config.micrositeKazariSettings.micrositeKazariEnabled)
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(
div(
cls := "edit-button",
a(
href := config.gitSiteUrl,
href := "/edit/master/modules/docs/src/main/tut/{{ page.path }}",
cls := "btn-sm btn-info",
text
)
)
)
case None => Nil
}
}
2 changes: 1 addition & 1 deletion src/main/scala/microsites/microsites.scala
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ case class MicrositeVisualSettings(
favicons: Seq[MicrositeFavicon],
shareOnSocial: Boolean)

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

case class MicrositeSettings(
identity: MicrositeIdentitySettings,
Expand Down
6 changes: 5 additions & 1 deletion src/test/scala/microsites/util/Arbitraries.scala
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,7 @@ trait Arbitraries {
micrositeKazariDependencies dependenciesListArbitrary.arbitrary
micrositeKazariResolvers Arbitrary.arbitrary[Seq[String]]
micrositeFooterText Arbitrary.arbitrary[Option[String]]
micrositeEditButtonText Arbitrary.arbitrary[Option[String]]
} yield
MicrositeSettings(
MicrositeIdentitySettings(
Expand All @@ -165,7 +166,10 @@ trait Arbitraries {
palette,
favicon,
shareOnSocial),
MicrositeTemplateTexts(micrositeFooterText),
MicrositeTemplateTexts(
micrositeFooterText,
micrositeEditButtonText
),
micrositeConfigYaml,
MicrositeFileLocations(
micrositeImgDirectory,
Expand Down

0 comments on commit d55dddc

Please sign in to comment.