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

Contents of /lib/Perly/View.pm

Parent Directory Parent Directory | Revision Log Revision Log


Revision 35 - (show annotations)
Thu Jun 7 09:19:27 2007 UTC (16 years, 11 months ago) by dpavlin
File size: 2543 byte(s)
refactor support for Textarea or CodePress
1 package Perly::View;
2
3 use strict;
4 use warnings;
5
6 use Jifty::View::Declare -base;
7
8 use Data::Dump qw/dump/;
9
10 template '/' => page {
11 h1 { _("Available code") }
12 div { show 'code_list' }
13 };
14
15 template '/edit' => page {
16 h1 { _("Enter your code") }
17 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 a {
32 attr { href => '/run/code=' . $code->id, }, 'run'
33 },
34 pre { $code->source },
35 }
36 }
37 }
38 };
39
40 sub codepress {
41 return { render_as => 'Textarea' };
42 return {
43 render_as => 'Jifty::Plugin::CodePress::Textarea',
44 submit => {
45 onclick => [
46 { beforeclick => 'CodePress.beforeSubmit();' },
47 ],
48 },
49 };
50 }
51
52 private template 'code_editor' => sub {
53 my $op = 'Create';
54 my $code = Perly::Model::Code->new();
55 if ( my $id = get 'id' ) {
56 $code->load( $id ) or die "can't load $id";
57 warn "loaded ", length( $code->source ), " bytes";
58 $op = 'Update';
59 }
60
61 warn "## editor: ", dump( codepress );
62
63 form {
64 my $action = new_action( class => $op . 'Code', arguments => { $code ? $code->as_hash : undef } );
65 render_param( $action => 'name' );
66 render_param( $action => 'source', cols => 80, rows => 25, language => 'perl', render_as => codepress->{render_as} );
67 #render_action( $action => [ 'source' => { cols => 80, rows => 30 }, ] );
68 form_submit( label => _($op), %{ codepress->{submit} } );
69 # IE problem http://support.microsoft.com/kb/281197
70 form_next_page( url => '/run/code=' . $action->argument_value('id') );
71 }
72 };
73
74 template '/upload' => page {
75 h1 { _("Upload new file") },
76 form {
77 my $action = new_action( class => 'Upload' );
78 render_action( $action => [ 'filename', 'content', 'file', 'format' ] );
79 form_submit(
80 label => _('Upload'),
81 );
82 }
83 };
84
85 template '/run' => page {
86 my $action = new_action( class => 'Run' );
87 h1 { _("Run code on some input") },
88 form {
89 render_param( $action => 'input', default_value => get('input') ),
90 render_param( $action => 'code', default_value => get('code') ),
91 form_submit(
92 label => _('Run'),
93 );
94 };
95
96 #warn dump( $action->result->content );
97
98 if ( my $input = $action->result->content( 'input' ) ) {
99 h2 { _("Input data") },
100 pre { $input }
101 }
102
103 if ( my $output = $action->result->content( 'output' ) ) {
104 h2 { _("Output result") },
105 pre { $output }
106 }
107 };
108
109 1;

  ViewVC Help
Powered by ViewVC 1.1.26