| 1 | package Yukki::Web::View; | ||||||||||||||||||||||
| 2 | 15 | $Yukki::Web::View::VERSION = '0.991_002'; # TRIAL | |||||||||||||||||||||
| 3 | |||||||||||||||||||||||
| 4 | 15 | ▶ | $Yukki::Web::View::VERSION = '0.991002';use v5.24; | ||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||
| 5 | 15 | ▶ | use utf8; | ||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||
| 6 | 15 | ▶ | use Moo; | ||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||
| 7 | |||||||||||||||||||||||
| 8 | 15 | ▶ | use Type::Params qw( validate ); | ||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||
| 9 | 15 | ▶ | use Scalar::Util qw( blessed reftype ); | ||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||
| 10 | 15 | ▶ | use Spreadsheet::Engine; | ||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||
| 11 | 15 | ▶ | use Template::Pure; | ||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||
| 12 | 15 | ▶ | use Text::MultiMarkdown; | ||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||
| 13 | 15 | ▶ | use Try::Tiny; | ||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||
| 14 | 15 | ▶ | use Type::Utils; | ||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||
| 15 | 15 | ▶ | use Types::Standard qw( Dict Str ArrayRef HashRef slurpy ); | ||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||
| 16 | |||||||||||||||||||||||
| 17 | 15 | ▶ | use namespace::clean; | ||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||
| 18 | |||||||||||||||||||||||
| 19 | # ABSTRACT: base class for Yukki::Web views | ||||||||||||||||||||||
| 20 | |||||||||||||||||||||||
| 21 | |||||||||||||||||||||||
| 22 | 15 | has app => ( | |||||||||||||||||||||
| 23 | is => 'ro', | ||||||||||||||||||||||
| 24 | isa => class_type('Yukki::Web'), | ||||||||||||||||||||||
| 25 | required => 1, | ||||||||||||||||||||||
| 26 | weak_ref => 1, | ||||||||||||||||||||||
| 27 | handles => 'Yukki::Role::App', | ||||||||||||||||||||||
| 28 | ); | ||||||||||||||||||||||
| 29 | |||||||||||||||||||||||
| 30 | |||||||||||||||||||||||
| 31 | 15 | has markdown => ( | |||||||||||||||||||||
| 32 | is => 'ro', | ||||||||||||||||||||||
| 33 | isa => class_type('Text::MultiMarkdown'), | ||||||||||||||||||||||
| 34 | required => 1, | ||||||||||||||||||||||
| 35 | lazy => 1, | ||||||||||||||||||||||
| 36 | builder => '_build_markdown', | ||||||||||||||||||||||
| 37 | handles => { | ||||||||||||||||||||||
| 38 | 'format_markdown' => 'markdown', | ||||||||||||||||||||||
| 39 | }, | ||||||||||||||||||||||
| 40 | ); | ||||||||||||||||||||||
| 41 | |||||||||||||||||||||||
| 42 | sub _build_markdown { | ||||||||||||||||||||||
| 43 | 0 | ▶ | Text::MultiMarkdown->new( | ||||||||||||||||||||
|
Subroutine
_build_markdown: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||
| 44 | markdown_in_html_blocks => 1, | ||||||||||||||||||||||
| 45 | heading_ids => 0, | ||||||||||||||||||||||
| 46 | ); | ||||||||||||||||||||||
| 47 | } | ||||||||||||||||||||||
| 48 | |||||||||||||||||||||||
| 49 | |||||||||||||||||||||||
| 50 | 15 | has messages_template => ( | |||||||||||||||||||||
| 51 | is => 'ro', | ||||||||||||||||||||||
| 52 | isa => class_type('Template::Pure'), | ||||||||||||||||||||||
| 53 | lazy => 1, | ||||||||||||||||||||||
| 54 | builder => '_build_messages_template', | ||||||||||||||||||||||
| 55 | ); | ||||||||||||||||||||||
| 56 | |||||||||||||||||||||||
| 57 | sub _build_messages_template { | ||||||||||||||||||||||
| 58 | 0 | ▶ | my $self = shift; | ||||||||||||||||||||
|
Subroutine
_build_messages_template: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||
| 59 | 0 | return $self->prepare_template( | |||||||||||||||||||||
| 60 | template => 'messages.html', | ||||||||||||||||||||||
| 61 | directives => [ | ||||||||||||||||||||||
| 62 | '.error' => { | ||||||||||||||||||||||
| 63 | 'error<-errors' => [ | ||||||||||||||||||||||
| 64 | '.' => 'error', | ||||||||||||||||||||||
| 65 | ], | ||||||||||||||||||||||
| 66 | }, | ||||||||||||||||||||||
| 67 | '.warning' => { | ||||||||||||||||||||||
| 68 | 'warning<-warnings' => [ | ||||||||||||||||||||||
| 69 | '.' => 'warning', | ||||||||||||||||||||||
| 70 | ], | ||||||||||||||||||||||
| 71 | }, | ||||||||||||||||||||||
| 72 | '.info' => { | ||||||||||||||||||||||
| 73 | 'one_info<-info' => [ | ||||||||||||||||||||||
| 74 | '.' => 'one_info', | ||||||||||||||||||||||
| 75 | ], | ||||||||||||||||||||||
| 76 | }, | ||||||||||||||||||||||
| 77 | ], | ||||||||||||||||||||||
| 78 | ); | ||||||||||||||||||||||
| 79 | } | ||||||||||||||||||||||
| 80 | |||||||||||||||||||||||
| 81 | has _page_templates => ( | ||||||||||||||||||||||
| 82 | is => 'ro', | ||||||||||||||||||||||
| 83 | isa => HashRef, | ||||||||||||||||||||||
| 84 | required => 1, | ||||||||||||||||||||||
| 85 | 0 | ▶ | default => sub { +{} }, | ||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||
| 86 | 15 | ); | |||||||||||||||||||||
| 87 | |||||||||||||||||||||||
| 88 | |||||||||||||||||||||||
| 89 | 15 | has links_template => ( | |||||||||||||||||||||
| 90 | is => 'ro', | ||||||||||||||||||||||
| 91 | isa => class_type('Template::Pure'), | ||||||||||||||||||||||
| 92 | lazy => 1, | ||||||||||||||||||||||
| 93 | builder => '_build_links_template', | ||||||||||||||||||||||
| 94 | ); | ||||||||||||||||||||||
| 95 | |||||||||||||||||||||||
| 96 | sub _build_links_template { | ||||||||||||||||||||||
| 97 | 0 | ▶ | my $self = shift; | ||||||||||||||||||||
|
Subroutine
_build_links_template: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||
| 98 | 0 | $self->prepare_template( | |||||||||||||||||||||
| 99 | template => 'links.html', | ||||||||||||||||||||||
| 100 | directives => [ | ||||||||||||||||||||||
| 101 | '.links' => { | ||||||||||||||||||||||
| 102 | 'link<-links' => [ | ||||||||||||||||||||||
| 103 | 'a' => 'link.label', | ||||||||||||||||||||||
| 104 | 'a@href' => 'link.href', | ||||||||||||||||||||||
| 105 | ], | ||||||||||||||||||||||
| 106 | }, | ||||||||||||||||||||||
| 107 | ], | ||||||||||||||||||||||
| 108 | ); | ||||||||||||||||||||||
| 109 | } | ||||||||||||||||||||||
| 110 | |||||||||||||||||||||||
| 111 | |||||||||||||||||||||||
| 112 | sub page_template { | ||||||||||||||||||||||
| 113 | 0 | ▶ | my ($self, $which) = @_; | ||||||||||||||||||||
|
Subroutine
page_template: not called CC=5 SCAR=34.0
Pod
documented
| |||||||||||||||||||||||
| 114 | |||||||||||||||||||||||
| 115 | return $self->_page_templates->{ $which } | ||||||||||||||||||||||
| 116 | 0 | ▶ | if $self->_page_templates->{ $which }; | ||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||
| 117 | |||||||||||||||||||||||
| 118 | 0 | ▶ | my $view = $which // 'default'; | ||||||||||||||||||||
|
Condition0%0/2
$which // "default"
MC/DC0%0/1
$which // "default"
$which
Truth table0%0/2
A
A= $which
| |||||||||||||||||||||||
| 119 | 0 | ▶ | my $view_args = $self->app->settings->page_views->{ $view } | ||||||||||||||||||||
|
Condition0%0/2
$self->app->settings->page_views->{$view} // {"template", "shell.html"}
MC/DC0%0/1
$self->app->settings->page_views->{$view} // {"template", "shell.html"}
$self->app->settings->page_views->{$view}
Truth table0%0/2
A
A= $self->app->settings->page_views->{$view}
| |||||||||||||||||||||||
| 120 | // { template => 'shell.html' }; | ||||||||||||||||||||||
| 121 | 0 | ▶ | $view_args->{directives} //= []; | ||||||||||||||||||||
|
Condition0%0/2
$view_args->{"directives"} //= []
MC/DC0%0/1
$view_args->{"directives"} //= []
$view_args->{"directives"}
Truth table0%0/2
A
A= $view_args->{"directives"}
| |||||||||||||||||||||||
| 122 | |||||||||||||||||||||||
| 123 | my %menu_vars = map { | ||||||||||||||||||||||
| 124 | 0 | my $menu_name = $_; | |||||||||||||||||||||
| 125 | 0 | "#nav-$menu_name .navigation" => { | |||||||||||||||||||||
| 126 | "menu_item<-$menu_name" => [ | ||||||||||||||||||||||
| 127 | 'a' => 'menu_item.label', | ||||||||||||||||||||||
| 128 | 'a@href' => 'menu_item.href', | ||||||||||||||||||||||
| 129 | ], | ||||||||||||||||||||||
| 130 | }, | ||||||||||||||||||||||
| 131 | 0 | } @{ $self->app->settings->menu_names }; | |||||||||||||||||||||
| 132 | |||||||||||||||||||||||
| 133 | return $self->_page_templates->{ $which } = $self->prepare_template( | ||||||||||||||||||||||
| 134 | template => $view_args->{template}, | ||||||||||||||||||||||
| 135 | directives => [ | ||||||||||||||||||||||
| 136 | $view_args->{directives}->@*, | ||||||||||||||||||||||
| 137 | 0 | 'head script.local' => { | |||||||||||||||||||||
| 138 | 'script<-scripts' => [ | ||||||||||||||||||||||
| 139 | '@src' => 'script', | ||||||||||||||||||||||
| 140 | ], | ||||||||||||||||||||||
| 141 | }, | ||||||||||||||||||||||
| 142 | 'head link.local' => { | ||||||||||||||||||||||
| 143 | 'link<-links' => [ | ||||||||||||||||||||||
| 144 | '@href' => 'link', | ||||||||||||||||||||||
| 145 | ], | ||||||||||||||||||||||
| 146 | }, | ||||||||||||||||||||||
| 147 | '#messages' => 'messages | encoded_string', | ||||||||||||||||||||||
| 148 | 'title' => 'main_title', | ||||||||||||||||||||||
| 149 | '.masthead-title' => 'title', | ||||||||||||||||||||||
| 150 | %menu_vars, | ||||||||||||||||||||||
| 151 | '#breadcrumb li' => { | ||||||||||||||||||||||
| 152 | 'crumb<-breadcrumb' => [ | ||||||||||||||||||||||
| 153 | 'a' => 'crumb.label', | ||||||||||||||||||||||
| 154 | 'a@href' => 'crumb.href', | ||||||||||||||||||||||
| 155 | ], | ||||||||||||||||||||||
| 156 | }, | ||||||||||||||||||||||
| 157 | '#content' => 'content | encoded_string', | ||||||||||||||||||||||
| 158 | ], | ||||||||||||||||||||||
| 159 | ); | ||||||||||||||||||||||
| 160 | } | ||||||||||||||||||||||
| 161 | |||||||||||||||||||||||
| 162 | |||||||||||||||||||||||
| 163 | sub prepare_template { | ||||||||||||||||||||||
| 164 | 0 | ▶ | my ($self, $opt) | ||||||||||||||||||||
|
Subroutine
prepare_template: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||
| 165 | = validate(\@_, class_type(__PACKAGE__), | ||||||||||||||||||||||
| 166 | slurpy Dict[ | ||||||||||||||||||||||
| 167 | template => Str, | ||||||||||||||||||||||
| 168 | directives => ArrayRef, | ||||||||||||||||||||||
| 169 | ]); | ||||||||||||||||||||||
| 170 | 0 | my ($template, $directives) = @{$opt}{qw( template directives )}; | |||||||||||||||||||||
| 171 | |||||||||||||||||||||||
| 172 | 0 | my $template_content = | |||||||||||||||||||||
| 173 | $self->app->locate_dir('template_path', $template)->slurp; | ||||||||||||||||||||||
| 174 | |||||||||||||||||||||||
| 175 | 0 | return Template::Pure->new( | |||||||||||||||||||||
| 176 | template => $template_content, | ||||||||||||||||||||||
| 177 | directives => $directives, | ||||||||||||||||||||||
| 178 | ); | ||||||||||||||||||||||
| 179 | } | ||||||||||||||||||||||
| 180 | |||||||||||||||||||||||
| 181 | |||||||||||||||||||||||
| 182 | sub render_page { | ||||||||||||||||||||||
| 183 | 0 | ▶ | my ($self, $opt) | ||||||||||||||||||||
|
Subroutine
render_page: not called CC=10 SCAR=47.0
Pod
documented
| |||||||||||||||||||||||
| 184 | = validate(\@_, class_type(__PACKAGE__), | ||||||||||||||||||||||
| 185 | slurpy Dict[ | ||||||||||||||||||||||
| 186 | template => class_type('Template::Pure'), | ||||||||||||||||||||||
| 187 | context => class_type('Yukki::Web::Context'), | ||||||||||||||||||||||
| 188 | vars => HashRef, | ||||||||||||||||||||||
| 189 | ]); | ||||||||||||||||||||||
| 190 | 0 | my ($template, $ctx, $vars) = @{$opt}{qw( template context vars )}; | |||||||||||||||||||||
| 191 | 0 | ▶ | $vars //= {}; | ||||||||||||||||||||
|
Condition0%0/2
$vars //= {}
MC/DC0%0/1
$vars //= {}
$vars
Truth table0%0/2
A
A= $vars
| |||||||||||||||||||||||
| 192 | |||||||||||||||||||||||
| 193 | 0 | ▶ | my $messages = $self->render( | ||||||||||||||||||||
|
Branch: 3 branches
| |||||||||||||||||||||||
| 194 | template => $self->messages_template, | ||||||||||||||||||||||
| 195 | context => $ctx, | ||||||||||||||||||||||
| 196 | vars => { | ||||||||||||||||||||||
| 197 | errors => $ctx->has_errors ? [ $ctx->list_errors ] : undef, | ||||||||||||||||||||||
| 198 | warnings => $ctx->has_warnings ? [ $ctx->list_warnings ] : undef, | ||||||||||||||||||||||
| 199 | info => $ctx->has_info ? [ $ctx->list_info ] : undef, | ||||||||||||||||||||||
| 200 | }, | ||||||||||||||||||||||
| 201 | ); | ||||||||||||||||||||||
| 202 | |||||||||||||||||||||||
| 203 | 0 | my ($main_title, $title); | |||||||||||||||||||||
| 204 | 0 | ▶ | if ($ctx->response->has_page_title) { | ||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||
| 205 | 0 | $title = $ctx->response->page_title; | |||||||||||||||||||||
| 206 | 0 | $main_title = $ctx->response->page_title . ' - Yukki'; | |||||||||||||||||||||
| 207 | } | ||||||||||||||||||||||
| 208 | else { | ||||||||||||||||||||||
| 209 | 0 | $title = $main_title = 'Yukki'; | |||||||||||||||||||||
| 210 | } | ||||||||||||||||||||||
| 211 | |||||||||||||||||||||||
| 212 | my %menu_vars = map { | ||||||||||||||||||||||
| 213 | 0 | $_ => $self->available_menu_items($ctx, $_) | |||||||||||||||||||||
| 214 | 0 | } @{ $self->app->settings->menu_names }; | |||||||||||||||||||||
| 215 | |||||||||||||||||||||||
| 216 | 0 | my @scripts = $self->app->settings->all_scripts; | |||||||||||||||||||||
| 217 | 0 | my @styles = $self->app->settings->all_styles; | |||||||||||||||||||||
| 218 | |||||||||||||||||||||||
| 219 | 0 | ▶ | my $view = $ctx->request->parameters->{view} // 'default'; | ||||||||||||||||||||
|
Condition0%0/2
$ctx->request->parameters->{"view"} // "default"
MC/DC0%0/1
$ctx->request->parameters->{"view"} // "default"
$ctx->request->parameters->{"view"}
Truth table0%0/2
A
A= $ctx->request->parameters->{"view"}
| |||||||||||||||||||||||
| 220 | |||||||||||||||||||||||
| 221 | 0 | ▶ | $vars->{'head script.local'} //= []; | ||||||||||||||||||||
|
Condition0%0/2
$vars->{"head script.local"} //= []
MC/DC0%0/1
$vars->{"head script.local"} //= []
$vars->{"head script.local"}
Truth table0%0/2
A
A= $vars->{"head script.local"}
| |||||||||||||||||||||||
| 222 | 0 | ▶ | $vars->{'head link.local'} //= []; | ||||||||||||||||||||
|
Condition0%0/2
$vars->{"head link.local"} //= []
MC/DC0%0/1
$vars->{"head link.local"} //= []
$vars->{"head link.local"}
Truth table0%0/2
A
A= $vars->{"head link.local"}
| |||||||||||||||||||||||
| 223 | |||||||||||||||||||||||
| 224 | return $self->render( | ||||||||||||||||||||||
| 225 | template => $self->page_template($view), | ||||||||||||||||||||||
| 226 | context => $ctx, | ||||||||||||||||||||||
| 227 | vars => { | ||||||||||||||||||||||
| 228 | $vars->%*, | ||||||||||||||||||||||
| 229 | scripts => [ | ||||||||||||||||||||||
| 230 | 0 | map { $ctx->rebase_url($_) } | |||||||||||||||||||||
| 231 | @scripts, | ||||||||||||||||||||||
| 232 | $vars->{'head script.local'}->@*, | ||||||||||||||||||||||
| 233 | ], | ||||||||||||||||||||||
| 234 | links => [ | ||||||||||||||||||||||
| 235 | 0 | ▶ | map { $ctx->rebase_url($_) } | ||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||
| 236 | @styles, | ||||||||||||||||||||||
| 237 | $vars->{'head link.local'}->@*, | ||||||||||||||||||||||
| 238 | ], | ||||||||||||||||||||||
| 239 | 'messages' => $messages, | ||||||||||||||||||||||
| 240 | 'main_title' => $main_title, | ||||||||||||||||||||||
| 241 | 'title' => $title, | ||||||||||||||||||||||
| 242 | %menu_vars, | ||||||||||||||||||||||
| 243 | 'breadcrumb' => $ctx->response->has_breadcrumb ? [ | ||||||||||||||||||||||
| 244 | map { | ||||||||||||||||||||||
| 245 | 0 | +{ | |||||||||||||||||||||
| 246 | %$_, | ||||||||||||||||||||||
| 247 | 0 | href => $ctx->rebase_url($_->{href}), | |||||||||||||||||||||
| 248 | } | ||||||||||||||||||||||
| 249 | } $ctx->response->breadcrumb_links | ||||||||||||||||||||||
| 250 | ] : undef, | ||||||||||||||||||||||
| 251 | 'content' => $self->render( | ||||||||||||||||||||||
| 252 | template => $template, | ||||||||||||||||||||||
| 253 | context => $ctx, | ||||||||||||||||||||||
| 254 | vars => $vars, | ||||||||||||||||||||||
| 255 | ), | ||||||||||||||||||||||
| 256 | }, | ||||||||||||||||||||||
| 257 | ); | ||||||||||||||||||||||
| 258 | } | ||||||||||||||||||||||
| 259 | |||||||||||||||||||||||
| 260 | |||||||||||||||||||||||
| 261 | sub available_menu_items { | ||||||||||||||||||||||
| 262 | 0 | ▶ | my ($self, $ctx, $name) = @_; | ||||||||||||||||||||
|
Subroutine
available_menu_items: not called CC=5 SCAR=34.0
Pod
documented
| |||||||||||||||||||||||
| 263 | |||||||||||||||||||||||
| 264 | my @items = map { | ||||||||||||||||||||||
| 265 | +{ | ||||||||||||||||||||||
| 266 | %$_, | ||||||||||||||||||||||
| 267 | 0 | href => $ctx->rebase_url($_->{href}), | |||||||||||||||||||||
| 268 | }, | ||||||||||||||||||||||
| 269 | } grep { | ||||||||||||||||||||||
| 270 | 0 | my $url = $_->{href}; $url =~ s{\?.*$}{}; | |||||||||||||||||||||
| 271 | |||||||||||||||||||||||
| 272 | 0 | my $match = $self->app->router->match($url); | |||||||||||||||||||||
| 273 | 0 | ▶ | return unless $match; | ||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||
| 274 | 0 | my $access_level_needed = $match->access_level; | |||||||||||||||||||||
| 275 | $self->check_access( | ||||||||||||||||||||||
| 276 | user => $ctx->session->{user}, | ||||||||||||||||||||||
| 277 | repository => $match->mapping->{repository} // '-', | ||||||||||||||||||||||
| 278 | 0 | ▶ | special => $match->mapping->{special} // '-', | ||||||||||||||||||||
|
Condition0%0/4
$match->mapping->{"repository"} // "-"
$match->mapping->{"special"} // "-"
MC/DC0%0/1
$match->mapping->{"repository"} // "-"
$match->mapping->{"repository"}
MC/DC0%0/1
$match->mapping->{"special"} // "-"
$match->mapping->{"special"}
Truth table0%0/2
A
A= $match->mapping->{"repository"}
Truth table0%0/2
A
A= $match->mapping->{"special"}
| |||||||||||||||||||||||
| 279 | needs => $access_level_needed, | ||||||||||||||||||||||
| 280 | ); | ||||||||||||||||||||||
| 281 | } $ctx->response->navigation_menu($name); | ||||||||||||||||||||||
| 282 | |||||||||||||||||||||||
| 283 | 0 | ▶ | return @items ? \@items : undef; | ||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||
| 284 | } | ||||||||||||||||||||||
| 285 | |||||||||||||||||||||||
| 286 | |||||||||||||||||||||||
| 287 | sub render_links { | ||||||||||||||||||||||
| 288 | 0 | ▶ | my ($self, $opt) | ||||||||||||||||||||
|
Subroutine
render_links: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||
| 289 | = validate(\@_, class_type(__PACKAGE__), | ||||||||||||||||||||||
| 290 | slurpy Dict[ | ||||||||||||||||||||||
| 291 | context => class_type('Yukki::Web::Context'), | ||||||||||||||||||||||
| 292 | links => ArrayRef[HashRef], | ||||||||||||||||||||||
| 293 | ]); | ||||||||||||||||||||||
| 294 | 0 | my ($ctx, $links) = @{$opt}{qw( context links )}; | |||||||||||||||||||||
| 295 | |||||||||||||||||||||||
| 296 | return $self->render( | ||||||||||||||||||||||
| 297 | template => $self->links_template, | ||||||||||||||||||||||
| 298 | context => $ctx, | ||||||||||||||||||||||
| 299 | vars => { | ||||||||||||||||||||||
| 300 | links => [ map { | ||||||||||||||||||||||
| 301 | 0 | +{ | |||||||||||||||||||||
| 302 | label => $_->{label}, | ||||||||||||||||||||||
| 303 | 0 | href => $ctx->rebase_url($_->{href}), | |||||||||||||||||||||
| 304 | } | ||||||||||||||||||||||
| 305 | } @$links ], | ||||||||||||||||||||||
| 306 | }, | ||||||||||||||||||||||
| 307 | ); | ||||||||||||||||||||||
| 308 | } | ||||||||||||||||||||||
| 309 | |||||||||||||||||||||||
| 310 | |||||||||||||||||||||||
| 311 | sub render { | ||||||||||||||||||||||
| 312 | 0 | ▶ | my ($self, $opt) | ||||||||||||||||||||
|
Subroutine
render: not called CC=2 SCAR=17.9
Pod
documented
| |||||||||||||||||||||||
| 313 | = validate(\@_, class_type(__PACKAGE__), | ||||||||||||||||||||||
| 314 | slurpy Dict[ | ||||||||||||||||||||||
| 315 | template => class_type('Template::Pure'), | ||||||||||||||||||||||
| 316 | context => class_type('Yukki::Web::Context'), | ||||||||||||||||||||||
| 317 | vars => HashRef, | ||||||||||||||||||||||
| 318 | ]); | ||||||||||||||||||||||
| 319 | 0 | my ($template, $ctx, $vars) = @{$opt}{qw( template context vars )}; | |||||||||||||||||||||
| 320 | 0 | ▶ | $vars //= {}; | ||||||||||||||||||||
|
Condition0%0/2
$vars //= {}
MC/DC0%0/1
$vars //= {}
$vars
Truth table0%0/2
A
A= $vars
| |||||||||||||||||||||||
| 321 | |||||||||||||||||||||||
| 322 | 0 | my %vars = ( | |||||||||||||||||||||
| 323 | %$vars, | ||||||||||||||||||||||
| 324 | ctx => $ctx, | ||||||||||||||||||||||
| 325 | view => $self, | ||||||||||||||||||||||
| 326 | ); | ||||||||||||||||||||||
| 327 | |||||||||||||||||||||||
| 328 | 0 | return $template->render($vars); | |||||||||||||||||||||
| 329 | } | ||||||||||||||||||||||
| 330 | |||||||||||||||||||||||
| 331 | 15 | 1; | |||||||||||||||||||||
| 332 | |||||||||||||||||||||||
| 333 | __END__ | ||||||||||||||||||||||
| 334 | |||||||||||||||||||||||
| 335 | =pod | ||||||||||||||||||||||
| 336 | |||||||||||||||||||||||
| 337 | =encoding UTF-8 | ||||||||||||||||||||||
| 338 | |||||||||||||||||||||||
| 339 | =head1 NAME | ||||||||||||||||||||||
| 340 | |||||||||||||||||||||||
| 341 | Yukki::Web::View - base class for Yukki::Web views | ||||||||||||||||||||||
| 342 | |||||||||||||||||||||||
| 343 | =head1 VERSION | ||||||||||||||||||||||
| 344 | |||||||||||||||||||||||
| 345 | version 0.991_002 | ||||||||||||||||||||||
| 346 | |||||||||||||||||||||||
| 347 | =head1 DESCRIPTION | ||||||||||||||||||||||
| 348 | |||||||||||||||||||||||
| 349 | This is the base class for all L<Yukki::Web> views. | ||||||||||||||||||||||
| 350 | |||||||||||||||||||||||
| 351 | =head1 ATTRIBUTES | ||||||||||||||||||||||
| 352 | |||||||||||||||||||||||
| 353 | =head2 app | ||||||||||||||||||||||
| 354 | |||||||||||||||||||||||
| 355 | This is the L<Yukki::Web> singleton. | ||||||||||||||||||||||
| 356 | |||||||||||||||||||||||
| 357 | =head2 markdown | ||||||||||||||||||||||
| 358 | |||||||||||||||||||||||
| 359 | This is the L<Text::MultiMarkdown> object for rendering L</yukkitext>. Do not | ||||||||||||||||||||||
| 360 | use. | ||||||||||||||||||||||
| 361 | |||||||||||||||||||||||
| 362 | Provides a C<format_markdown> method delegated to C<markdown>. Do not use. | ||||||||||||||||||||||
| 363 | |||||||||||||||||||||||
| 364 | =head2 messages_template | ||||||||||||||||||||||
| 365 | |||||||||||||||||||||||
| 366 | This is the template used to render info, warning, and error messages to the page. | ||||||||||||||||||||||
| 367 | |||||||||||||||||||||||
| 368 | =head2 links_template | ||||||||||||||||||||||
| 369 | |||||||||||||||||||||||
| 370 | This is the template object used to render links. | ||||||||||||||||||||||
| 371 | |||||||||||||||||||||||
| 372 | =head1 METHODS | ||||||||||||||||||||||
| 373 | |||||||||||||||||||||||
| 374 | =head2 page_template | ||||||||||||||||||||||
| 375 | |||||||||||||||||||||||
| 376 | my $template = $self->page_template('default'); | ||||||||||||||||||||||
| 377 | |||||||||||||||||||||||
| 378 | Returns the template used to render pages for the given style name. | ||||||||||||||||||||||
| 379 | |||||||||||||||||||||||
| 380 | =head2 prepare_template | ||||||||||||||||||||||
| 381 | |||||||||||||||||||||||
| 382 | my $template = $self->prepare_template({ | ||||||||||||||||||||||
| 383 | template => 'foo.html', | ||||||||||||||||||||||
| 384 | directives => { ... }, | ||||||||||||||||||||||
| 385 | }); | ||||||||||||||||||||||
| 386 | |||||||||||||||||||||||
| 387 | This prepares a template for later rendering. | ||||||||||||||||||||||
| 388 | |||||||||||||||||||||||
| 389 | The C<template> is the name of the template file to use. | ||||||||||||||||||||||
| 390 | |||||||||||||||||||||||
| 391 | The C<directives> are the L<Template::Pure> directives to apply data given at render time to modify the template to create the output. | ||||||||||||||||||||||
| 392 | |||||||||||||||||||||||
| 393 | =head2 render_page | ||||||||||||||||||||||
| 394 | |||||||||||||||||||||||
| 395 | my $document = $self->render_page({ | ||||||||||||||||||||||
| 396 | template => 'foo.html', | ||||||||||||||||||||||
| 397 | context => $ctx, | ||||||||||||||||||||||
| 398 | vars => { ... }, | ||||||||||||||||||||||
| 399 | }); | ||||||||||||||||||||||
| 400 | |||||||||||||||||||||||
| 401 | This renders the given template and places it into the content section of the | ||||||||||||||||||||||
| 402 | F<shell.html> template. | ||||||||||||||||||||||
| 403 | |||||||||||||||||||||||
| 404 | The C<context> is used to render parts of the shell template. | ||||||||||||||||||||||
| 405 | |||||||||||||||||||||||
| 406 | The C<vars> are processed against the given template with L<Template::Pure>. | ||||||||||||||||||||||
| 407 | |||||||||||||||||||||||
| 408 | =head2 available_menu_items | ||||||||||||||||||||||
| 409 | |||||||||||||||||||||||
| 410 | my @items = $self->available_menu_items($ctx, 'menu_name'); | ||||||||||||||||||||||
| 411 | |||||||||||||||||||||||
| 412 | Retrieves the navigation menu from the L<Yukki::Web::Response> and purges any links that the current user does not have access to. | ||||||||||||||||||||||
| 413 | |||||||||||||||||||||||
| 414 | =head2 render_links | ||||||||||||||||||||||
| 415 | |||||||||||||||||||||||
| 416 | my $document = $self->render_links($ctx, \@navigation_links); | ||||||||||||||||||||||
| 417 | |||||||||||||||||||||||
| 418 | This renders a set of links using the F<links.html> template. | ||||||||||||||||||||||
| 419 | |||||||||||||||||||||||
| 420 | =head2 render | ||||||||||||||||||||||
| 421 | |||||||||||||||||||||||
| 422 | my $document = $self->render({ | ||||||||||||||||||||||
| 423 | template => $template, | ||||||||||||||||||||||
| 424 | vars => { ... }, | ||||||||||||||||||||||
| 425 | }); | ||||||||||||||||||||||
| 426 | |||||||||||||||||||||||
| 427 | This renders the given L<Template::Pure>. The C<vars> are | ||||||||||||||||||||||
| 428 | used as the ones passed to the C<process> method. | ||||||||||||||||||||||
| 429 | |||||||||||||||||||||||
| 430 | =head1 AUTHOR | ||||||||||||||||||||||
| 431 | |||||||||||||||||||||||
| 432 | Andrew Sterling Hanenkamp <hanenkamp@cpan.org> | ||||||||||||||||||||||
| 433 | |||||||||||||||||||||||
| 434 | =head1 COPYRIGHT AND LICENSE | ||||||||||||||||||||||
| 435 | |||||||||||||||||||||||
| 436 | This software is copyright (c) 2017 by Qubling Software LLC. | ||||||||||||||||||||||
| 437 | |||||||||||||||||||||||
| 438 | This is free software; you can redistribute it and/or modify it under | ||||||||||||||||||||||
| 439 | the same terms as the Perl 5 programming language system itself. | ||||||||||||||||||||||
| 440 | |||||||||||||||||||||||
| 441 | =cut | ||||||||||||||||||||||