From 70df55d4130eeaab38854488d84bc518165787fa Mon Sep 17 00:00:00 2001 From: Andy Wilkinson Date: Wed, 8 Mar 2017 13:04:27 +0000 Subject: [PATCH 1/2] Use code block switch extension from separate project Closes gh-229 --- buildSrc/build.gradle | 7 --- .../CodeBlockSwitchExtension.groovy | 28 ------------ .../CodeBlockSwitchPostProcessor.groovy | 39 ---------------- ...sciidoctor.extension.spi.ExtensionRegistry | 1 - .../src/main/resources/codeBlockSwitch.css | 23 ---------- .../src/main/resources/codeBlockSwitch.js | 45 ------------------- docs/build.gradle | 7 +++ 7 files changed, 7 insertions(+), 143 deletions(-) delete mode 100644 buildSrc/build.gradle delete mode 100644 buildSrc/src/main/groovy/org/springframework/restdocs/asciidoctor/CodeBlockSwitchExtension.groovy delete mode 100644 buildSrc/src/main/groovy/org/springframework/restdocs/asciidoctor/CodeBlockSwitchPostProcessor.groovy delete mode 100644 buildSrc/src/main/resources/META-INF/services/org.asciidoctor.extension.spi.ExtensionRegistry delete mode 100644 buildSrc/src/main/resources/codeBlockSwitch.css delete mode 100644 buildSrc/src/main/resources/codeBlockSwitch.js diff --git a/buildSrc/build.gradle b/buildSrc/build.gradle deleted file mode 100644 index ec63ab98..00000000 --- a/buildSrc/build.gradle +++ /dev/null @@ -1,7 +0,0 @@ -repositories { - mavenCentral() -} - -dependencies { - compile 'org.asciidoctor:asciidoctorj:1.5.2' -} \ No newline at end of file diff --git a/buildSrc/src/main/groovy/org/springframework/restdocs/asciidoctor/CodeBlockSwitchExtension.groovy b/buildSrc/src/main/groovy/org/springframework/restdocs/asciidoctor/CodeBlockSwitchExtension.groovy deleted file mode 100644 index 2dbd0364..00000000 --- a/buildSrc/src/main/groovy/org/springframework/restdocs/asciidoctor/CodeBlockSwitchExtension.groovy +++ /dev/null @@ -1,28 +0,0 @@ -/* - * Copyright 2014-2016 the original author or authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.springframework.restdocs.asciidoctor - -import org.asciidoctor.Asciidoctor -import org.asciidoctor.extension.spi.ExtensionRegistry - -class CodeBlockSwitchExtension implements ExtensionRegistry { - - @Override - public void register(Asciidoctor asciidoctor) { - asciidoctor.javaExtensionRegistry().postprocessor(new CodeBlockSwitchPostProcessor()); - } -} \ No newline at end of file diff --git a/buildSrc/src/main/groovy/org/springframework/restdocs/asciidoctor/CodeBlockSwitchPostProcessor.groovy b/buildSrc/src/main/groovy/org/springframework/restdocs/asciidoctor/CodeBlockSwitchPostProcessor.groovy deleted file mode 100644 index e87edf96..00000000 --- a/buildSrc/src/main/groovy/org/springframework/restdocs/asciidoctor/CodeBlockSwitchPostProcessor.groovy +++ /dev/null @@ -1,39 +0,0 @@ -/* - * Copyright 2014-2015 the original author or authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.springframework.restdocs.asciidoctor - -import org.asciidoctor.ast.Document -import org.asciidoctor.extension.Postprocessor - -class CodeBlockSwitchPostProcessor extends Postprocessor { - - String process(Document document, String output) { - def css = getClass().getResource("/codeBlockSwitch.css").text - def javascript = getClass().getResource("/codeBlockSwitch.js").text - def replacement = """ - - - -""" - return output.replace("", replacement); - } - -} \ No newline at end of file diff --git a/buildSrc/src/main/resources/META-INF/services/org.asciidoctor.extension.spi.ExtensionRegistry b/buildSrc/src/main/resources/META-INF/services/org.asciidoctor.extension.spi.ExtensionRegistry deleted file mode 100644 index 2dcc8a1d..00000000 --- a/buildSrc/src/main/resources/META-INF/services/org.asciidoctor.extension.spi.ExtensionRegistry +++ /dev/null @@ -1 +0,0 @@ -org.springframework.restdocs.asciidoctor.CodeBlockSwitchExtension \ No newline at end of file diff --git a/buildSrc/src/main/resources/codeBlockSwitch.css b/buildSrc/src/main/resources/codeBlockSwitch.css deleted file mode 100644 index 6fb1947b..00000000 --- a/buildSrc/src/main/resources/codeBlockSwitch.css +++ /dev/null @@ -1,23 +0,0 @@ -.hidden { - display: none; -} - -.switch { - border-width: 1px 1px 0 1px; - border-style: solid; - border-color: #7a2518; - display: inline-block; -} - -.switch--item { - padding: 10px; - background-color: #ffffff; - color: #7a2518; - display: inline-block; - cursor: pointer; -} - -.switch--item.selected { - background-color: #7a2519; - color: #ffffff; -} \ No newline at end of file diff --git a/buildSrc/src/main/resources/codeBlockSwitch.js b/buildSrc/src/main/resources/codeBlockSwitch.js deleted file mode 100644 index 13ac0fc1..00000000 --- a/buildSrc/src/main/resources/codeBlockSwitch.js +++ /dev/null @@ -1,45 +0,0 @@ -function addBlockSwitches() { - $('.primary').each(function() { - primary = $(this); - createSwitchItem(primary, createBlockSwitch(primary)).item.addClass("selected"); - primary.children('.title').remove(); - }); - $('.secondary').each(function(idx, node) { - secondary = $(node); - primary = findPrimary(secondary); - switchItem = createSwitchItem(secondary, primary.children('.switch')); - switchItem.content.addClass('hidden'); - findPrimary(secondary).append(switchItem.content); - secondary.remove(); - }); -} - -function createBlockSwitch(primary) { - blockSwitch = $('
'); - primary.prepend(blockSwitch); - return blockSwitch; -} - -function findPrimary(secondary) { - candidate = secondary.prev(); - while (!candidate.is('.primary')) { - candidate = candidate.prev(); - } - return candidate; -} - -function createSwitchItem(block, blockSwitch) { - blockName = block.children('.title').text(); - content = block.children('.content').first().append(block.next('.colist')); - item = $('
' + blockName + '
'); - item.on('click', '', content, function(e) { - $(this).addClass('selected'); - $(this).siblings().removeClass('selected'); - e.data.siblings('.content').addClass('hidden'); - e.data.removeClass('hidden'); - }); - blockSwitch.append(item); - return {'item': item, 'content': content}; -} - -$(addBlockSwitches); \ No newline at end of file diff --git a/docs/build.gradle b/docs/build.gradle index a8c7706c..3c298984 100644 --- a/docs/build.gradle +++ b/docs/build.gradle @@ -2,7 +2,14 @@ plugins { id 'org.asciidoctor.convert' version '1.5.3' } +repositories { + maven { + url 'https://repo.spring.io/release' + } +} + dependencies { + asciidoctor 'io.spring.asciidoctor:spring-asciidoctor-extensions:0.1.0.RELEASE' testCompile project(':spring-restdocs-mockmvc') testCompile project(':spring-restdocs-restassured') testCompile 'javax.validation:validation-api' From 5a76decc118359f4004a5cc1aac5ef745b455c14 Mon Sep 17 00:00:00 2001 From: Andy Wilkinson Date: Wed, 8 Mar 2017 13:07:09 +0000 Subject: [PATCH 2/2] Link to correct branch on GitHub in snapshot documentation Closes gh-367 --- docs/build.gradle | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/build.gradle b/docs/build.gradle index 3c298984..beea19a0 100644 --- a/docs/build.gradle +++ b/docs/build.gradle @@ -24,6 +24,6 @@ asciidoctor { include 'index.adoc' } attributes 'revnumber': project.version, - 'branch-or-tag': project.version.endsWith('SNAPSHOT') ? 'master': "v${project.version}" + 'branch-or-tag': project.version.endsWith('SNAPSHOT') ? '1.1.x': "v${project.version}" inputs.files(sourceSets.test.java) } \ No newline at end of file