/[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 242 by dpavlin, Wed Dec 14 18:56:17 2005 UTC
# 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    
161          if (! $mfn) {          if (! $record_uri) {
162                  $c->log->warn("no mfn, using 1");                  $c->log->fatal("no record_uri");
163                  $mfn = 1;                  return;
164          }          }
165    
166          my $template_filename = $c->req->params->{template_filename};          my $template_filename = $c->req->params->{template_filename};
# Line 169  sub record : Local { Line 171  sub record : Local {
171    
172          my $webpac = $c->comp('Model::WebPAC');          my $webpac = $c->comp('Model::WebPAC');
173    
174          my $html = $webpac->record( mfn => $mfn, template => $template_filename );          my $html = $webpac->record( record_uri => $record_uri, template => $template_filename );
175    
176          if ($html) {          if ($html) {
177                  $c->log->debug('check html with tidy');                  $c->log->debug('check html with tidy');
# Line 180  sub record : Local { Line 182  sub record : Local {
182                          qr/inserting missing 'title' element/,                          qr/inserting missing 'title' element/,
183                          qr/lacks "summary" attribute/,                          qr/lacks "summary" attribute/,
184                  ] );                  ] );
                 if ( $tidy->parse('html', $html) ) {  
                         if ( $tidy->messages ) {  
                                 $html .= '<div class="tidy">HTML Tidy output:';  
185    
186                                  my @lines = split(/[\n\r]+/, $html);                  my @lines = split( "\n", $html );
187                    $_ = "$_\n" for @lines;
188    
189                    if ( $tidy->parse('tidy', @lines) ) {
190                            if ( $tidy->messages ) {
191                                    $html .= <<__TIDY_CLOSE__;
192    <div id="tidy_show" class="notice" style="display: none;" onclick="Element.hide('tidy_show'); Element.show('tidy');">?</div>
193    <div id="tidy" class="tidy">
194    <a href="#" onclick="Element.hide('tidy'); Element.show('tidy_show'); return false;">close</a>
195    HTML Tidy output:
196    <br/>
197    __TIDY_CLOSE__
198                                  # Escape <, >, & and ", and to produce valid XML                                  # Escape <, >, & and ", and to produce valid XML
199                                  my %escape = ('<'=>'&lt;', '>'=>'&gt;', '&'=>'&amp;', '"'=>'&quot;');                                  my %escape = ('<'=>'&lt;', '>'=>'&gt;', '&'=>'&amp;', '"'=>'&quot;');
200                                  my $escape_re  = join '|' => keys %escape;                                  my $escape_re  = join '|' => keys %escape;
201    
   
202                                  foreach my $m ( $tidy->messages ) {                                  foreach my $m ( $tidy->messages ) {
203                                          my $c = $lines[ ( $m->line - 2 ) ];                                          my $c = $lines[ ( $m->line - 1 ) ];
204                                          my $txt = $m->as_string;                                          my $txt = $m->as_string;
205                                          $c =~ s/($escape_re)/$escape{$1}/g;                                          $c =~ s/($escape_re)/$escape{$1}/g;
206                                          $txt =~ s/($escape_re)/$escape{$1}/g;                                          $txt =~ s/($escape_re)/$escape{$1}/g;
207                                          my $class = '';                                          my $class = '';
208                                          $class = ' class="tidy_'.lc($1).'"' if ($txt =~ /(Warning|Error):/s);                                          $class = ' class="tidy_'.lc($1).'"' if ($txt =~ /(Warning|Error):/s);
209                                          $html .= "<div${class}>$txt | <tt>$c</tt></div>";                                          $html .= 'line ' . $m->line . ":<span${class}>$txt<tt>$c</tt></span>";
210                                  }                                  }
211                                  $html .= '</div>';                                  $html .= '</div>';
212                          }                          }
213                  } else {                  } else {
214                          $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>};
215                  }                  }
216            } else {
217                    $html .= qq{<div class="no_results">Can't find record</div>};
218          }          }
219                    
                   
220          $c->response->content_type('text/html; charset=utf-8');          $c->response->content_type('text/html; charset=utf-8');
221          $c->res->output( $html );          $c->response->body( $html );
222  }  }
223    
224    

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

  ViewVC Help
Powered by ViewVC 1.1.26