/[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 3 by dpavlin, Sun Jun 3 15:34:30 2007 UTC revision 36 by dpavlin, Thu Jun 7 09:34:01 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    
45            return {
46                    render_as => 'Jifty::Plugin::CodePress::Textarea',
47                    submit => {
48                            onclick => [
49                                    { beforeclick => 'CodePress.beforeSubmit();'  },
50                            ],
51                    },
52            };
53    }
54    
55  private template 'code_editor' => sub {  private template 'code_editor' => sub {
56            my $op = 'Create';
57            my $code = Perly::Model::Code->new();
58            if ( my $id = get 'id' ) {
59                    $code->load( $id ) or die "can't load $id";
60                    warn "loaded ", length( $code->source ), " bytes";
61                    $op = 'Update';
62            }
63    
64            warn "## editor: ", dump( codepress );
65    
66          form {          form {
67                  my $action = new_action( class => 'CreateCode' );                  my $action = new_action( class => $op . 'Code', arguments => { $code ? $code->as_hash : undef } );
68                  render_param( $action => 'source', cols => 80, rows => 25 );                  render_param( $action => 'name' );
69                    render_param( $action => 'source', cols => 80, rows => 25, language => 'perl', render_as => codepress->{render_as} );
70                  #render_action( $action => [ 'source' => { cols => 80, rows => 30 }, ] );                  #render_action( $action => [ 'source' => { cols => 80, rows => 30 }, ] );
71                  form_submit( label => _("Save my code") );                  form_submit( label => _($op), %{ codepress->{submit} } );
72                    # IE problem http://support.microsoft.com/kb/281197
73                    form_next_page( url => '/run/code=' . $action->argument_value('id') );
74            }
75    };
76    
77    template '/upload' => page {
78            h1 { _("Upload new file") },
79            form {
80                    my $action = new_action( class => 'Upload' );
81                    render_action( $action => [ 'filename', 'content', 'file', 'format' ] );
82                    form_submit(
83                            label => _('Upload'),
84                    );
85            }
86    };
87    
88    template '/run' => page {
89            my $action = new_action( class => 'Run' );
90            h1 { _("Run code on some input") },
91            form {
92                    render_param( $action => 'input', default_value => get('input') ),
93                    render_param( $action => 'code', default_value => get('code') ),
94                    form_submit(
95                            label => _('Run'),
96                    );
97            };
98    
99            #warn dump( $action->result->content );
100    
101            if ( my $input = $action->result->content( 'input' ) ) {
102                    h2 { _("Input data") },
103                    pre { $input }
104            }
105    
106            if ( my $output = $action->result->content( 'output' ) ) {
107                    h2 { _("Output result") },
108                    pre { $output }
109          }          }
110  };  };
111    

Legend:
Removed from v.3  
changed lines
  Added in v.36

  ViewVC Help
Powered by ViewVC 1.1.26