package view; # BUILD CONSTRAINT: all views must return $content, $extension. # additional return values (as seen below) are optional. However, # careful use of svn externals and dependency management in path.pm can # resolve most issues with this constraint. use strict; use warnings; use Dotiac::DTL qw/Template *TEMPLATE_DIRS/; use Dotiac::DTL::Addon::markup; use ASF::Util qw/read_text_file sort_tables/; push our @TEMPLATE_DIRS, "templates"; # This is most widely used view. It takes a # 'template' argument and a 'path' argument. # Assuming the path ends in foo.mdtext, any files # like foo.page/bar.mdtext will be parsed and # passed to the template in the "bar" (hash) # variable. sub single_narrative { my %args = @_; my %styleargs = @_; my $file = "content$args{path}"; my $template = $args{template}; $args{path} =~ s/\.mdtext$/\.html/; $args{breadcrumbs} = breadcrumbs($args{path}); read_text_file $file, \%args; my $page_path = $file; $page_path =~ s/\.[^.]+$/.page/; if (-d $page_path) { for my $f (grep -f, glob "$page_path/*.mdtext") { $f =~ m!/([^/]+)\.mdtext$! or die "Bad filename: $f\n"; $args{$1} = {}; read_text_file $f, $args{$1}; } } # default navbars and mdtext from templates folder. my $templates_folder = "templates"; if (-d $templates_folder) { for my $f (grep -f, glob "$templates_folder/*.mdtext") { $f =~ m!/([^/]+)\.mdtext$! or die "Bad filename: $f\n"; $args{$1} = {}; read_text_file $f, $args{$1}; } } # folder specific overrides $templates_folder = templatesfolder($args{path}); $args{templates_folder} = $templates_folder; if (-d $templates_folder) { for my $f (grep -f, glob "$templates_folder/*.mdtext") { $f =~ m!/([^/]+)\.mdtext$! or die "Bad filename: $f\n"; $args{$1} = {}; read_text_file $f, $args{$1}; } } $args{content} = sort_tables($args{content}); return Template($template)->render(\%args), html => \%args; } # This view is used to wrap html. It takes a # 'template' argument and a 'path' argument. # Assuming the path ends in foo.html, any files # like foo.page/bar.mdtext will be parsed and # passed to the template in the "bar" (hash) # variable. sub html_page { my %args = @_; my %styleargs = @_; my $file = "content$args{path}"; my $template = $args{template}; $args{breadcrumbs} = breadcrumbs($args{path}); read_text_file $file, \%args; my $page_path = $file; $page_path =~ s/\.[^.]+$/.page/; if (-d $page_path) { for my $f (grep -f, glob "$page_path/*.mdtext") { $f =~ m!/([^/]+)\.mdtext$! or die "Bad filename: $f\n"; $args{$1} = {}; read_text_file $f, $args{$1}; } } # default navbars and mdtext from templates folder. my $templates_folder = "templates"; if (-d $templates_folder) { for my $f (grep -f, glob "$templates_folder/*.mdtext") { $f =~ m!/([^/]+)\.mdtext$! or die "Bad filename: $f\n"; $args{$1} = {}; read_text_file $f, $args{$1}; } } # folder specific overrides $templates_folder = templatesfolder($args{path}); $args{templates_folder} = $templates_folder; if (-d $templates_folder) { for my $f (grep -f, glob "$templates_folder/*.mdtext") { $f =~ m!/([^/]+)\.mdtext$! or die "Bad filename: $f\n"; $args{$1} = {}; read_text_file $f, $args{$1}; } } if ($args{content} =~ m!