5 |
|
|
6 |
use Jifty::View::Declare -base; |
use Jifty::View::Declare -base; |
7 |
|
|
8 |
|
use Perly::SyntaxHighlight; |
9 |
use Data::Dump qw/dump/; |
use Data::Dump qw/dump/; |
10 |
|
|
11 |
template '/' => page { |
template '/' => page { |
32 |
a { |
a { |
33 |
attr { href => '/run/code=' . $code->id, }, 'run' |
attr { href => '/run/code=' . $code->id, }, 'run' |
34 |
}, |
}, |
35 |
pre { $code->source }, |
outs_raw( Perly::SyntaxHighlight->color( $code->source ) ) |
36 |
} |
} |
37 |
} |
} |
38 |
} |
} |
39 |
}; |
}; |
40 |
|
|
41 |
|
sub codepress { |
42 |
|
my $codepress = 1; |
43 |
|
$codepress = current_user->user_object->codepress if ( current_user->id ); |
44 |
|
return { render_as => 'Textarea' } unless ( $codepress ); |
45 |
|
return { render_as => 'Jifty::Plugin::CodePress::Textarea' }; |
46 |
|
} |
47 |
|
|
48 |
private template 'code_editor' => sub { |
private template 'code_editor' => sub { |
49 |
my $op = 'Create'; |
my $op = 'Create'; |
50 |
my $code = Perly::Model::Code->new(); |
my $code = Perly::Model::Code->new(); |
53 |
warn "loaded ", length( $code->source ), " bytes"; |
warn "loaded ", length( $code->source ), " bytes"; |
54 |
$op = 'Update'; |
$op = 'Update'; |
55 |
} |
} |
56 |
|
|
57 |
|
warn "## editor: ", dump( codepress ); |
58 |
|
|
59 |
form { |
form { |
60 |
my $action = new_action( class => $op . 'Code', arguments => { $code ? $code->as_hash : undef } ); |
my $action = new_action( class => $op . 'Code', arguments => { $code ? $code->as_hash : undef } ); |
61 |
render_param( $action => 'name' ); |
render_param( $action => 'name' ); |
62 |
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 => codepress->{render_as} ); |
63 |
#render_action( $action => [ 'source' => { cols => 80, rows => 30 }, ] ); |
#render_action( $action => [ 'source' => { cols => 80, rows => 30 }, ] ); |
64 |
form_submit( |
form_submit( label => _($op) ); |
65 |
label => _($op), |
# IE problem http://support.microsoft.com/kb/281197 |
|
onclick => [ |
|
|
{ beforeclick => "CodePress.beforeSubmit();" }, |
|
|
], |
|
|
); |
|
66 |
form_next_page( url => '/run/code=' . $action->argument_value('id') ); |
form_next_page( url => '/run/code=' . $action->argument_value('id') ); |
67 |
} |
} |
68 |
}; |
}; |
79 |
}; |
}; |
80 |
|
|
81 |
template '/run' => page { |
template '/run' => page { |
82 |
my $action = new_action( class => 'Run', arguments => { |
my $action = new_action( class => 'Run' ); |
|
input => get('input'), |
|
|
code => get('code'), |
|
|
} ); |
|
83 |
h1 { _("Run code on some input") }, |
h1 { _("Run code on some input") }, |
84 |
form { |
form { |
85 |
render_action( $action => [ 'input', 'code' ] ); |
render_param( $action => 'input', default_value => get('input') ), |
86 |
|
render_param( $action => 'code', default_value => get('code') ), |
87 |
form_submit( |
form_submit( |
88 |
label => _('Run'), |
label => _('Run'), |
89 |
); |
); |
102 |
} |
} |
103 |
}; |
}; |
104 |
|
|
105 |
|
template '/prefs' => page { |
106 |
|
my $action = new_action( class => 'UpdateUser', arguments => { id => current_user->id } ); |
107 |
|
h1 { _("My preferences") }, |
108 |
|
form { |
109 |
|
render_action( $action => [ 'name', 'email', 'codepress' ] ); |
110 |
|
form_submit( |
111 |
|
label => _('Save changes'), |
112 |
|
); |
113 |
|
}; |
114 |
|
}; |
115 |
|
|
116 |
1; |
1; |