3 use Web::Simple __PACKAGE__;
4 use Method::Signatures::Simple;
9 package App::IdiotBox::Announcement;
11 sub made_at { shift->{made_at} }
12 sub bucket { shift->{bucket} }
13 sub video_count { shift->{video_count} }
15 package App::IdiotBox::Bucket;
17 sub slug { shift->{slug} }
18 sub name { shift->{name} }
19 sub video_count { shift->{video_count} }
23 template_dir => $FindBin::Bin.'/../share/html'
27 sub (/) { $self->show_front_page },
28 subdispatch sub (/*/...) {
29 my $bucket = $self->buckets->get({ slug => $_[1] });
32 $self->show_bucket($bucket)
35 $self->show_video($bucket->videos->get({ slug => $_[1] }));
41 method recent_announcements { $self->{recent_announcements} }
43 method show_front_page {
44 my $ann = $self->recent_announcements;
47 '#announcement-list' => [
49 repeat_for => $ann->map(sub { [
50 '.fill-bucket-name' => [
51 -replace_content => { replace_with => $_->bucket->name }
53 '.fill-bucket-link' => [
54 -set_attribute => { name => 'href', value => $_->bucket->slug.'/' }
56 '.fill-new-videos' => [
57 -replace_content => { replace_with => $_->video_count }
59 '.fill-total-videos' => [
60 -replace_content => { replace_with => $_->bucket->video_count }
69 method show_bucket ($bucket) {
70 $self->html_response(bucket => [
71 '.fill-bucket-name' => [
72 -replace_content => { replace_with => $bucket->name }
76 repeat_for => $bucket->videos->map(sub { [
77 '.fill-video-name' => [
78 -replace_content => { replace_with => $_->name }
80 '.fill-video-author' => [
81 -replace_content => { replace_with => $_->author }
83 '.fill-video-link' => [
85 name => 'href', value => $_->slug.'/'
94 method show_video ($video) {
95 $self->html_response(video => [
96 '.fill-video-name' => [
97 -replace_content => { replace_with => $video->name }
99 '.fill-author-name' => [
100 -replace_content => { replace_with => $video->author }
102 '.fill-bucket-link' => [
103 -set_attribute => { name => 'href', value => '../' }
105 '.fill-bucket-name' => [
106 -replace_content => { replace_with => $video->bucket->name }
108 '.fill-video-details' => [
109 -replace_content => { replace_with => $video->details }
114 method html_response ($template_name, $selectors) {
115 my $io = $self->_zoom_for($template_name => $selectors)->as_readable_fh;
116 return [ 200, [ 'Content-Type' => 'text/html' ], $io ]
119 method _template_filename_for ($name) {
120 $self->{config}{template_dir}.'/'.$name.'.html';
123 method _layout_zoom {
124 $self->{layout_zoom} ||= HTML::Zoom->from_file(
125 $self->_template_filename_for('layout')
129 method _zoom_for ($template_name, $selectors) {
130 ($self->{zoom_for_template}{$template_name} ||= do {
132 HTML::Zoom->from_file(
133 $self->_template_filename_for($template_name)
137 -capture_events => { into => \@body }
141 $self->_layout_zoom->with_selectors(
143 -replace_content_events => { replace_with => \@body }
146 })->with_selectors($selectors)