Skip to content

Commit

Permalink
replace generic flavour insertions with explicit ones
Browse files Browse the repository at this point in the history
  • Loading branch information
msangel committed Jun 11, 2023
1 parent e7e9609 commit 9fd5a5c
Show file tree
Hide file tree
Showing 6 changed files with 11 additions and 9 deletions.
8 changes: 5 additions & 3 deletions src/main/java/liqp/ParseSettings.java
Original file line number Diff line number Diff line change
Expand Up @@ -147,21 +147,23 @@ public ParseSettings build() {
liquidStyleInclude = fl.isLiquidStyleInclude();
}

Insertions allInsertions = fl.getInsertions().mergeWith(Insertions.of(this.insertions));

Filters finalFilters = fl.getFilters().mergeWith(filters);

return new ParseSettings(fl, this.stripSpacesAroundTags, this.stripSingleLine, this.mapper,
this.insertions, finalFilters, evaluateInOutputTag, errorMode, liquidStyleInclude);
allInsertions, finalFilters, evaluateInOutputTag, errorMode, liquidStyleInclude);
}

}

private ParseSettings(Flavor flavor, boolean stripSpacesAroundTags, boolean stripSingleLine,
ObjectMapper mapper, List<Insertion> insertions, Filters filters, boolean evaluateInOutputTag, TemplateParser.ErrorMode errorMode, boolean liquidStyleInclude) {
ObjectMapper mapper, Insertions insertions, Filters filters, boolean evaluateInOutputTag, TemplateParser.ErrorMode errorMode, boolean liquidStyleInclude) {
this.flavor = flavor;
this.stripSpacesAroundTags = stripSpacesAroundTags;
this.stripSingleLine = stripSingleLine;
this.mapper = mapper;
this.insertions = Insertions.of(insertions);
this.insertions = insertions;
this.filters = filters;
this.evaluateInOutputTag = evaluateInOutputTag;
this.errorMode = errorMode;
Expand Down
4 changes: 2 additions & 2 deletions src/main/java/liqp/Template.java
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ private Template(File file, Insertions insertions, Filters filters, ParseSetting

// TemplateParser constructor
Template(TemplateParser parser, CharStream input) {
this(input, parser.getParseSettings().flavor.getInsertions(), parser.getParseSettings().filters, parser.getParseSettings());
this(input, parser.getParseSettings().insertions, parser.getParseSettings().filters, parser.getParseSettings());
this.templateParser = parser;
}

Expand Down Expand Up @@ -159,7 +159,7 @@ public void syntaxError(Recognizer<?, ?> recognizer, Object offendingSymbol, int

CommonTokenStream tokens = new CommonTokenStream(lexer);
ParseSettings parseSettings = this.templateParser.getParseSettings();
LiquidParser parser = new LiquidParser(tokens, parseSettings.flavor.isLiquidStyleInclude(), parseSettings.evaluateInOutputTag, parseSettings.errorMode);
LiquidParser parser = new LiquidParser(tokens, parseSettings.liquidStyleInclude, parseSettings.evaluateInOutputTag, parseSettings.errorMode);

parser.removeErrorListeners();

Expand Down
2 changes: 1 addition & 1 deletion src/main/java/liqp/filters/Where.java
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ public Where(){
@Override
public Object apply(Object value, TemplateContext context, Object... params) {
WhereImpl delegate;
if (context.getParseSettings().flavor.isLiquidStyleWhere()) {
if (context.getParseSettings().liquidStyleInclude) {
checkParams(params, 1, 2);
delegate = new LiquidWhereImpl(context, PropertyResolverHelper.INSTANCE);
} else {
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/liqp/parser/v4/NodeVisitor.java
Original file line number Diff line number Diff line change
Expand Up @@ -409,7 +409,7 @@ public LNode visitJekyll_include_params(Jekyll_include_paramsContext ctx) {
// ;
@Override
public LNode visitJekyll_include_output(Jekyll_include_outputContext ctx) {
if (this.parseSettings.flavor != Flavor.JEKYLL)
if (this.parseSettings.liquidStyleInclude)
throw new LiquidException("`{% include ouput %}` can only be used for Flavor.JEKYLL", ctx);

return visitOutput(ctx.output());
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/liqp/tags/Include.java
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ public Object render(TemplateContext context, LNode... nodes) {
Map<String, Object> variables = new HashMap<String, Object>();

if (nodes.length > 1) {
if (context.getParseSettings().flavor != Flavor.JEKYLL) {
if (context.getParseSettings().liquidStyleInclude) {
// check if there's a optional "with expression"
Object value = nodes[1].render(context);
context.put(includeResource, value);
Expand Down
2 changes: 1 addition & 1 deletion src/test/java/liqp/TestUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ public static LNode getNode(String source, String rule, ParseSettings parseSetti
throws Exception {

LiquidLexer lexer = new LiquidLexer(CharStreams.fromString("{{ " + source + " }}"));
LiquidParser parser = new LiquidParser(new CommonTokenStream(lexer), parseSettings.flavor.isLiquidStyleInclude(), parseSettings.evaluateInOutputTag, parseSettings.flavor.getErrorMode());
LiquidParser parser = new LiquidParser(new CommonTokenStream(lexer), parseSettings.liquidStyleInclude, parseSettings.evaluateInOutputTag, parseSettings.errorMode);

LiquidParser.OutputContext root = parser.output();;
NodeVisitor visitor = new NodeVisitor(Insertions.STANDARD_INSERTIONS, parseSettings.filters, parseSettings);
Expand Down

0 comments on commit 9fd5a5c

Please sign in to comment.