Use code block switch extension from separate project

This should have been merged forwards following the changes in
70df55d413.

See gh-229
This commit is contained in:
Andy Wilkinson
2017-03-08 13:04:27 +00:00
parent 835c1a5546
commit cf77eabe04
7 changed files with 7 additions and 143 deletions

View File

@@ -1,7 +0,0 @@
repositories {
mavenCentral()
}
dependencies {
compile 'org.asciidoctor:asciidoctorj:1.5.2'
}

View File

@@ -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());
}
}

View File

@@ -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 = """<style>
$css
</style>
<script src=\"http://cdnjs.cloudflare.com/ajax/libs/zepto/1.1.6/zepto.min.js\"></script>
<script type="text/javascript">
$javascript
</script>
</head>
"""
return output.replace("</head>", replacement);
}
}

View File

@@ -1 +0,0 @@
org.springframework.restdocs.asciidoctor.CodeBlockSwitchExtension

View File

@@ -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;
}

View File

@@ -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 = $('<div class="switch"></div>');
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 = $('<div class="switch--item">' + blockName + '</div>');
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);

View File

@@ -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 'io.rest-assured:rest-assured'