| 1 | package MsOffice::Word::Template::Engine::Mustache; | ||
| 2 | use 5.024; | ||
| 3 | use Moose; | ||
| 4 | use Template::Mustache; | ||
| 5 | |||
| 6 | extends 'MsOffice::Word::Template::Engine'; | ||
| 7 | |||
| 8 | |||
| 9 | use namespace::clean -except => 'meta'; | ||
| 10 | |||
| 11 | our $VERSION = '2.05'; | ||
| 12 | |||
| 13 | #====================================================================== | ||
| 14 | # ATTRIBUTES | ||
| 15 | #====================================================================== | ||
| 16 | |||
| 17 | has 'start_tag' => (is => 'ro', isa => 'Str', default => "{{"); | ||
| 18 | has 'end_tag' => (is => 'ro', isa => 'Str', default => "}}"); | ||
| 19 | |||
| 20 | #====================================================================== | ||
| 21 | # METHODS | ||
| 22 | #====================================================================== | ||
| 23 | |||
| 24 | sub compile_template { | ||
| 25 | my ($self, $template_text) = @_; | ||
| 26 | |||
| 27 | return Template::Mustache->new( | ||
| 28 | template => $template_text, | ||
| 29 | $self->{_constructor_args}->%*, | ||
| 30 | ); | ||
| 31 | } | ||
| 32 | |||
| 33 | |||
| 34 | sub process_part { | ||
| 35 | my ($self, $part_name, $package_part, $vars) = @_; | ||
| 36 | |||
| 37 | # currently a no-op; but here is a chance to do some processing with $part_name and $vars | ||
| 38 | |||
| 39 | return $self->process($part_name, $vars); | ||
| 40 | } | ||
| 41 | |||
| 42 | sub process { | ||
| 43 | my ($self, $template_name, $vars) = @_; | ||
| 44 | |||
| 45 | my $tmpl = $self->compiled_template->{$template_name} | ||
| 46 | or die "don't have a compiled template for '$template_name'"; | ||
| 47 | |||
| 48 | my $new_contents = $tmpl->render($vars); | ||
| 49 | |||
| 50 | return $new_contents; | ||
| 51 | } | ||
| 52 | |||
| 53 | |||
| 54 | 1; | ||
| 55 | |||
| 56 | __END__ |