Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- $ cat page.html
- <h1>A page</h1>
- <!-- insert menu -->
- <!-- menu ends -->
- $ cat menu.tmpl
- <ul id="#menu">…</ul>
- $ update-templates page.html && cat page.html
- <h1>A page</h1>
- <!-- insert menu -->
- <ul id="#menu">…</ul>
- <!-- menu ends -->
- $ echo "Moo" > menu.tmpl
- $ update-templates page.html && cat page.html
- <h1>A page</h1>
- <!-- insert menu -->
- Moo
- <!-- menu ends -->
- <!--#include file="menu.html" -->
- sub readfile($) {
- open(FILE, 'r', shift);
- my $buffer;
- read (FILE, $buffer, 2 ** 20); # one megabyte maximum.
- close(FILE);
- return $buffer;
- }
- sub writefile($$) {
- open(FILE, 'w', shift);
- print FILE shift;
- close(FILE);
- }
- for my $file(@ARGV) {
- my $content = readfile($file);
- $content =~ s/<!--s+includes+(S+)s+-->.*?<!--s+ends+1s+-->/"<!-- include $1 -->".readfile($1)."<!-- end $1 -->"/ge;
- writefile($file, $content);
- }
- <p id='moo'></p>
- <script type="text/javascript" src="moo.js"></script>
- $('moo').innerHTML="hello world"
- <html>
- <head> ... whatever ...</head>
- <body>
- <div id="menu">
- Item 1
- Item 2
- (this could even be generated automatically from the files)
- </div>
- <div id="content">
- <!-- CONTENT -->
- </div>
- </body>
- </html>
- <p>This is my page content.</p>
- $template = get_contents(page.tpl)
- for each of the .txt files in the src directory {
- $c = get_contents($file)
- write(string_replace("<!-- CONTENT -->", $c, $template)) into page1.html
- }
- $ php script.php
Add Comment
Please, Sign In to add comment