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

  ViewVC Help
Powered by ViewVC 1.1.26