Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bug/custom tag parameters as string #46

Merged
merged 2 commits into from
Feb 6, 2017

Conversation

bkiers
Copy link
Owner

@bkiers bkiers commented Feb 6, 2017

Fix for custom tag parameters being previously separated by commas. Now all (optional) parameters are 1 string (as per the Liquid specs).

Below an example of how it must be used:

public class Test {

    public static void main(String[] args) {

        String source = "{% highlight shell linenos %}\n" +
                "cd /opt/dev/myproject\n" +
                "mvn clean install\n" +
                "{% endhighlight %}";

        String rendered = Template
                .parse(source)
                .with(new Highlight())
                .render();

        System.out.println(rendered);
    }
}

class Highlight extends Tag {

    public Highlight() {
        super("highlight");
    }

    @Override
    public Object render(TemplateContext context, LNode... nodes) {

        // parameters will be null when no parameters are present
        Object parameters = nodes[0].render(context);

        // The inner contents of the tag will always be in nodes[1]
        String sourceCode = super.asString(nodes[1].render(context));

        System.out.printf("parameters=`%s`\nsourceCode=`%s`\n", parameters, sourceCode);

        return "TODO";
    }
}

Running the code above will print:

parameters=`shell linenos`
sourceCode=`
cd /opt/dev/myproject
mvn clean install
`
TODO

Also see: #42

@bkiers bkiers merged commit 2bdd94a into develop Feb 6, 2017
@bkiers bkiers deleted the bug/custom-tag-parameters-as-string branch February 6, 2017 19:54
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

1 participant