/[Perly]/lib/Perly/View.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 /lib/Perly/View.pm

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

revision 22 by dpavlin, Wed Jun 6 09:17:05 2007 UTC revision 47 by dpavlin, Sun Jun 8 18:44:27 2008 UTC
# Line 5  use warnings; Line 5  use warnings;
5    
6  use Jifty::View::Declare -base;  use Jifty::View::Declare -base;
7    
8    use Perly::SyntaxHighlight;
9  use Data::Dump qw/dump/;  use Data::Dump qw/dump/;
10    
11  template '/' => page {  template '/' => page {
# Line 18  template '/edit' => page { Line 19  template '/edit' => page {
19  };  };
20    
21  private template 'code_list' => sub {  private template 'code_list' => sub {
22          ul {          my $coll = Perly::Model::CodeCollection->new();
23                  my $coll = Perly::Model::CodeCollection->new();          $coll->unlimit;
24                  $coll->unlimit;          while ( my $code = $coll->next ) {
25                  while ( my $code = $coll->next ) {                  div {
26                          li {                          { class is 'code-name' }
27                                  a {                          hyperlink( url => '/edit/id=' . $code->id, label => $code->name ),
28                                          attr { href => '/edit?id=' . $code->id, },                          small { length( $code->source ), ' bytes ', $code->created_on, ' ' },
29                                          $code->name,                          hyperlink( url => '/run/code=' . $code->id, label => 'run' ),
30                                  },                  };
31                                  small { length( $code->source ), ' bytes ', $code->created_on },                  outs_raw( Perly::SyntaxHighlight->color( $code->source ) )
                                 a {  
                                         attr { href => '/run?code=' . $code->id, }, 'run'  
                                 },  
                                 pre { $code->source },  
                         }  
                 }  
32          }          }
33  };  };
34    
35    sub codepress {
36            my $codepress = 1;
37            $codepress = current_user->user_object->codepress if ( current_user->id );
38            return { render_as => 'Textarea' } unless ( $codepress );
39            return { render_as => 'Jifty::Plugin::CodePress::Textarea' };
40    }
41    
42  private template 'code_editor' => sub {  private template 'code_editor' => sub {
43          my $op = 'Create';          my $op = 'Create';
44          my $code = Perly::Model::Code->new();          my $code = Perly::Model::Code->new();
# Line 45  private template 'code_editor' => sub { Line 47  private template 'code_editor' => sub {
47                  warn "loaded ", length( $code->source ), " bytes";                  warn "loaded ", length( $code->source ), " bytes";
48                  $op = 'Update';                  $op = 'Update';
49          }          }
50    
51            warn "## editor: ", dump( codepress );
52    
53          form {          form {
54                  my $action = new_action( class => $op . 'Code', arguments => { $code ? $code->as_hash : undef } );                  my $action = new_action( class => $op . 'Code', arguments => { $code ? $code->as_hash : undef } );
55                  render_param( $action => 'name' );                  render_param( $action => 'name' );
56                  render_param( $action => 'source', cols => 80, rows => 25, language => 'perl', render_as => 'Jifty::Plugin::CodePress::Textarea' );                  render_param( $action => 'source', cols => 80, rows => 35, language => 'perl', render_as => codepress->{render_as} );
57                  #render_action( $action => [ 'source' => { cols => 80, rows => 30 }, ] );                  #render_action( $action => [ 'source' => { cols => 80, rows => 30 }, ] );
58                  form_submit(                  form_submit( label => _($op) );
59                          label => _($op),                  # IE problem http://support.microsoft.com/kb/281197
60                          onclick => [                  form_next_page( url => '/run/code=' . $action->argument_value('id') );
                                 { beforeclick => "CodePress.beforeSubmit();" },  
                         ],  
                 );  
61          }          }
62  };  };
63    
# Line 71  template '/upload' => page { Line 73  template '/upload' => page {
73  };  };
74    
75  template '/run' => page {  template '/run' => page {
76          my $action = new_action( class => 'Run', arguments => { input => get('input'), code => get('code') } );          my $action = new_action( class => 'Run' );
77          h1 { _("Run code on some input") },          h1 { _("Run code on some input") },
78          form {          form {
79                  render_action( $action => [ 'input', 'code' ] );                  render_param( $action => 'input', default_value => get('input') ),
80                    render_param( $action => 'code', default_value => get('code') ),
81                  form_submit(                  form_submit(
82                          label => _('Run'),                          label => _('Run'),
83                  );                  );
# Line 93  template '/run' => page { Line 96  template '/run' => page {
96          }          }
97  };  };
98    
99    template '/prefs' => page {
100            my $action = new_action( class => 'UpdateUser', arguments => { id => current_user->id } );
101            h1 { _("My preferences") },
102            form {
103                    render_action( $action => [ 'name', 'email', 'codepress' ] );
104                    form_submit(
105                            label => _('Save changes'),
106                    );
107            };
108    };
109    
110  1;  1;

Legend:
Removed from v.22  
changed lines
  Added in v.47

  ViewVC Help
Powered by ViewVC 1.1.26