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") } |
h1 { _("Available code") } |
12 |
div { show 'code_list' } |
div { show 'code_list' } |
28 |
$code->name, |
$code->name, |
29 |
}, |
}, |
30 |
small { length( $code->source ), ' bytes ', $code->created_on }, |
small { length( $code->source ), ' bytes ', $code->created_on }, |
31 |
|
a { |
32 |
|
attr { href => '/run?code=' . $code->id, }, 'run' |
33 |
|
}, |
34 |
pre { $code->source }, |
pre { $code->source }, |
35 |
} |
} |
36 |
} |
} |
38 |
}; |
}; |
39 |
|
|
40 |
private template 'code_editor' => sub { |
private template 'code_editor' => sub { |
|
my $content; |
|
41 |
my $op = 'Create'; |
my $op = 'Create'; |
42 |
my $id; |
my $code = Perly::Model::Code->new(); |
43 |
if ( $id = get 'id' ) { |
if ( my $id = get 'id' ) { |
|
my $code = Perly::Model::Code->new(); |
|
44 |
$code->load( $id ) or die "can't load $id"; |
$code->load( $id ) or die "can't load $id"; |
45 |
$content = $code->source; |
warn "loaded ", length( $code->source ), " bytes"; |
|
warn "loaded ", length( $content ), " bytes"; |
|
46 |
$op = 'Update'; |
$op = 'Update'; |
47 |
} |
} |
48 |
form { |
form { |
49 |
my $action = new_action( class => $op . 'Code', arguments => { id => $id, source => $content }, ); |
my $action = new_action( class => $op . 'Code', arguments => { $code ? $code->as_hash : undef } ); |
50 |
|
render_param( $action => 'name' ); |
51 |
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' ); |
52 |
#render_action( $action => [ 'source' => { cols => 80, rows => 30 }, ] ); |
#render_action( $action => [ 'source' => { cols => 80, rows => 30 }, ] ); |
53 |
form_submit( |
form_submit( |
63 |
h1 { _("Upload new file") }, |
h1 { _("Upload new file") }, |
64 |
form { |
form { |
65 |
my $action = new_action( class => 'Upload' ); |
my $action = new_action( class => 'Upload' ); |
66 |
render_action( $action => [ 'content', 'file', 'format' ] ); |
render_action( $action => [ 'filename', 'content', 'file', 'format' ] ); |
67 |
form_submit( |
form_submit( |
68 |
label => _('Upload'), |
label => _('Upload'), |
69 |
); |
); |
71 |
}; |
}; |
72 |
|
|
73 |
template '/run' => page { |
template '/run' => page { |
74 |
|
my $action = new_action( class => 'Run', arguments => { input => get('input'), code => get('code') } ); |
75 |
h1 { _("Run code on some input") }, |
h1 { _("Run code on some input") }, |
76 |
form { |
form { |
|
my $action = new_action( class => 'Run' ); |
|
77 |
render_action( $action => [ 'input', 'code' ] ); |
render_action( $action => [ 'input', 'code' ] ); |
78 |
form_submit( |
form_submit( |
79 |
label => _('Run'), |
label => _('Run'), |
80 |
); |
); |
81 |
|
}; |
82 |
|
|
83 |
|
#warn dump( $action->result->content ); |
84 |
|
|
85 |
|
if ( my $input = $action->result->content( 'input' ) ) { |
86 |
|
h2 { _("Input data") }, |
87 |
|
pre { $input } |
88 |
|
} |
89 |
|
|
90 |
|
if ( my $output = $action->result->content( 'output' ) ) { |
91 |
|
h2 { _("Output result") }, |
92 |
|
pre { $output } |
93 |
} |
} |
94 |
}; |
}; |
95 |
|
|