ssg/CHANGELOG.md
2023-02-14 16:10:23 +01:00

4.6 KiB

Changelog

All notable changes to SSG will be documented in this file.

The format is based on Keep a Changelog, and this project adheres to Semantic Versioning.

Next

Added

  • Templates, SpecialPages, and Parts all have access to path of type String representing the path of the 'source' file: either a text file or a special page. In Templates, the 'source' comes from the path of the Text being rendered; in SpecialPages, this comes from the path of the SpecialPage being rendered (i.e., itself); in Parts, this comes from either the Template or SpecialPage which called the Part.

    <%
        // in a template or part when rendering a text at 'home.md'
        assert path == 'home.md'
    
        // in a template or part when rendering a text at 'posts/helloWorld.md'
        assert path == 'posts/helloWorld.md'
    
        // in a special page or part when rendering a special page at 'foo/bar/specialPage.gsp'
        assert path == 'foo/bar/specialPage.gsp'
    %>
    

    0371d41, 9983685, 076bc9b.

  • Templates, SpecialPages, and Parts all have access to a urlBuilder of type PathBasedUrlBuilder (implementing UrlBuilder). Use it like so:

    <%
        // when path == 'nested/post.whatever'
        assert urlBuilder.relative('images/test.jpg') == '../images/test.jpg'
    
        // when path == 'simple.whatever'
        assert urlBuilder.relative('images/test.jpg') == 'images/test.jpg'
    %>
    

    Nota bene: likely will break on Windows since PathBasedUrlBuilder currently uses Java's Path api and paths would be thusly rendered using Windows-style backslashes. 0371d41.

  • Parts have access to all other parts now via parts, an object of type EmbeddablePartsMap. For example:

    <% 
        // myPart.gsp
        out << parts['otherPart.gsp'].render()
    %>
    

    0e49414.

  • A tagBuilder object of type DynamicTagBuilder (implementing TagBuilder) is available in Templates, SpecialPages, and Parts.

    <%
        def simpleTag = tagBuilder.test()
        assert simpleTag == '<test />'
    
        def tagWithBody = tagBuilder.title 'Hello, World!'
        assert tagWithBody == '<title>Hello, World!</title>'
    
        def tagWithAttributes = tagBuilder.meta name: 'og:title', content: 'Hello, World!'
        assert tagWithAttributes == '<meta name="og:title" content="Hello, World!" />'
    
        def tagWithAttributesAndBody = tagBuilder.p([id: 'my-paragraph'], 'Hello, World!')
        assert tagWithAttributesAndBody == '<p id="my-paragraph">Hello, World!</p>'
    %>
    

    This is likely most useful for building simple, one-line html/xml tags. 93687d.

  • Parts have a text object of type EmbeddableText. If one is rendering a Part called from anything other than a Template (which has an associated text), this will be null. 34d9cd5.

Breaking Changes

  • The path object of type String, where it did previously exist, was stripped of its extension when previously referring to Texts or SpecialPages; now, the extension is present. For example:
    <%
        // suppose we have a text called 'test.md' and we are in a template, special page, or part
        assert texts['test'] == null
        assert texts['test.md'] != null
    %>
    
    0371d41.
  • The text object in Templates is now an instance of EmbeddableText instead of String. Thus, one must use text.render() to obtain the rendered text. 34d9cd5.

Deprecated

  • The frontMatter object in Templates is now deprecated. Use text.frontMatter instead. eafc8cd.