/[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

Annotation of /lib/Perly/View.pm

Parent Directory Parent Directory | Revision Log Revision Log


Revision 20 - (hide annotations)
Wed Jun 6 00:05:20 2007 UTC (16 years, 11 months ago) by dpavlin
File size: 2058 byte(s)
edit filename also and simplify code
1 dpavlin 3 package Perly::View;
2    
3     use strict;
4     use warnings;
5    
6     use Jifty::View::Declare -base;
7    
8 dpavlin 15 use Data::Dump qw/dump/;
9    
10 dpavlin 3 template '/' => page {
11 dpavlin 11 h1 { _("Available code") }
12     div { show 'code_list' }
13     };
14    
15     template '/edit' => page {
16 dpavlin 3 h1 { _("Enter your code") }
17     div { show 'code_editor' }
18     };
19    
20 dpavlin 11 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 dpavlin 12 $code->name,
29     },
30     small { length( $code->source ), ' bytes ', $code->created_on },
31 dpavlin 11 pre { $code->source },
32     }
33     }
34     }
35     };
36    
37 dpavlin 3 private template 'code_editor' => sub {
38 dpavlin 10 my $op = 'Create';
39 dpavlin 20 my $code = Perly::Model::Code->new();
40     if ( my $id = get 'id' ) {
41 dpavlin 10 $code->load( $id ) or die "can't load $id";
42 dpavlin 20 warn "loaded ", length( $code->source ), " bytes";
43 dpavlin 10 $op = 'Update';
44     }
45 dpavlin 3 form {
46 dpavlin 20 my $action = new_action( class => $op . 'Code', arguments => { $code ? $code->as_hash : undef } );
47     render_param( $action => 'name' );
48 dpavlin 6 render_param( $action => 'source', cols => 80, rows => 25, language => 'perl', render_as => 'Jifty::Plugin::CodePress::Textarea' );
49 dpavlin 3 #render_action( $action => [ 'source' => { cols => 80, rows => 30 }, ] );
50 dpavlin 4 form_submit(
51 dpavlin 10 label => _($op),
52 dpavlin 4 onclick => [
53     { beforeclick => "CodePress.beforeSubmit();" },
54     ],
55     );
56 dpavlin 3 }
57     };
58    
59 dpavlin 8 template '/upload' => page {
60     h1 { _("Upload new file") },
61     form {
62     my $action = new_action( class => 'Upload' );
63 dpavlin 9 render_action( $action => [ 'content', 'file', 'format' ] );
64 dpavlin 8 form_submit(
65     label => _('Upload'),
66     );
67     }
68     };
69    
70 dpavlin 14 template '/run' => page {
71 dpavlin 15 my $action = new_action( class => 'Run' );
72 dpavlin 14 h1 { _("Run code on some input") },
73     form {
74     render_action( $action => [ 'input', 'code' ] );
75     form_submit(
76     label => _('Run'),
77     );
78 dpavlin 15 };
79 dpavlin 17
80     #warn dump( $action->result->content );
81    
82     if ( my $input = $action->result->content( 'input' ) ) {
83     h2 { _("Input data") },
84     pre { $input }
85 dpavlin 14 }
86 dpavlin 17
87     if ( my $output = $action->result->content( 'output' ) ) {
88     h2 { _("Output result") },
89     pre { $output }
90     }
91 dpavlin 14 };
92    
93 dpavlin 3 1;

  ViewVC Help
Powered by ViewVC 1.1.26