#!/usr/bin/perl #------------------------------------------------------------------- # flatHelp.pl is Copyright 2006 Colin Kuskie #------------------------------------------------------------------- # This software is distributed under the same terms as WebGUI via # the GPL. The HTML generated by flatHelp is under the same license # and legal terms as WebGUI. #------------------------------------------------------------------- # ckuskie@sterling.net #------------------------------------------------------------------- #------------------------------------------------------------------- # WebGUI is Copyright 2001-2006 Plain Black Corporation. #------------------------------------------------------------------- # Please read the legal notices (docs/legal.txt) and the license # (docs/license.txt) that came with WebGUI before using it. #------------------------------------------------------------------- # http://www.plainblack.com info@plainblack.com #------------------------------------------------------------------- our ($webguiRoot); our $VERSION = '0.4'; BEGIN { $webguiRoot = "../"; unshift (@INC, $webguiRoot."/lib"); } $| = 1; use strict; use Getopt::Long; use Tie::IxHash; use WebGUI; use WebGUI::International; use WebGUI::Macro; use WebGUI::Macro::International; use WebGUI::Utility; use WebGUI::Session; use WebGUI::Asset::Template; use WebGUI::Operation::Help; use Data::Dumper; my ($configFile, $language, $help); GetOptions( 'configFile=s'=>\$configFile, 'language=s'=>\$language, 'help'=>\$help, ); $language = $language || "English"; if ($help || $configFile eq ""){ print < [--language=] --configFile WebGUI config file. Options: --help Display this help message and exit. STOP exit; } warn "Starting..."; my $session = WebGUI::Session->open($webguiRoot, $configFile); die "Unable to get session" unless ref $session eq "WebGUI::Session"; $session->user({userId => 3}); my $i18n = WebGUI::International->new($session, '', $language); warn "OK\n"; my $help_article = <

:

EOT #------------------------------------------------------------------- sub _link { my ($hid, $namespace, $text) = @_; $hid =~ tr{ /}{--}; return sprintf qq!%s!, $namespace, $hid, $text; } #------------------------------------------------------------------- sub www_generateHelp { my @aux_links = @_; my @helpIndex; my $dir = join '/', $webguiRoot,"lib","WebGUI","Help"; opendir (DIR,$dir) or die ("Can't open Help directory at $dir!: $!\n"); my @files = grep { /\.pm$/} readdir(DIR); closedir(DIR); my $i = 0; foreach my $file (sort @files) { if ($file =~ /(.*?)\.pm$/) { my $namespace = $1; my $help = WebGUI::Operation::Help::_load($session, $namespace); foreach my $key (keys %{$help}) { push @helpIndex, [$namespace, $key, $i18n->get($help->{$key}{title},$namespace)]; $i++; } } } my $index = qq!

Help Index for WebGUI $WebGUI::VERSION

\n!; my $output = ''; $i -= scalar @aux_links; my $halfway = round($i/2); $i = 0; $index .= join '', @aux_links; @helpIndex = sort { $a->[2] cmp $b->[2] } @helpIndex; foreach my $helpEntry (@helpIndex) { my ($namespace, $id, $title) = @{ $helpEntry }; $index .= _link($id,$namespace,$title); $index .= "
\n"; $i++; if ($i == $halfway) { $index .= '
'; } $output .= www_viewHelp($id,$namespace); } $index .= "
\n"; return ($index,$output); } #------------------------------------------------------------------- sub www_viewHelp { my ($hid,$namespace) = @_; my $help = WebGUI::Operation::Help::_get($session,$hid,$namespace); my %vars; ##Namespace specific object, used in getting template variables; my $i18m = WebGUI::International->new($session, $namespace, $language); $hid =~ tr{ /}{--}; $vars{"help.link"} = join "_", $namespace, $hid; $vars{"help.title"} = $i18n->get($help->{title}, $namespace); $vars{body} = $i18n->get($help->{body}, $namespace); $vars{uiLevelLabel} = $i18n->get('739', 'WebGUI'); warn sprintf "Undefined help: %s->%s\n", $namespace, $hid unless defined($vars{body}) and defined($vars{'help.title'}); foreach my $row (@{ $help->{fields} }) { push @{ $vars{fields} }, { 'title' => $i18n->get($row->{title},$row->{namespace}), 'description' => $i18n->get($row->{description},$row->{namespace}), 'uiLevel' => $row->{uiLevel}, }; } my @related = @{ $help->{related} }; foreach my $row ( @related ) { my $relatedHelp = WebGUI::Operation::Help::_get($session, $row->{tag}, $row->{namespace}); my $relatedTitle = $i18n->get($relatedHelp->{title},$row->{namespace}); warn sprintf "Undefined related link called by: %s->%s\n namespace: %s, hid: %s, title: %s\n", $namespace, $hid, $row->{tag}, $row->{namespace}, $relatedTitle unless $relatedTitle; push @{ $vars{related} }, { 'relatedLink' => _link($row->{tag}, $row->{namespace}, $relatedTitle) }; } $vars{variable_loop1} = WebGUI::Operation::Help::_getTemplateVars($session, 1, $help->{variables}, $i18m); my $output = WebGUI::Asset::Template->processRaw($session, $help_article, \%vars); WebGUI::Macro::process($session, \$output); return $output; } my $major; ($major = $WebGUI::VERSION) =~ s/^(\d+).+$/$1.x.x/; $major .= '.txt'; my @aux_docs = ( { filename => 'legal.txt', linktext => 'Plain Black License', name => 'legal', }, { filename => 'license.txt', linktext => 'GNU Public License', name => 'license', }, { filename => 'gotcha.txt', linktext => 'Upgrade gotchas', name => 'gotcha', }, { filename => join('/', 'changelog', $major), linktext => 'Change log', name => 'changelog', }, ); undef $/; my $aux_content = ''; my @aux_links = (); foreach (@aux_docs) { my $file = join '/', $webguiRoot, 'docs', $_->{filename}; open FN, $file or die "Unable to open $file: $!\n"; my $contents = ; close FN; $contents =~ tr/ //d; $aux_content .= sprintf( qq!

%s

%s
!, $_->{name}, $_->{linktext}, $contents); push @aux_links, sprintf( qq!%s
\n!, $_->{name}, $_->{linktext}); } my ($index,$helpText) = www_generateHelp(@aux_links); my $body = join "\n", $index, $helpText; my $cssFile = join '/', $webguiRoot, 'www/extras/help.css'; open CSS, $cssFile or die "Unable to open $cssFile for edit: $!\n"; undef $/; my $css = ; close CSS; print < WebGUI Help for $WebGUI::VERSION $body $aux_content EOT warn "Cleaning up..."; $session->close(); warn "OK\n"