Debian Codegraph @

mqtt-client-website/ext/scalate/Boot.scala

raw
1 /**
2 * Licensed to the Apache Software Foundation (ASF) under one or more
3 * contributor license agreements. See the NOTICE file distributed with
4 * this work for additional information regarding copyright ownership.
5 * The ASF licenses this file to You under the Apache License, Version 2.0
6 * (the "License"); you may not use this file except in compliance with
7 * the License. You may obtain a copy of the License at
8 *
9 * http://www.apache.org/licenses/LICENSE-2.0
10 *
11 * Unless required by applicable law or agreed to in writing, software
12 * distributed under the License is distributed on an "AS IS" BASIS,
13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 * See the License for the specific language governing permissions and
15 * limitations under the License.
16 */
17 package scalate
18
19 import org.fusesource.scalate.util.Logging
20 import java.util.concurrent.atomic.AtomicBoolean
21 import _root_.Website._
22 import org.fusesource.scalate.TemplateEngine
23 import org.fusesource.scalamd.{MacroDefinition, Markdown}
24 import java.util.regex.Matcher
25 import org.fusesource.scalate.wikitext.Pygmentize
26
27 class Boot(engine: TemplateEngine) extends Logging {
28
29 private var _initialised = new AtomicBoolean(false)
30
31 def run: Unit = {
32 if (_initialised.compareAndSet(false, true)) {
33
34 def pygmentize(m:Matcher):String = Pygmentize.pygmentize(m.group(2), m.group(1))
35
36 // add some macros to markdown.
37 Markdown.macros :::= List(
38 MacroDefinition("""\{pygmentize::(.*?)\}(.*?)\{pygmentize\}""", "s", pygmentize, true),
39 MacroDefinition("""\{pygmentize\_and\_compare::(.*?)\}(.*?)\{pygmentize\_and\_compare\}""", "s", pygmentize, true),
40 MacroDefinition("""\$\{website_base_url\}""", "", _ => website_base_url.toString, true)
41 )
42
43 for( ssp <- engine.filter("ssp"); md <- engine.filter("markdown") ) {
44 engine.pipelines += "ssp.md"-> List(ssp, md)
45 engine.pipelines += "ssp.markdown"-> List(ssp, md)
46 }
47 info("Bootstrapped website gen for: %s".format(project_name))
48 }
49 }
50 }