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

  ViewVC Help
Powered by ViewVC 1.1.26