blob: 8801d8dba5e4e371c45982038ab8781c7679c97d [file] [log] [blame]
package generator
import groovy.text.markup.BaseTemplate
import groovy.text.markup.MarkupTemplateEngine
import groovy.text.markup.TemplateConfiguration
import groovy.transform.CompileStatic
@CompileStatic
abstract class PageTemplate extends BaseTemplate {
public static final String BASEDIR = "basePath"
private final Map model
PageTemplate(
final MarkupTemplateEngine templateEngine,
final Map model, final Map<String, String> modelTypes, final TemplateConfiguration configuration) {
super(templateEngine, model, modelTypes, configuration)
this.model = model
}
String relative(String path) {
String base = (String) model.get(BASEDIR)
if (base && !path.startsWith('http') && !path.startsWith(File.separator)) {
String up = "..${File.separator}"
"${up*(1+base.count(File.separator))}$path"
} else {
path
}
}
/**
* Converts and outputs asciidoctor markup into HTML
* @param body the asciidoctor markup
*/
void asciidoc(String body, Map options=[:]) {
yieldUnescaped asciidocText(body, options)
}
/**
* Converts and returns asciidoctor markup into HTML. This method
* does *not* automatically render the result so it is possible
* to post-process the generated HTML.
* @param body the asciidoctor markup
*/
String asciidocText(String body, Map options=[:]) {
def asciidoctor = AsciidoctorFactory.instance
def attributes = options.attributes
if (!attributes) {
attributes = [:]
options.put('attributes', attributes)
}
attributes['source-highlighter'] = 'prettify'
asciidoctor.convert(body,options)
}
String latestDocURL(String target) {
"${DocUtils.DOCS_BASEURL}/html/$target"
}
}