forked from SPC/spc-site
Add ref resolution to basic page features
This commit is contained in:
parent
bf884732c1
commit
d3a6ab658a
@ -1,7 +1,7 @@
|
||||
---
|
||||
type: page
|
||||
title: Consulting
|
||||
transformation: snark.replaceLinks
|
||||
transformation: snark.basic
|
||||
language: en
|
||||
---
|
||||
|
||||
@ -21,7 +21,7 @@ Our research, which primarily includes open source projects, has already been ap
|
||||
<img src="images/pic03.jpg" alt="" />
|
||||
</span>
|
||||
<header class="major">
|
||||
<h3><a href="${homeRef}/consulting/research" class="link">Research</a></h3>
|
||||
<h3><a href="${resolvePageRef("consulting.research")}" class="link">Research</a></h3>
|
||||
<p>Analytics, prototyping and research for fundamental science and industry.</p>
|
||||
</header>
|
||||
</article>
|
||||
@ -30,7 +30,7 @@ Our research, which primarily includes open source projects, has already been ap
|
||||
<img src="images/pic04.jpg" alt="" />
|
||||
</span>
|
||||
<header class="major">
|
||||
<h3><a href="${homeRef}/consulting/expert" class="link">Expert activity</a></h3>
|
||||
<h3><a href="${resolvePageRef("consulting.expert")}" class="link">Expert activity</a></h3>
|
||||
<p>Analysis and improvement of existing scientific software and projects.</p>
|
||||
</header>
|
||||
</article>
|
||||
@ -39,7 +39,7 @@ Our research, which primarily includes open source projects, has already been ap
|
||||
<img src="images/pic05.jpg" alt="" />
|
||||
</span>
|
||||
<header class="major">
|
||||
<h3><a href="${homeRef}/consulting/architecture" class="link">Architecture</a></h3>
|
||||
<h3><a href="${resolvePageRef("consulting.architecture")}" class="link">Architecture</a></h3>
|
||||
<p>Design the architecture for scientific and technological applications.</p>
|
||||
</header>
|
||||
</article>
|
||||
@ -48,7 +48,7 @@ Our research, which primarily includes open source projects, has already been ap
|
||||
<img src="images/pic06.jpg" alt="" />
|
||||
</span>
|
||||
<header class="major">
|
||||
<h3><a href="${homeRef}/consulting/development" class="link">Development</a></h3>
|
||||
<h3><a href="${resolvePageRef("consulting.development")}" class="link">Development</a></h3>
|
||||
<p>The development and support of open-source and in-house solutions( libraries, frameworks and end-user application).</p>
|
||||
</header>
|
||||
</article>
|
||||
|
@ -126,7 +126,7 @@ class SnarkPlugin : AbstractPlugin() {
|
||||
"gif".asName() to SnarkParser(ImageIOReader, "gif"),
|
||||
)
|
||||
TextTransformation.TYPE -> mapOf(
|
||||
"replaceLinks".asName() to TextTransformation.replaceLinks
|
||||
"basic".asName() to BasicTextTransformation
|
||||
)
|
||||
else -> super.content(target)
|
||||
}
|
||||
|
@ -10,10 +10,26 @@ fun interface TextTransformation {
|
||||
companion object {
|
||||
const val TYPE = "snark.textTransformation"
|
||||
val TEXT_TRANSFORMATION_KEY = NameToken("transformation")
|
||||
}
|
||||
}
|
||||
|
||||
val replaceLinks: TextTransformation = object : TextTransformation {
|
||||
context(PageBuilder) override fun transform(text: String): String {
|
||||
return text.replace("\${homeRef}", homeRef)
|
||||
object BasicTextTransformation : TextTransformation {
|
||||
|
||||
private val regex = "\\\$\\{(\\w*)(?>\\(\"(.*)\"\\))?\\}".toRegex()
|
||||
|
||||
context(PageBuilder) override fun transform(text: String): String {
|
||||
return text.replace(regex) { match ->
|
||||
when (match.groups[1]!!.value) {
|
||||
"homeRef" -> homeRef
|
||||
"resolveRef" -> {
|
||||
val refString = match.groups[2]?.value ?: error("resolveRef requires a string (quoted) argument")
|
||||
resolveRef(refString)
|
||||
}
|
||||
"resolvePageRef" -> {
|
||||
val refString = match.groups[2]?.value ?: error("resolvePageRef requires a string (quoted) argument")
|
||||
resolvePageRef(refString)
|
||||
}
|
||||
else -> match.value
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user