/[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

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

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 180 by dpavlin, Sun Nov 27 17:26:43 2005 UTC revision 274 by dpavlin, Sat Dec 17 03:20:14 2005 UTC
# Line 75  sub template : Local { Line 75  sub template : Local {
75                  if ($webpac->save_html( $template_full_path, $t )) {                  if ($webpac->save_html( $template_full_path, $t )) {
76                          $c->res->output("<span>saved $template_filename, $size bytes</span>");                          $c->res->output("<span>saved $template_filename, $size bytes</span>");
77                  } else {                  } else {
78                          $c->res->output("<span>error saving $template_filename!</span>");                          $c->res->output("<span class=\"error\">error saving $template_filename!</span>");
79                  }                  }
80                  return;                  return;
81          }          }
# Line 131  sub css : Local { Line 131  sub css : Local {
131                  if ($webpac->save_html( $css_full_path, $t )) {                  if ($webpac->save_html( $css_full_path, $t )) {
132                          $c->res->output("<span>saved $css_filename, $size bytes</span>");                          $c->res->output("<span>saved $css_filename, $size bytes</span>");
133                  } else {                  } else {
134                          $c->res->output("<span>error saving $css_filename!</span>");                          $c->res->output("<span class=\"error\">error saving $css_filename!</span>");
135                  }                  }
136                  return;                  return;
137          }          }
# Line 140  sub css : Local { Line 140  sub css : Local {
140    
141          $c->stash->{'css_content'} = $webpac->load_html( $css_full_path );          $c->stash->{'css_content'} = $webpac->load_html( $css_full_path );
142    
143            $c->stash->{'css_list'} = [ qw/user.css foobar.css/ ];
144    
145          $c->stash->{template} = 'editor/css.tt';          $c->stash->{template} = 'editor/css.tt';
146  }  }
147    
# Line 154  sub record : Local { Line 156  sub record : Local {
156    
157          $c->log->debug('record params '.Dumper($c->req->params));          $c->log->debug('record params '.Dumper($c->req->params));
158    
159          my $mfn = $c->req->params->{mfn};          my $record_uri = $c->req->params->{record_uri};
160            $record_uri ||= $c->config->{editor}->{default_record_uri} and
161          if (! $mfn) {                  $c->log->warn("using editor: default_record_uri");
162                  $c->log->warn("no mfn, using 1");  
163                  $mfn = 1;          if (! $record_uri) {
164                    $c->log->fatal("record called without record_uri and default_record_uri not found in config under editor");
165                    $c->stash->{error} = 'record retrival failed';
166                    $c->stash->{template} = 'error.tt';
167                    return;
168          }          }
169    
170          my $template_filename = $c->req->params->{template_filename};          my $template_filename = $c->req->params->{template_filename};
# Line 169  sub record : Local { Line 175  sub record : Local {
175    
176          my $webpac = $c->comp('Model::WebPAC');          my $webpac = $c->comp('Model::WebPAC');
177    
178          my $html = $webpac->record( mfn => $mfn, template => $template_filename );          my $html = $webpac->record( record_uri => $record_uri, template => $template_filename );
179    
180          if ($html) {          if ($html) {
181                  $c->log->debug('check html with tidy');                  $c->log->debug('check html with tidy');
# Line 180  sub record : Local { Line 186  sub record : Local {
186                          qr/inserting missing 'title' element/,                          qr/inserting missing 'title' element/,
187                          qr/lacks "summary" attribute/,                          qr/lacks "summary" attribute/,
188                  ] );                  ] );
                 if ( $tidy->parse('html', $html) ) {  
                         if ( $tidy->messages ) {  
                                 $html .= '<div class="tidy">HTML Tidy output:';  
189    
190                                  my @lines = split(/[\n\r]+/, $html);                  my @lines = split( "\n", $html );
191                    $_ = "$_\n" for @lines;
192    
193                    if ( $tidy->parse('tidy', @lines) ) {
194                            if ( $tidy->messages ) {
195                                    $html .= <<__TIDY_CLOSE__;
196    <div id="tidy_show" class="notice" style="display: none;" onclick="Element.hide('tidy_show'); Element.show('tidy');">?</div>
197    <div id="tidy" class="tidy">
198    <a href="#" onclick="Element.hide('tidy'); Element.show('tidy_show'); return false;">close</a>
199    HTML Tidy output:
200    <br/>
201    __TIDY_CLOSE__
202                                  # Escape <, >, & and ", and to produce valid XML                                  # Escape <, >, & and ", and to produce valid XML
203                                  my %escape = ('<'=>'&lt;', '>'=>'&gt;', '&'=>'&amp;', '"'=>'&quot;');                                  my %escape = ('<'=>'&lt;', '>'=>'&gt;', '&'=>'&amp;', '"'=>'&quot;');
204                                  my $escape_re  = join '|' => keys %escape;                                  my $escape_re  = join '|' => keys %escape;
205    
   
206                                  foreach my $m ( $tidy->messages ) {                                  foreach my $m ( $tidy->messages ) {
207                                          my $c = $lines[ ( $m->line - 2 ) ];                                          my $c = $lines[ ( $m->line - 1 ) ];
208                                          my $txt = $m->as_string;                                          my $txt = $m->as_string;
209                                          $c =~ s/($escape_re)/$escape{$1}/g;                                          $c =~ s/($escape_re)/$escape{$1}/g;
210                                          $txt =~ s/($escape_re)/$escape{$1}/g;                                          $txt =~ s/($escape_re)/$escape{$1}/g;
211                                          my $class = '';                                          my $class = '';
212                                          $class = ' class="tidy_'.lc($1).'"' if ($txt =~ /(Warning|Error):/s);                                          $class = ' class="tidy_'.lc($1).'"' if ($txt =~ /(Warning|Error):/s);
213                                          $html .= "<div${class}>$txt | <tt>$c</tt></div>";                                          $html .= 'line ' . $m->line . ":<span${class}>$txt<tt>$c</tt></span>";
214                                  }                                  }
215                                  $html .= '</div>';                                  $html .= '</div>';
216                          }                          }
217                  } else {                  } else {
218                          $html .= qq{<div class="tidy tidy_error">Can't parse this record with HTML Tidy!</div>};                          $html .= qq{<div class="tidy tidy_error">Can't parse this record with HTML Tidy!</div>};
219                  }                  }
220            } else {
221                    $html .= qq{<div class="no_results">Can't find record</div>};
222          }          }
223                    
                   
224          $c->response->content_type('text/html; charset=utf-8');          $c->response->content_type('text/html; charset=utf-8');
225          $c->res->output( $html );          $c->response->body( $html );
226  }  }
227    
228    

Legend:
Removed from v.180  
changed lines
  Added in v.274

  ViewVC Help
Powered by ViewVC 1.1.26