This episode is for subscribers only. Sign Up or Log in to watch it.

5. Introduction to Luminus, part 3

Published 24 May 16

In this closing episode of the Luminus introduction, you’ll learn how to extend the template language with custom filters, and how to generate HTML components in code using Hiccup.

Show notes

In part 1 we set up our database, and implemented the rendering of wiki pages. In the second part we saw how to add a form to edit the pages, and we ended by showing the custom markup for links within our wiki, that we’re planning to implement.

In this third and final part of the introduction to Luminus, we’ll implement a custom filter to render these links, and we’ll handle creating new pages, so that the wiki is fully functional.

This is the syntax we want to use for links. Right now that doesn’t work yet, because they’re not valid markdown. For them to work we’ll have to do some extra processing when rendering a page. The Selmer templating system lets you write your own filters, so we’ll make one called wiki-links to render our links.

<!-- wiki-page.html -->
{{body|wiki-links|markdown}}

This filter isn’t defined yet, let’s fix that. The layout namespace is where Luminus puts custom tags and filters. You can see the markdown filter that we used earlier, as well as the csrf-field tag we needed for the form.

Add a new filter called wiki-links. We’ll just pass through the content for now. Let’s test that, everything should still work as before.

(ns lambwiki.layout
  ,,,)
,,,

(defn wiki-links [content]
  content)

(filters/add-filter! :wiki-links wiki-links)

Code

To follow along with this episode, you can start with the code provided on Github. Check out the part-2 branch, and follow the instructions in the README to set up your database. After that you should be ready to start this episode.

Regular Expressions

Have a look at this Regexp fiddle to play around with the regexp we used to extract links, #"\[\[([^\]]+)\]\]".

Regular expressions in Clojure make use of Java’s regexp engine. For a comprehensive overview of its syntax and features, you’ll have to head to the javadoc for java.util.regex.Pattern.

Further Reading

For more info on wiki, CSRF, and a full list of all the versions used in this project, have a look at the show notes for part 2.