/[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 4 by dpavlin, Sun Jun 3 22:49:47 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/;
10    
11  template '/' => page {  template '/' => page {
12            h1 { _("Available code") }
13            div { show 'code_list' }
14    };
15    
16    template '/edit' => page {
17          h1 { _("Enter your code") }          h1 { _("Enter your code") }
18          div { show 'code_editor' }          div { show 'code_editor' }
19  };  };
20    
21    private template 'code_list' => sub {
22            my $coll = Perly::Model::CodeCollection->new();
23            $coll->unlimit;
24            while ( my $code = $coll->next ) {
25                    div {
26                            { class is 'code-name' }
27                            hyperlink( url => '/edit/id=' . $code->id, label => $code->name ),
28                            small { length( $code->source ), ' bytes ', $code->created_on, ' ' },
29                            hyperlink( url => '/run/code=' . $code->id, label => 'run' ),
30                    };
31                    outs_raw( Perly::SyntaxHighlight->color( $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';
44            my $code = Perly::Model::Code->new();
45            if ( my $id = get 'id' ) {
46                    $code->load( $id ) or die "can't load $id";
47                    warn "loaded ", length( $code->source ), " bytes";
48                    $op = 'Update';
49            }
50    
51            warn "## editor: ", dump( codepress );
52    
53          form {          form {
54                  my $action = new_action( class => 'CreateCode' );                  my $action = new_action( class => $op . 'Code', arguments => { $code ? $code->as_hash : undef } );
55                  render_param( $action => 'source', cols => 80, rows => 25 );                  render_param( $action => 'name' );
56                    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( label => _($op) );
59                    # IE problem http://support.microsoft.com/kb/281197
60                    form_next_page( url => '/run/code=' . $action->argument_value('id') );
61            }
62    };
63    
64    template '/upload' => page {
65            h1 { _("Upload new file") },
66            form {
67                    my $action = new_action( class => 'Upload' );
68                    render_action( $action => [ 'filename', 'content', 'file', 'format' ] );
69                  form_submit(                  form_submit(
70                          label => _("Save my code"),                          label => _('Upload'),
                         onclick => [  
                                 { beforeclick => "CodePress.beforeSubmit();" },  
                         ],  
71                  );                  );
72          }          }
73  };  };
74    
75    template '/run' => page {
76            my $action = new_action( class => 'Run' );
77            h1 { _("Run code on some input") },
78            form {
79                    render_param( $action => 'input', default_value => get('input') ),
80                    render_param( $action => 'code', default_value => get('code') ),
81                    form_submit(
82                            label => _('Run'),
83                    );
84            };
85    
86            #warn dump( $action->result->content );
87    
88            if ( my $input = $action->result->content( 'input' ) ) {
89                    h2 { _("Input data") },
90                    pre { $input }
91            }
92    
93            if ( my $output = $action->result->content( 'output' ) ) {
94                    h2 { _("Output result") },
95                    pre { $output }
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.4  
changed lines
  Added in v.47

  ViewVC Help
Powered by ViewVC 1.1.26