#!/usr/bin/env perl
use common::sense;
use Rhetoric 'With::MockRequest';
use Getopt::Long;
use Data::Dump 'pp';
Getopt::Long::Configure('no_ignore_case');
GetOptions(
  \%_,
  'config|c=s%',
  'help|h'
);

my $C = \%Rhetoric::CONFIG;
for (keys %{$_{config}}) {
  if (/\[/ || /\{/) {
    my $key = $_;
    eval '$C->'.$key.' = $_{config}'."{'$key'}";
  } else {
    $C->{$_} = $_{config}{$_}
  }
}
pp $C;

Rhetoric->init;

package Rhetoric::Controllers;
use IO::All;

# TODO - add archives when that controller is ready
# TODO - add categories when that controller is ready
my %replacement = (
  Home     => [ '/index.html', '/page/(\d+).html' ],
  Post     => [ '/(\d+)/(\d+)/([\w-]+).html' ],
  X        => [ '/(.*).html' ],
);

while (my ($controller, $urls) = each(%replacement)) {
  $Rhetoric::Controllers::C{$controller}->{urls} = $urls;
}

# TODO - export pages for Home controller
pp \%Rhetoric::Controllers::C;
my ($cc, $content) = Rhetoric->get('Home');
$content > io('index.html');

# TODO - export pages for Post controller

# TODO - export pages for X controller
# XXX  - How will I know what pages to export for X?

# TODO - export static files for current theme
