FunctionalPerl
view release on metacpan or search on metacpan
htmlgen/gen view on Meta::CPAN
use FP::Array ":all";
use File::Spec;
use FP::Array_sort;
use FP::Ops qw(string_cmp real_cmp the_method cut_method);
use FP::Equal qw(equal);
use FP::autobox;
use Chj::TEST ":all";
use FP::List qw(is_pair list);
use PXML::Util qw(pxml_map_elements_exhaustively);
use FP::Hash ":all";
use PXML::Tags qw(with_toc);
use FP::Predicates qw(complement);
use FP::Git::Repository;
use FunctionalPerl::Htmlgen::PathTranslate;
use FunctionalPerl::Htmlgen::PathUtil qw(path_add path_diff path0);
use FunctionalPerl::Htmlgen::Cost;
use FunctionalPerl::Htmlgen::default_config qw($default_config);
use FunctionalPerl::Htmlgen::FileUtil qw(existingpath_or create_parent_dirs);
use FunctionalPerl::Htmlgen::MarkdownPlus qw(markdownplus_parse);
use FP::Lazy;
use FunctionalPerl::Htmlgen::Mediawiki qw(mediawiki_prepare mediawiki_replace
mediawiki_rexpand);
use PXML::Preserialize qw(pxmlpre);
use FP::PureHash;
use FP::Equal qw(pointer_eq);
use FP::Carp;
our $css_path = "htmlgen.css";
sub usage {
print "$myname config inbase outbase
config is the path to a Perl file ending in a hash with config
values, see functional-perl/website/gen-config.pl for an example.
inbase needs to be a git working directory.
Assumes that there is a file '$css_path', which is included in the
<head/> and copied to outbase.
Options:
--repl open a repl instead of running the main action
--trap trap uncached exception in a repl (implied by --repl)
";
exit 1;
}
our $verbose = 0;
our ($opt_repl, $opt_trap);
GetOptions(
"verbose" => \$verbose,
"help" => sub {usage},
"repl" => \$opt_repl,
"trap" => \$opt_trap,
) or exit 1;
usage unless @ARGV == 3 or ($opt_repl and @ARGV >= 1);
our ($configpath, $inbase, $outbase) = @ARGV;
our $user_config = require $configpath;
require FP::Repl::Trap if $opt_trap;
our $config = hashset_union($user_config, $default_config);
lock_hash %$config;
our $pathtranslate = FunctionalPerl::Htmlgen::PathTranslate->new__(
subhash($config, "is_indexpath0", "downcaps"));
our $gitrepository = FP::Git::Repository->new_(chdir => $inbase);
sub path0_to_inpath($path0) {
"$inbase/" . $path0
}
sub path0_to_outpath($path0) {
#"$outbase/".$pathtranslate->xsuffix_md_to_html($path0,0)
# nope, also used for .pl file copying,
"$outbase/" . $pathtranslate->possibly_suffix_md_to_html($path0, 0)
}
use FunctionalPerl::Htmlgen::Toc;
use FunctionalPerl::Htmlgen::Linking;
use FunctionalPerl::Htmlgen::PerlTidy;
# XX make configurable
# (This is getting a bit too layered now. Still Ok?)
# normal simply gives a keyword arg based constructor that creates it
sub normal($classname) {
sub {
$classname->new_(@_)
}
}
# This one adds in the functional_perl_base_dir argument:
sub with_args ($classname, @args) {
sub {
$classname->new_(@_, @args)
}
}
our $pxml_mappers =
# These implement FunctionalPerl::Htmlgen::PXMLMapper; subarray
# for those that match on the same tagname, in order of preference
# (the chain exits once an element has been replaced).
[
normal("FunctionalPerl::Htmlgen::Linking::Anchors"),
normal("FunctionalPerl::Htmlgen::Toc"), # <with_toc>
[
normal("FunctionalPerl::Htmlgen::PerlTidy"),
with_args(
"FunctionalPerl::Htmlgen::Linking::code",
# For names that we never want to auto-link as modules to
# CPAN since they are something else ("CPAN-exceptions"):
( run in 3.360 seconds using v1.01-cache-2.11-cpan-39bf76dae61 )