Skip to content

Commit

Permalink
Builder annotation also including unwanted items, so DIY
Browse files Browse the repository at this point in the history
  • Loading branch information
ultraq committed Jan 27, 2025
1 parent 06132c6 commit 5376c63
Showing 1 changed file with 32 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,6 @@ import org.thymeleaf.processor.IProcessor
import org.thymeleaf.standard.processor.StandardXmlNsTagProcessor
import org.thymeleaf.templatemode.TemplateMode

import groovy.transform.builder.Builder
import groovy.transform.builder.SimpleStrategy

/**
* A dialect for Thymeleaf that lets you build layouts and reusable templates in
* order to improve code reuse.
Expand All @@ -51,32 +48,27 @@ import groovy.transform.builder.SimpleStrategy
*
* @author Emanuel Rabina
*/
@Builder(
builderStrategy = SimpleStrategy,
includes = ['sortingStrategy', 'autoHeadMerging', 'experimentalTitleTokens'],
prefix = 'with'
)
class LayoutDialect extends AbstractProcessorDialect {

static final String DIALECT_NAME = 'Layout'
static final String DIALECT_PREFIX = 'layout'
static final int DIALECT_PRECEDENCE = 10

SortingStrategy sortingStrategy = new AppendingStrategy()
private SortingStrategy sortingStrategy = new AppendingStrategy()

/**
* Experimental option, set to {@code false} to skip the automatic merging
* of an HTML {@code <head>} section.
*/
boolean autoHeadMerging = true
private boolean autoHeadMerging = true

/**
* Experimental option, set to {@code true} to use standard Thymeleaf
* expression syntax for title patterns and to have access to the title parts
* in templates as the variables {@code layoutDialectContentTitle} and
* {@code layoutDialectLayoutTitle}.
*/
boolean experimentalTitleTokens = false
private boolean experimentalTitleTokens = false

/**
* Constructor, configure the layout dialect.
Expand Down Expand Up @@ -125,4 +117,33 @@ class LayoutDialect extends AbstractProcessorDialect {
new CollectFragmentProcessor(TemplateMode.XML, dialectPrefix)
]
}

/**
* Configure this instance of the layout dialect with the given {@code autoHeadMerging}
* value.
*/
LayoutDialect withAutoHeadMerging(boolean autoHeadMerging) {

this.autoHeadMerging = autoHeadMerging
return this
}

/**
* Configure this instance of the layout dialect with the given {@code experimentalTitleTokens}
* value.
*/
LayoutDialect withExperimentalTitleTokens(boolean experimentalTitleTokens) {

this.experimentalTitleTokens = experimentalTitleTokens
return this
}

/**
* Configure this instance of the layout dialect with the given {@code sortingStrategy}.
*/
LayoutDialect withSortingStrategy(SortingStrategy sortingStrategy) {

this.sortingStrategy = sortingStrategy
return this
}
}

0 comments on commit 5376c63

Please sign in to comment.