/[webpac2]/Webpacus/lib/Webpacus/Controller/Editor.pm
This is repository of my old source code which isn't updated any more. Go to git.rot13.org for current projects!
ViewVC logotype

Annotation of /Webpacus/lib/Webpacus/Controller/Editor.pm

Parent Directory Parent Directory | Revision Log Revision Log


Revision 167 - (hide annotations)
Sat Nov 26 21:11:41 2005 UTC (18 years, 5 months ago) by dpavlin
File size: 3312 byte(s)
 r11170@llin:  dpavlin | 2005-11-26 22:13:58 +0100
 implemented template list and switching

1 dpavlin 134 package Webpacus::Controller::Editor;
2    
3     use strict;
4     use warnings;
5     use base 'Catalyst::Controller';
6    
7 dpavlin 165 use Data::Dumper;
8    
9 dpavlin 134 =head1 NAME
10    
11 dpavlin 165 Webpacus::Controller::Editor - AJAX template and CSS editor
12 dpavlin 134
13     =head1 SYNOPSIS
14    
15 dpavlin 165 See L<Webpacus>, L<WebPAC>
16 dpavlin 134
17     =head1 DESCRIPTION
18    
19     Catalyst Controller.
20    
21     =head1 METHODS
22    
23     =over 4
24    
25     =item default
26    
27     =cut
28    
29     sub default : Private {
30 dpavlin 165 my ( $self, $c ) = @_;
31 dpavlin 134
32 dpavlin 165 my $webpac = $c->comp('Model::WebPAC');
33     my $params = $c->req->params;
34     my $log = $c->log;
35 dpavlin 134
36 dpavlin 165 my $template_filename =
37     $c->req->params->{template_filename} ||
38     $c->config->{webpac}->{default_template} ||
39     $c->log->fatal("need default_template");
40    
41     $c->stash->{template_filename} = $template_filename;
42    
43     $c->stash->{template} = 'editor.tt';
44 dpavlin 134 }
45    
46 dpavlin 165 =item template
47    
48     fetch template using C<template_filename> in request or
49     C<< webpac->default_template >>.
50    
51     =cut
52    
53 dpavlin 134 sub template : Local {
54 dpavlin 135 my ( $self, $c ) = @_;
55 dpavlin 134
56 dpavlin 167 my $template_filename =
57 dpavlin 165 $c->req->params->{template_filename} ||
58     $c->config->{webpac}->{default_template} ||
59     $c->log->fatal("need default_template");
60 dpavlin 135
61     my $webpac = $c->comp('Model::WebPAC');
62    
63 dpavlin 167 my $template_path = $webpac->{template_path} || $c->log->fatal("can't find template_path in Model::WebPAC");
64 dpavlin 135
65 dpavlin 167 my $template_full_path = "$template_path/$template_filename";
66    
67 dpavlin 165 $c->log->debug("loading $template_full_path");
68    
69     if (! -r $template_full_path) {
70     $c->log->warn("can't find '$template_full_path': $!");
71     $c->res->output("can't find template '$template_full_path'");
72     return;
73     }
74    
75 dpavlin 167 # load template html
76 dpavlin 135 $c->stash->{'template_content'} =
77     $webpac->load_html( $template_full_path );
78    
79 dpavlin 167 # load template list
80    
81     opendir(my $d, $template_path) || $c->log->fatal("can't opendir '$template_path': $!");
82     my @templates = grep { /\.tt$/i } readdir($d);
83    
84     $c->stash->{template_list} = \@templates;
85     $c->stash->{template_filename} = $template_filename;
86    
87 dpavlin 135 $c->stash->{template} = 'editor/template.tt';
88 dpavlin 134 }
89    
90 dpavlin 165 =item css
91    
92 dpavlin 167 Return css.
93    
94     B<Not finished>
95    
96 dpavlin 165 =cut
97    
98 dpavlin 134 sub css : Local {
99 dpavlin 135 my ( $self, $c ) = @_;
100 dpavlin 134
101 dpavlin 135 my $css_file = $c->config->{webpac}->{default_css} || die("need default_css");
102     my $css_path = $c->config->{webpac}->{css_path} || die("need css_path");
103     my $webpac = $c->comp('Model::WebPAC');
104 dpavlin 165
105     my $css_full_path = "$css_path/$css_file";
106    
107     $c->log->debug("loading $css_full_path");
108    
109     $c->stash->{'css_content'} = $webpac->load_html( $css_full_path );
110    
111 dpavlin 135 $c->stash->{template} = 'editor/css.tt';
112 dpavlin 134 }
113    
114 dpavlin 165 =item record
115    
116 dpavlin 167 Return html of record taking C<mfn> and C<template_filename> from request.
117    
118 dpavlin 165 =cut
119    
120     sub record : Local {
121     my ( $self, $c ) = @_;
122    
123     $c->log->debug('record params '.Dumper($c->req->params));
124    
125     my $mfn = $c->req->params->{mfn};
126    
127     if (! $mfn) {
128     $c->log->warn("no mfn, using 1");
129     $mfn = 1;
130     }
131    
132     my $template_filename = $c->req->params->{template_filename};
133     if (! $template_filename) {
134     $template_filename = $c->config->{webpac}->{default_template} || $c->log->fatal("no webpac->default_template in configuration!");
135     $c->log->warn("no template_filename using $template_filename");
136     }
137    
138     my $webpac = $c->comp('Model::WebPAC');
139    
140     $c->res->output(
141     $webpac->record( mfn => $mfn, template => $template_filename )
142     );
143     }
144    
145 dpavlin 167
146    
147 dpavlin 134 =back
148    
149     =head1 AUTHOR
150    
151 dpavlin 165 Dobrica Pavlinusic, C<< <dpavlin@rot13.org> >>
152 dpavlin 134
153     =head1 LICENSE
154    
155     This library is free software, you can redistribute it and/or modify
156     it under the same terms as Perl itself.
157    
158     =cut
159    
160     1;

  ViewVC Help
Powered by ViewVC 1.1.26