[TxMt] bundle command
Benoit Gagnon
b.gagnon at gmail.com
Sat Feb 25 15:15:34 UTC 2006
On Feb 25, 2006, at 3:14 AM, Oliver Taylor wrote:
> I'm working on a bundle command (see below) that converts a plain-
> text document (screenplay) to a PHP file for conversion to PDF via
> FPDF (http://www.fpdf.org). Everything is working just fine except
> for two things I just can't figure out--for the record, this code
> was given to me by Allen for an HTML conversion and I've repurposed
> it for this.
>
> The first problem I'm having is with the very last line of code.
> The idea is to get safari to open the generated document in Safari
> and process it as a web-page. Because $DST seems to output the file-
> path I can't just have it open "http://localhost/example.php",
> which is what I want. How do I do that? Is it in the manual, 'cause
> I missed that part.
You don't need to use a webserver to run PHP. It comes with a
standalone command line app, rightfully called "php". It will take
stdin, output to stdout, and do all these things you cannot do in a
web server / client browser scenario.
ben
>
> The second question is regarding the 19th line of code:
>
> $this->Cell(5.5,.18," XXXX ",0,0,'L',0);
>
> I want to know if there is a way to define the "XXXX" bit in the
> document itself with something like:
>
> $header = example
>
> How would that be done?
>
> Thanks in advance, you guys are really helping make this bundle
> kick butt.
>
> -------------------------------
> # first figure out a name for the result
> NAME="${TM_FILENAME:-untitled}"
> BASENAME="${NAME%.*}"
> DST="/Library/WebServer/Documents/$BASENAME"
>
> # everything we output within { … } is written to the PHP file via
> redirection (see line with the })
> {
> # first output PHP header
> cat <<HEAD
> <?php
> require("fpdf/fpdf.php");
>
> class PDF extends FPDF
> {
> //Page header
> function Header()
> {
> //Move to the right
> \$this->Cell(5.5,.18," XXXX ",0,0,'L',0);
> //Title
> \$this->Cell(.5,.18,\$this->PageNo(),0,2,'R',0);
> \$this->ln(.32);
> }
> }
>
> \$pdf=new PDF("P","in","Letter");
> \$pdf->SetMargins(1.5,.5,1);
> \$pdf->AddPage();
> \$pdf->SetFont("Courier","",12);
>
> HEAD
>
> # then PHP body (converted from document)
> perl -pe '
> s/"/\\"/g; #escape quotes
> s/\/\/(.*)\/\/|^\/\/(.*)//g; # strip out non-printing comments
> s/^(\t{4})([^\t].*)$/\$pdf->Cell(2);\$pdf->MultiCell(0,.18,"$2",
> 0,L,0);/g; #characters
> s/^(\t{3})([^\t].*)$/\$pdf->Cell(1.5);\$pdf->MultiCell
> (1.5,.18,"$2",0,L,0);/g; #parenthetical
> s/^(\t{2})([^\t].*)$/\$pdf->Cell(1);\$pdf->MultiCell(3.5,.18,"$2",
> 0,L,0);\$pdf->ln();/g; #dialogue
> s/(\t{10})([^\t].*:)/\$pdf->Cell(4);\$pdf->MultiCell(2,.18,"$2");\
> $pdf->ln();/g; #right-transitions
> s/^\w+.{2,20}:\s*$/\$pdf->MultiCell(0,.18,"$&",0,L,0);\$pdf->ln();/
> g; #left-transitions
> s/^(\w|\.|\[|\-).*$/\$pdf->MultiCell(0,.18,"$&",0,L,0);\$pdf->ln
> ();/g; #paragraph
> '
>
> # and finally PHP footer
> cat <<'TAIL'
>
> $pdf->Output();
> ?>
>
> TAIL
> } >"$DST.php"
>
> # open the generated PHP file in Safari
> open -a Safari "$DST.php"
> ______________________________________________________________________
> For new threads USE THIS: textmate at lists.macromates.com
> (threading gets destroyed and the universe will collapse if you don't)
> http://lists.macromates.com/mailman/listinfo/textmate
More information about the textmate
mailing list