line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package CogWiki; |
2
|
2
|
|
|
2
|
|
1455
|
use Mo; |
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
3
|
|
|
|
|
|
|
extends 'Cog::App'; |
4
|
|
|
|
|
|
|
|
5
|
|
|
|
|
|
|
our $VERSION = '0.04'; |
6
|
|
|
|
|
|
|
|
7
|
|
|
|
|
|
|
use constant webapp_class => 'CogWiki::WebApp'; |
8
|
|
|
|
|
|
|
use constant maker_class => 'CogWiki::Maker'; |
9
|
|
|
|
|
|
|
|
10
|
|
|
|
|
|
|
package CogWiki::WebApp; |
11
|
|
|
|
|
|
|
use Mo; |
12
|
|
|
|
|
|
|
extends 'Cog::WebApp'; |
13
|
|
|
|
|
|
|
|
14
|
|
|
|
|
|
|
use constant SHARE_DIST => 'CogWiki'; |
15
|
|
|
|
|
|
|
use constant url_map => [ |
16
|
|
|
|
|
|
|
'()', |
17
|
|
|
|
|
|
|
['/' => 'redirect', ('/pages/')], |
18
|
|
|
|
|
|
|
['/home/?' => 'home_page'], |
19
|
|
|
|
|
|
|
['/pages/?' => 'page_list'], |
20
|
|
|
|
|
|
|
['/page/([A-Z0-9]{4})/?' => 'page_display', ('$1')], |
21
|
|
|
|
|
|
|
['/page/name/([^/]+)/?' => 'page_by_name', ('$1')], |
22
|
|
|
|
|
|
|
['/tags/' => 'tag_list' ], |
23
|
|
|
|
|
|
|
['/tag/([^/]+)/?' => 'tag_page_list', ('$1')], |
24
|
|
|
|
|
|
|
]; |
25
|
|
|
|
|
|
|
|
26
|
|
|
|
|
|
|
use constant site_navigation => [ |
27
|
|
|
|
|
|
|
'()', |
28
|
|
|
|
|
|
|
['Home' => '/home/'], |
29
|
|
|
|
|
|
|
['Recent Changes' => '/pages/'], |
30
|
|
|
|
|
|
|
['Tags' => '/tags/'], |
31
|
|
|
|
|
|
|
]; |
32
|
|
|
|
|
|
|
|
33
|
|
|
|
|
|
|
package CogWiki::Maker; |
34
|
|
|
|
|
|
|
use Mo; |
35
|
|
|
|
|
|
|
extends 'Cog::Maker'; |
36
|
|
|
|
|
|
|
use IO::All; |
37
|
|
|
|
|
|
|
|
38
|
|
|
|
|
|
|
sub all_files { |
39
|
|
|
|
|
|
|
my $self = shift; |
40
|
|
|
|
|
|
|
return grep { |
41
|
|
|
|
|
|
|
$_->filename =~ /\.cog$/; |
42
|
|
|
|
|
|
|
} io($self->config->content_root)->all_files; |
43
|
|
|
|
|
|
|
} |
44
|
|
|
|
|
|
|
|
45
|
|
|
|
|
|
|
sub make_cache { |
46
|
|
|
|
|
|
|
my $self = shift; |
47
|
|
|
|
|
|
|
io('cache')->mkdir; |
48
|
|
|
|
|
|
|
|
49
|
|
|
|
|
|
|
my $time = time; |
50
|
|
|
|
|
|
|
my $page_list = []; |
51
|
|
|
|
|
|
|
my $blobs = {}; |
52
|
|
|
|
|
|
|
|
53
|
|
|
|
|
|
|
$self->config->store->delete_tag_index; # XXX Temporary solution until can do smarter |
54
|
|
|
|
|
|
|
for my $page_file ($self->all_files) { |
55
|
|
|
|
|
|
|
my $page = $self->config->classes->{page}->from_text($page_file->all); |
56
|
|
|
|
|
|
|
my $id = $page->Short or next; |
57
|
|
|
|
|
|
|
|
58
|
|
|
|
|
|
|
for my $Name (@{$page->Name}) { |
59
|
|
|
|
|
|
|
my $name = $self->config->store->index_name($Name, $id); |
60
|
|
|
|
|
|
|
io->file("cache/name/$name.txt")->assert->print($id); |
61
|
|
|
|
|
|
|
} |
62
|
|
|
|
|
|
|
|
63
|
|
|
|
|
|
|
$self->config->store->index_tag($_, $id) |
64
|
|
|
|
|
|
|
for $self->all_tags($page); |
65
|
|
|
|
|
|
|
|
66
|
|
|
|
|
|
|
my $blob = { |
67
|
|
|
|
|
|
|
%$page, |
68
|
|
|
|
|
|
|
Id => $id, |
69
|
|
|
|
|
|
|
Type => $page->Type, |
70
|
|
|
|
|
|
|
Title => $page->Title, |
71
|
|
|
|
|
|
|
Time => $page->Time, |
72
|
|
|
|
|
|
|
size => length($page->Content), |
73
|
|
|
|
|
|
|
duration => $page->duration, |
74
|
|
|
|
|
|
|
}; |
75
|
|
|
|
|
|
|
delete $blob->{Content}; |
76
|
|
|
|
|
|
|
delete $blob->{Name}; |
77
|
|
|
|
|
|
|
push @$page_list, $blob; |
78
|
|
|
|
|
|
|
$blobs->{$id} = $blob; |
79
|
|
|
|
|
|
|
|
80
|
|
|
|
|
|
|
$self->make_page_html($page, $page_file); |
81
|
|
|
|
|
|
|
|
82
|
|
|
|
|
|
|
delete $page->{content}; |
83
|
|
|
|
|
|
|
io("cache/$id.json")->print($self->json->encode($blob)); |
84
|
|
|
|
|
|
|
} |
85
|
|
|
|
|
|
|
io("cache/page-list.json")->print($self->json->encode($page_list)); |
86
|
|
|
|
|
|
|
$self->make_tag_cloud($blobs); |
87
|
|
|
|
|
|
|
} |
88
|
|
|
|
|
|
|
|
89
|
|
|
|
|
|
|
sub make_page_html { |
90
|
|
|
|
|
|
|
my $self = shift; |
91
|
|
|
|
|
|
|
my $page = shift; |
92
|
|
|
|
|
|
|
my $page_file = shift; |
93
|
|
|
|
|
|
|
my $id = $page->Short; |
94
|
|
|
|
|
|
|
my $html_filename = "cache/$id.html"; |
95
|
|
|
|
|
|
|
|
96
|
|
|
|
|
|
|
return if -e $html_filename and -M $html_filename < -M $page_file->name; |
97
|
|
|
|
|
|
|
|
98
|
|
|
|
|
|
|
my $markup = $page->markup || 'simple'; |
99
|
|
|
|
|
|
|
my $method = "${markup}_to_html"; |
100
|
|
|
|
|
|
|
my $html = $self->$method($page->Content); |
101
|
|
|
|
|
|
|
|
102
|
|
|
|
|
|
|
print $page_file->filename . " -> $html_filename\n"; |
103
|
|
|
|
|
|
|
io($html_filename)->assert->print($html); |
104
|
|
|
|
|
|
|
} |
105
|
|
|
|
|
|
|
|
106
|
|
|
|
|
|
|
sub html_to_html { |
107
|
|
|
|
|
|
|
return $_[1]; |
108
|
|
|
|
|
|
|
} |
109
|
|
|
|
|
|
|
|
110
|
|
|
|
|
|
|
sub txt_to_html { |
111
|
|
|
|
|
|
|
my $self = shift; |
112
|
|
|
|
|
|
|
my $html = shift; |
113
|
|
|
|
|
|
|
|
114
|
|
|
|
|
|
|
$html =~ s/&/&/g; |
115
|
|
|
|
|
|
|
$html =~ s/</g; |
116
|
|
|
|
|
|
|
$html =~ s/>/>/g; |
117
|
|
|
|
|
|
|
|
118
|
|
|
|
|
|
|
$html = "$html \n"; |
119
|
|
|
|
|
|
|
|
120
|
|
|
|
|
|
|
return $html; |
121
|
|
|
|
|
|
|
} |
122
|
|
|
|
|
|
|
|
123
|
|
|
|
|
|
|
sub pod_to_html { |
124
|
|
|
|
|
|
|
my $self = shift; |
125
|
|
|
|
|
|
|
my $pod = shift; |
126
|
|
|
|
|
|
|
|
127
|
|
|
|
|
|
|
my $html; |
128
|
|
|
|
|
|
|
my $p = Pod::Simple::HTML->new; |
129
|
|
|
|
|
|
|
$p->output_string(\$html); |
130
|
|
|
|
|
|
|
$p->parse_string_document($pod); |
131
|
|
|
|
|
|
|
|
132
|
|
|
|
|
|
|
$html =~ s/.*!-- start doc -->(.*?) |