/[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 40 by dpavlin, Sat Jun 9 23:18:08 2007 UTC
# Line 5  use warnings; Line 5  use warnings;
5    
6  use Jifty::View::Declare -base;  use Jifty::View::Declare -base;
7    
8    use Data::Dump qw/dump/;
9    
10  template '/' => page {  template '/' => page {
11            h1 { _("Available code") }
12            div { show 'code_list' }
13    };
14    
15    template '/edit' => page {
16          h1 { _("Enter your code") }          h1 { _("Enter your code") }
17          div { show 'code_editor' }          div { show 'code_editor' }
18  };  };
19    
20    private template 'code_list' => sub {
21            ul {
22                    my $coll = Perly::Model::CodeCollection->new();
23                    $coll->unlimit;
24                    while ( my $code = $coll->next ) {
25                            li {
26                                    a {
27                                            attr { href => '/edit/id=' . $code->id, },
28                                            $code->name,
29                                    },
30                                    small { length( $code->source ), ' bytes ', $code->created_on },
31                                    a {
32                                            attr { href => '/run/code=' . $code->id, }, 'run'
33                                    },
34                                    pre { $code->source },
35                            }
36                    }
37            }
38    };
39    
40    sub codepress {
41            my $codepress = 1;
42            $codepress = current_user->user_object->codepress if ( current_user->id );
43            return { render_as => 'Textarea' } unless ( $codepress );
44            return { render_as => 'Jifty::Plugin::CodePress::Textarea' };
45    }
46    
47  private template 'code_editor' => sub {  private template 'code_editor' => sub {
48            my $op = 'Create';
49            my $code = Perly::Model::Code->new();
50            if ( my $id = get 'id' ) {
51                    $code->load( $id ) or die "can't load $id";
52                    warn "loaded ", length( $code->source ), " bytes";
53                    $op = 'Update';
54            }
55    
56            warn "## editor: ", dump( codepress );
57    
58          form {          form {
59                  my $action = new_action( class => 'CreateCode' );                  my $action = new_action( class => $op . 'Code', arguments => { $code ? $code->as_hash : undef } );
60                  render_param( $action => 'source', cols => 80, rows => 25 );                  render_param( $action => 'name' );
61                    render_param( $action => 'source', cols => 80, rows => 25, language => 'perl', render_as => codepress->{render_as} );
62                  #render_action( $action => [ 'source' => { cols => 80, rows => 30 }, ] );                  #render_action( $action => [ 'source' => { cols => 80, rows => 30 }, ] );
63                    form_submit( label => _($op) );
64                    # IE problem http://support.microsoft.com/kb/281197
65                    form_next_page( url => '/run/code=' . $action->argument_value('id') );
66            }
67    };
68    
69    template '/upload' => page {
70            h1 { _("Upload new file") },
71            form {
72                    my $action = new_action( class => 'Upload' );
73                    render_action( $action => [ 'filename', 'content', 'file', 'format' ] );
74                  form_submit(                  form_submit(
75                          label => _("Save my code"),                          label => _('Upload'),
                         onclick => [  
                                 { beforeclick => "CodePress.beforeSubmit();" },  
                         ],  
76                  );                  );
77          }          }
78  };  };
79    
80    template '/run' => page {
81            my $action = new_action( class => 'Run' );
82            h1 { _("Run code on some input") },
83            form {
84                    render_param( $action => 'input', default_value => get('input') ),
85                    render_param( $action => 'code', default_value => get('code') ),
86                    form_submit(
87                            label => _('Run'),
88                    );
89            };
90    
91            #warn dump( $action->result->content );
92    
93            if ( my $input = $action->result->content( 'input' ) ) {
94                    h2 { _("Input data") },
95                    pre { $input }
96            }
97    
98            if ( my $output = $action->result->content( 'output' ) ) {
99                    h2 { _("Output result") },
100                    pre { $output }
101            }
102    };
103    
104    template '/prefs' => page {
105            my $action = new_action( class => 'UpdateUser', arguments => { id => current_user->id } );
106            h1 { _("My preferences") },
107            form {
108                    render_action( $action => [ 'name', 'email', 'codepress' ] );
109                    form_submit(
110                            label => _('Save changes'),
111                    );
112            };
113    };
114    
115  1;  1;

Legend:
Removed from v.4  
changed lines
  Added in v.40

  ViewVC Help
Powered by ViewVC 1.1.26