Created
November 11, 2014 10:45
-
-
Save tomill/339487f9c0859a8b135d to your computer and use it in GitHub Desktop.
tt-to-twig.pl
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
use strict; | |
use warnings; | |
local $| = 1; | |
while (my $line = <>) { | |
$line =~ s/\[% WRAPPER '(.+?)' %\]/{% extends "layout.html.twig" %}\n{% set pageid = '' %}\n\n{% block content %}/g; | |
$line =~ s/\[% END # WRAPPER %\]/{% endblock %}/g; | |
$line =~ s/\[% FOREACH (.+?) IN (.+?) %\]/{% for $1 in $2 %}/g; | |
$line =~ s/\[% END # FOREACH %\]/{% endfor %}/g; | |
$line =~ s/\[% IF (.+?) %\]/{% if $1 %}/g; | |
$line =~ s/\[% ELSE %\]/{% else %}/g; | |
$line =~ s/\[% END # IF %\]/{% endif %}/g; | |
$line =~ s/\[% END %\]/{% endfixme %}/g; | |
$line =~ s!\[% (.+?) %\]! | |
my $var = $1; | |
$var =~ s{\|\|}{?:}; | |
$var =~ s{//}{?:}; | |
$var =~ s{ _ }{ ~ }g; | |
sprintf '{{ %s }}', $var; | |
!ge; | |
print $line; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment