NAME

Template::LiquidX::Tidy - Indentation for Liquid template documents

SYNOPSIS

use Template::LiquidX::Tidy;
use Template::Liquid;
use Template::LiquidX::Tag::...; # any additional tag modules you need

my $parsed      = Template::Liquid->parse($template_string);
my $tidy_string = $parsed->{document}->tidy(\%options);

DESCRIPTION

The LiquidX::Tidy module enhances a parsed Template::Liquid::Document with a method to indent the document source code according to some options.

You can also use the command line client liquid_tidy to indent your template source codes.

METHODS

Template::Liquid::Document::tidy(%options)

This method is to be called on a Template::Liquid::Document, i.e. some node in the document created by Template::Liquid->parse.

It returns a string of the formatted and indented document node.

Th following options are possible:

html => boolean

Indent HTML code. Defaults to on.

indent => number

The number of spaces for each indentation level. Default 4.

force_nl => boolean

Whether to forcibly add line breaks into tags listed as force_nl_tags.

Default no for the module, yes for the command line client.

short_if => number

The length of a text inbetween {% if %} that should be exempt from force_nl

force_nl_tags => 'for endfor ...'

A space separated list of tags where force_nl will add line breaks.

Default tags: for endfor comment endcomment if unless elsif else endif endunless case when endcase

Template::Liquid::Document::dump()

This method is to be called on a Template::Liquid::Document, i.e. some node in the document created by Template::Liquid->parse.

It returns a copy of the source document.

Template::Liquid::Document::transform()

my ($transformed_document, $replacement_map) = $document->transform();
my $new_document = Template::LiquidX::Tidy::transform_back(
    $transformed_document, $replacement_map);

This method is to be called on a Template::Liquid::Document, i.e. some node in the document created by Template::Liquid->parse.

It returns a tuple with the source document where all Liquid tags have been replaced by HTML entities and blank <div> and <i> tags. This HTML document can the be further processed before using the transform_back method to put back the Liquid tags.

Template::LiquidX::Tidy::transform_back($transformed_document, $replacement_map)

This method returns a new template string undoing a transform operation.