/[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 8 by dpavlin, Tue Jun 5 11:32:42 2007 UTC revision 20 by dpavlin, Wed Jun 6 00:05:20 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                                    pre { $code->source },
32                            }
33                    }
34            }
35    };
36    
37  private template 'code_editor' => sub {  private template 'code_editor' => sub {
38            my $op = 'Create';
39            my $code = Perly::Model::Code->new();
40            if ( my $id = get 'id' ) {
41                    $code->load( $id ) or die "can't load $id";
42                    warn "loaded ", length( $code->source ), " bytes";
43                    $op = 'Update';
44            }
45          form {          form {
46                  my $action = new_action( class => 'CreateCode' );                  my $action = new_action( class => $op . 'Code', arguments => { $code ? $code->as_hash : undef } );
47                    render_param( $action => 'name' );
48                  render_param( $action => 'source', cols => 80, rows => 25, language => 'perl', render_as => 'Jifty::Plugin::CodePress::Textarea' );                  render_param( $action => 'source', cols => 80, rows => 25, language => 'perl', render_as => 'Jifty::Plugin::CodePress::Textarea' );
49                  #render_action( $action => [ 'source' => { cols => 80, rows => 30 }, ] );                  #render_action( $action => [ 'source' => { cols => 80, rows => 30 }, ] );
50                  form_submit(                  form_submit(
51                          label => _("Save my code"),                          label => _($op),
52                          onclick => [                          onclick => [
53                                  { beforeclick => "CodePress.beforeSubmit();" },                                  { beforeclick => "CodePress.beforeSubmit();" },
54                          ],                          ],
# Line 28  template '/upload' => page { Line 60  template '/upload' => page {
60          h1 { _("Upload new file") },          h1 { _("Upload new file") },
61          form {          form {
62                  my $action = new_action( class => 'Upload' );                  my $action = new_action( class => 'Upload' );
63                  render_action( $action => [ 'file', 'content' ] );                  render_action( $action => [ 'content', 'file', 'format' ] );
64                  form_submit(                  form_submit(
65                          label => _('Upload'),                          label => _('Upload'),
66                  );                  );
67          }          }
68  };  };
69    
70    template '/run' => page {
71            my $action = new_action( class => 'Run' );
72            h1 { _("Run code on some input") },
73            form {
74                    render_action( $action => [ 'input', 'code' ] );
75                    form_submit(
76                            label => _('Run'),
77                    );
78            };
79    
80            #warn dump( $action->result->content );
81    
82            if ( my $input = $action->result->content( 'input' ) ) {
83                    h2 { _("Input data") },
84                    pre { $input }
85            }
86    
87            if ( my $output = $action->result->content( 'output' ) ) {
88                    h2 { _("Output result") },
89                    pre { $output }
90            }
91    };
92    
93  1;  1;

Legend:
Removed from v.8  
changed lines
  Added in v.20

  ViewVC Help
Powered by ViewVC 1.1.26