/[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 34 - (hide annotations)
Wed Jun 6 22:07:12 2007 UTC (17 years ago) by dpavlin
File size: 2352 byte(s)
document IE bug
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 dpavlin 30 attr { href => '/edit/id=' . $code->id, },
28 dpavlin 12 $code->name,
29     },
30     small { length( $code->source ), ' bytes ', $code->created_on },
31 dpavlin 21 a {
32 dpavlin 30 attr { href => '/run/code=' . $code->id, }, 'run'
33 dpavlin 21 },
34 dpavlin 11 pre { $code->source },
35     }
36     }
37     }
38     };
39    
40 dpavlin 3 private template 'code_editor' => sub {
41 dpavlin 10 my $op = 'Create';
42 dpavlin 20 my $code = Perly::Model::Code->new();
43     if ( my $id = get 'id' ) {
44 dpavlin 10 $code->load( $id ) or die "can't load $id";
45 dpavlin 20 warn "loaded ", length( $code->source ), " bytes";
46 dpavlin 10 $op = 'Update';
47     }
48 dpavlin 3 form {
49 dpavlin 20 my $action = new_action( class => $op . 'Code', arguments => { $code ? $code->as_hash : undef } );
50     render_param( $action => 'name' );
51 dpavlin 6 render_param( $action => 'source', cols => 80, rows => 25, language => 'perl', render_as => 'Jifty::Plugin::CodePress::Textarea' );
52 dpavlin 3 #render_action( $action => [ 'source' => { cols => 80, rows => 30 }, ] );
53 dpavlin 4 form_submit(
54 dpavlin 10 label => _($op),
55 dpavlin 4 onclick => [
56     { beforeclick => "CodePress.beforeSubmit();" },
57     ],
58     );
59 dpavlin 34 # IE problem http://support.microsoft.com/kb/281197
60 dpavlin 30 form_next_page( url => '/run/code=' . $action->argument_value('id') );
61 dpavlin 3 }
62     };
63    
64 dpavlin 8 template '/upload' => page {
65     h1 { _("Upload new file") },
66     form {
67     my $action = new_action( class => 'Upload' );
68 dpavlin 22 render_action( $action => [ 'filename', 'content', 'file', 'format' ] );
69 dpavlin 8 form_submit(
70     label => _('Upload'),
71     );
72     }
73     };
74    
75 dpavlin 14 template '/run' => page {
76 dpavlin 33 my $action = new_action( class => 'Run' );
77 dpavlin 14 h1 { _("Run code on some input") },
78     form {
79 dpavlin 33 render_param( $action => 'input', default_value => get('input') ),
80     render_param( $action => 'code', default_value => get('code') ),
81 dpavlin 14 form_submit(
82     label => _('Run'),
83     );
84 dpavlin 15 };
85 dpavlin 17
86     #warn dump( $action->result->content );
87    
88     if ( my $input = $action->result->content( 'input' ) ) {
89     h2 { _("Input data") },
90     pre { $input }
91 dpavlin 14 }
92 dpavlin 17
93     if ( my $output = $action->result->content( 'output' ) ) {
94     h2 { _("Output result") },
95     pre { $output }
96     }
97 dpavlin 14 };
98    
99 dpavlin 3 1;

  ViewVC Help
Powered by ViewVC 1.1.26