Last active
September 27, 2017 10:22
-
-
Save pesterhazy/e59d8c5e863fc45d7317c6dc99c994e4 to your computer and use it in GitHub Desktop.
rplcr - Simple HTML templating
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
#!/usr/bin/env perl | |
# | |
# rplcr: Simple HTML templating using perl | |
# | |
# HTML templating in the spirit of "the simplest thing that could possibly work". | |
# | |
# Matches lines ending in | |
# | |
# <!-- $RPLCR$ some_perl_code_goes_here --> | |
# | |
# where some_perl_code_goes_here is arbitrary perl code that gets | |
# applied to the line. | |
# | |
# Example: | |
# | |
# <script src="js/lib.js"></script> <!-- $RPLCR$ s:(js/):$ENV{ASSET_PREFIX}.$1:e --> | |
# | |
# Used like this: | |
# | |
# ASSET_PREFIX=my-asset-id rplcr index.html | |
# | |
# Or if you want in-place editing: | |
# | |
# ASSET_PREFIX=my-asset-id perl -i rplcr index.html | |
while (<>) { | |
$line = $_; | |
if ($line =~ /^(.*)<!--\s+\$RPLCR\$\s+(.*?)-->\s*$/) { | |
$content = $1; | |
$code = $2; | |
$_ = $1; | |
eval($code); | |
print "$_\n"; | |
} | |
else { | |
print $line; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment