53 |
sub template : Local { |
sub template : Local { |
54 |
my ( $self, $c ) = @_; |
my ( $self, $c ) = @_; |
55 |
|
|
56 |
my $template_file = |
my $template_filename = |
57 |
$c->req->params->{template_filename} || |
$c->req->params->{template_filename} || |
58 |
$c->config->{webpac}->{default_template} || |
$c->config->{webpac}->{default_template} || |
59 |
$c->log->fatal("need default_template"); |
$c->log->fatal("need default_template"); |
60 |
|
|
61 |
my $webpac = $c->comp('Model::WebPAC'); |
my $webpac = $c->comp('Model::WebPAC'); |
62 |
|
|
63 |
my $template_full_path = $webpac->{template_path} . "/$template_file"; |
my $template_path = $webpac->{template_path} || $c->log->fatal("can't find template_path in Model::WebPAC"); |
64 |
|
|
65 |
|
my $template_full_path = "$template_path/$template_filename"; |
66 |
|
|
67 |
|
if ($c->req->params->{save_template}) { |
68 |
|
|
69 |
|
$c->response->content_type('text/html; charset=utf-8'); |
70 |
|
|
71 |
|
my $t = $c->req->params->{template_content}; |
72 |
|
my $size = length($t); |
73 |
|
$c->log->debug("saving $template_full_path, $size bytes"); |
74 |
|
if ($webpac->save_html( $template_full_path, $t )) { |
75 |
|
$c->res->output("<span>saved $template_filename, $size bytes</span>"); |
76 |
|
} else { |
77 |
|
$c->res->output("<span>error saving $template_filename!</span>"); |
78 |
|
} |
79 |
|
return; |
80 |
|
} |
81 |
|
|
82 |
$c->log->debug("loading $template_full_path"); |
$c->log->debug("loading $template_full_path"); |
83 |
|
|
84 |
if (! -r $template_full_path) { |
if (! -r $template_full_path) { |
85 |
$c->log->warn("can't find '$template_full_path': $!"); |
$c->log->warn("can't find '$template_full_path': $!"); |
86 |
|
$c->response->content_type('text/html; charset=utf-8'); |
87 |
$c->res->output("can't find template '$template_full_path'"); |
$c->res->output("can't find template '$template_full_path'"); |
88 |
return; |
return; |
89 |
} |
} |
90 |
|
|
91 |
|
# load template html |
92 |
$c->stash->{'template_content'} = |
$c->stash->{'template_content'} = |
93 |
$webpac->load_html( $template_full_path ); |
$webpac->load_html( $template_full_path ); |
94 |
|
|
95 |
|
# load template list |
96 |
|
|
97 |
|
opendir(my $d, $template_path) || $c->log->fatal("can't opendir '$template_path': $!"); |
98 |
|
my @templates = grep { /\.tt$/i } readdir($d); |
99 |
|
|
100 |
|
$c->stash->{template_list} = \@templates; |
101 |
|
$c->stash->{template_filename} = $template_filename; |
102 |
|
|
103 |
$c->stash->{template} = 'editor/template.tt'; |
$c->stash->{template} = 'editor/template.tt'; |
104 |
} |
} |
105 |
|
|
106 |
=item css |
=item css |
107 |
|
|
108 |
|
Return css. |
109 |
|
|
110 |
|
B<Not finished> |
111 |
|
|
112 |
=cut |
=cut |
113 |
|
|
114 |
sub css : Local { |
sub css : Local { |
115 |
my ( $self, $c ) = @_; |
my ( $self, $c ) = @_; |
116 |
|
|
117 |
my $css_file = $c->config->{webpac}->{default_css} || die("need default_css"); |
my $css_filename = $c->config->{webpac}->{default_css} || die("need default_css"); |
118 |
my $css_path = $c->config->{webpac}->{css_path} || die("need css_path"); |
my $css_path = $c->config->{webpac}->{css_path} || die("need css_path"); |
119 |
my $webpac = $c->comp('Model::WebPAC'); |
my $webpac = $c->comp('Model::WebPAC'); |
120 |
|
|
121 |
my $css_full_path = "$css_path/$css_file"; |
my $css_full_path = "$css_path/$css_filename"; |
122 |
|
|
123 |
|
if ($c->req->params->{save_css}) { |
124 |
|
|
125 |
|
$c->response->content_type('text/html; charset=utf-8'); |
126 |
|
|
127 |
|
my $t = $c->req->params->{css_content}; |
128 |
|
my $size = length($t); |
129 |
|
$c->log->debug("saving $css_full_path, $size bytes"); |
130 |
|
if ($webpac->save_html( $css_full_path, $t )) { |
131 |
|
$c->res->output("<span>saved $css_filename, $size bytes</span>"); |
132 |
|
} else { |
133 |
|
$c->res->output("<span>error saving $css_filename!</span>"); |
134 |
|
} |
135 |
|
return; |
136 |
|
} |
137 |
|
|
138 |
$c->log->debug("loading $css_full_path"); |
$c->log->debug("loading $css_full_path"); |
139 |
|
|
144 |
|
|
145 |
=item record |
=item record |
146 |
|
|
147 |
|
Return html of record taking C<mfn> and C<template_filename> from request. |
148 |
|
|
149 |
=cut |
=cut |
150 |
|
|
151 |
sub record : Local { |
sub record : Local { |
168 |
|
|
169 |
my $webpac = $c->comp('Model::WebPAC'); |
my $webpac = $c->comp('Model::WebPAC'); |
170 |
|
|
171 |
|
$c->response->content_type('text/html; charset=utf-8'); |
172 |
$c->res->output( |
$c->res->output( |
173 |
$webpac->record( mfn => $mfn, template => $template_filename ) |
$webpac->record( mfn => $mfn, template => $template_filename ) |
174 |
); |
); |
175 |
} |
} |
176 |
|
|
|
=back |
|
177 |
|
|
178 |
|
|
179 |
|
=back |
180 |
|
|
181 |
=head1 AUTHOR |
=head1 AUTHOR |
182 |
|
|
183 |
Dobrica Pavlinusic, C<< <dpavlin@rot13.org> >> |
Dobrica Pavlinusic, C<< <dpavlin@rot13.org> >> |