Taylor Venable avatar Taylor Venable committed 829b4dc

Make output directory customizable

Comments (0)

Files changed (2)

     db_user => undef,
     db_pass => undef,
     document => {
-        output_fmt => 'html'
+        output_fmt => 'html',
+        html => {
+            output_dir => './doc'
+        }
     }
 };
 
     my ($config) = @_;
 
     my $help = 0;
-    my $result = GetOptions('db-name=s' => \($$config{db_name}),
-                            'db-host=s' => \($$config{db_host}),
-                            'db-port=i' => \($$config{db_port}),
-                            'help'      => \$help);
+    my $result = GetOptions('db-name=s'         => \($$config{db_name}),
+                            'db-host=s'         => \($$config{db_host}),
+                            'db-port=i'         => \($$config{db_port}),
+                            'html-output-dir=s' => \($config->{document}->{html}->{output_dir}),
+                            'help'              => \$help);
 
     help() if $help;
 }
     my ($dbh) = @_;
     my $tables = [];
 
-    my $sth = $dbh->prepare('show tables');
+    my $sth = $dbh->prepare('show tables', { RaiseError => 1});
     $sth->execute;
     while (my $row = $sth->fetchrow_arrayref) {
         push $tables, $$row[0];
     my $table_links = [];
     my $table_data  = [];
 
-    if ($config->{document}->{output_fmt} eq 'html') {
-        $html = HTML::Tiny->new();
-        $config->{document}->{html} = $html;
-    }
-
     my $doc = App::SqlChamp::Data::Doc::new();
 
     $doc->{tables} = show_tables($dbh);
 
     given ($config->{document}->{output_fmt}) {
         when ('html') {
-            App::SqlChamp::Output::HTML::render_doc($doc);
+            App::SqlChamp::Output::HTML::render_doc($config, $doc);
         }
         when ('dokuwiki') {
-            App::SqlChamp::Output::HTML::render_doc($doc);
+            App::SqlChamp::Output::HTML::render_doc($config, $doc);
         }
     }
 

lib/App/SqlChamp/Output/HTML.pm

 }
 
 sub render_doc($) {
-    my ($doc) = @_;
+    my ($config, $doc) = @_;
 
     my $html = HTML::Tiny->new();
+    my $output_dir = $config->{document}->{html}->{output_dir};
 
-    open my $handle, '>', 'doc/_index.html';
+    open my $handle, '>', "$output_dir/_index.html";
     print $handle render_page("Table Documentation", [
         $html->ul([
             map {
 
         next if (scalar @{$body} == 0);
 
-        open my $handle, '>', "doc/$letter.html";
+        open my $handle, '>', "$output_dir/$letter.html";
         print $handle render_page("Table Documentation: $letter", $body);
         close $handle;
     }
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.