#!/usr/bin/perl -w # # appleScriptDoc: Convert pasted class descriptions to HTML. # # 2008-11-11: Written by Steven J. DeRose, sderose@acm.org. # # To do: use strict; use Getopt::Long; my $version = "2008-11-11"; my $e = ""; # error-message prefix my $quiet = 0; my $verbose = 0; ################################################################################ Getopt::Long::Configure ("ignore_case"); my $result = GetOptions( "h|help" => sub { showUsage(); exit; }, "q!" => \$quiet, "v+" => \$verbose, "version" => sub { showLicense(); exit; } ); ($result) || die "Bad options.\n"; ############################################################################### # Set implied options, validate option values... my ($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) = localtime; $mon++; if ($mon < 10) { $mon = "0$mon"; } my $date = ($year + 1900) . "-$mon-$mday" . "T$hour:$min:$sec"; my $lsquo = "Ô"; my $rsquo = "Õ"; my $ldquo = "Ò"; my $rdquo = "Ó"; my $blanks = 1; # Are we in a block of blank lines? my $buf = ""; # Accumulate links to classes printHeader(); my $lnum = 0; while (my $l = <>) { $lnum++; if (1) { if ($l eq "\n") { $blanks++; next; } if ($blanks > 0) { print "\n\n\n"; print "\n"; print "
\n"; # print "
\n";
		$blanks = 0;
    }
	}
	
	# contains/contained by headers
	if ($l =~ m/^contain/) {
		$l =~ s!^contains ([\w ]+)!contains $1!g;
		my $orig;
		do {
		 	$orig = $l;
			$l =~ s!^(contains .*, )([\w ]+)!$1$2!g;
		} while ($orig ne $l);
		$l =~ s!^contains!

Contains:!; $l =~ s!^contained by (.*, )([\w ]+)!contained by $1$2!g; $l =~ s!^contained by!

Contained by:!; $l =~ s!^(

!; } # element/property headers $l =~ s!^elements!\n

Elements

!; $l =~ s!^properties!\n

Properties

!; # property spec lines $l =~ s!^([\w ]+)\s?(\(.*?\))\s*:\s(.*)$!

$1 $2 $3!; # class name header line $l =~ s!\[inh. (\w+) > (\w+)![inh. $1 > $2!; $l =~ s!\[inh. (\w+)![inh. $1!; $l =~ s!([\[;] ?)see also ([\w ]+)!$1see also $2!; # expect en-space 0x2002 before the "n" $l =~ s!^(.*?)(\sn,?\s)!

$1

\n$1$2!; $l =~ s!^(.*?)(\sn,.*? : )!

$1

\n$1$2!; $l =~ s!\] : (.*$)!] : $1!; # curly quotes $l =~ s!$ldquo!!g; $l =~ s!$rdquo!!g; $l =~ s!$lsquo!\‘!g; $l =~ s!$rsquo!\’!g; if ($l =~ m/

.*$!!; $name =~ s!

\n

Class list (move into table at top):

\n"; print "\n\n
$buf
\n\n"; print "\n\n"; ($quiet) || warn "Done, $lnum lines processed.\n"; ############################################################################### sub printHeader { print qq{ Object Summary for AppleScript™

Object Summary for AppleScript™

This outline should help you quickly find how to get at most of the properties available, for use with AppleScript.

Extracted from the dictionary as visible in Apple's Script Editor™. Conversion done $date, by 'appleScriptDoc' version of $version, by Steven J. DeRose..

Container Outline

application
    windows.

Inheritance Outline

   

Class list

application
window
}; print "\n\n"; } ############################################################################### sub showUsage { warn " Usage: appleScriptDoc [options] file Converts doc from an AppleScript appilcation dictionary, to HTML. 1: Go into the Apple Script Editor, and do Open Dictionary for the application you're interested in. 2: Go through each package, and click on each class (marked by 'C' on a square blue background). 2a: For each class, select the entire (bottom) documentation pane, and copy it into an editor document somewhere. Put several blank lines between successive pasted blocks. 3: Save the editor file you made. 4: Run this script, piping in that file, and save as HTML. 5: Edit the HTML: 5a: move the 'class list' from the bottom to the top. 5b: Set the title and the h1 to say what application the doc is for. 5c: Set up container and inheritance outlines if desired. 6: Check, fix, and tell me about any problems (there shouldn't be many). 7: Post on the Web so nobody else has to repeat your work for that app. Options: -q Suppress most messages. -v Add more messages, and check integrity frequently. -version Show version/license info and exit (sjd $version). Known Bugs/Limitations (please report any other bugs to sderose\@acm.org): 'contained by' lines are not fully tagged yet. some stray ':'. Related commands: "; } sub showLicense { print " This work by Steven J. DeRose is licensed under a Creative Commons Attribution-Share Alike 3.0 Unported License. For further information on this license, see http://creativecommons.org/licenses/by-sa/3.0/. The author's present email is sderose at acm.org. This software was last updated on $version. For the most recent version, see http://www.derose.net/steve/utilities/. "; }