Changeset 8
- Timestamp:
- 05/16/05 20:35:29 (3 years ago)
- Files:
-
- trunk/Build.PL (modified) (1 diff)
- trunk/lib/Scrpbk.pm (modified) (1 diff)
- trunk/lib/Scrpbk/C/Scrap.pm (modified) (2 diffs)
- trunk/lib/Scrpbk/M/Scrap.pm (modified) (1 diff)
- trunk/misc/sql/0001.sql (added)
- trunk/root/base/main.css (modified) (1 diff)
- trunk/root/base/menu/person (modified) (1 diff)
- trunk/root/base/scrap/edit (modified) (2 diffs)
- trunk/root/base/scrap/line (modified) (2 diffs)
- trunk/t/c/scrap.t (modified) (3 diffs)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
trunk/Build.PL
r2 r8 16 16 'File::Spec' => 0, 17 17 'FindBin' => 0, 18 'HTML::Entities' => 0, 18 19 'Getopt::Long' => 0, 19 20 'Mail::Mailer' => 0, trunk/lib/Scrpbk.pm
r6 r8 18 18 Scrpbk->setup; 19 19 20 { # Check that the correct db version is being used. 21 my $dbh = Scrpbk::M::DBI::db_Main(); 22 my ($db_version) = $dbh->selectrow_array("select scrpbk_db_version(1)"); 23 $db_version ||= 0; 24 die "Wrong database version: have '$db_version', need '$VERSION'" 25 unless $db_version == $VERSION; 26 } 27 20 28 # If we are testing turn on debugging. 21 # sub debug { $yaml_config->{setting} eq 'testing' ? 1 : 0 };29 #sub debug { $yaml_config->{setting} eq 'testing' ? 1 : 0 }; 22 30 23 31 sub begin : Private { trunk/lib/Scrpbk/C/Scrap.pm
r5 r8 176 176 177 177 # Get and tidy the values. 178 my $name = $c->req->param('name') || ''; 179 my $note = $c->req->param('note') || ''; 180 my $url = $c->req->param('url') || ''; 181 $name =~ s/^\s*(.*)\s*$/$1/; 182 $note =~ s/^\s*(.*)\s*$/$1/; 183 $url =~ s/^\s*(.*)\s*$/$1/; 184 178 my $content = $c->req->param('content') || ''; 179 $content =~ s/^\s*(.*)\s*$/$1/; 180 181 # If there is no content maybe it is a bookmark post. 182 unless ( $content ) { 183 my $name = $c->req->param('name') || ''; 184 my $url = $c->req->param('url') || ''; 185 $name =~ s/^\s*(.*)\s*$/$1/; 186 $url =~ s/^\s*(.*)\s*$/$1/; 187 188 $content = "**${name}**: " if $name; 189 $content .= "[$url]" if $url; 190 } 191 192 # Put the content on the stash. 193 $c->stash->{new} = { content => $content }; 194 195 # Validate the inputs. 185 196 my @messages = (); 186 187 # Validate the inputs. 188 push @messages, "The name is too long, must be no more than than 40 chars" 189 if length($name) > 40; 190 push @messages, "The name is too short, must be at least 1 char" 191 if length($name) < 1; 192 push @messages, "The note is too long, must be no more than than 1000 chars" 193 if length($note) > 1000; 194 push @messages, "The url is too long, must be no more than than 500 chars" 195 if length($url) > 500; 197 push @messages, "The content is too long, must be no more than than 10,000 chars" 198 if length($content) > 10_000; 199 push @messages, "The content must have something in it." 200 if length($content) == 0; 196 201 197 202 # Return if errors found. 198 203 if ( scalar @messages ) { 199 204 $c->stash->{messages} = \@messages; 200 $c->stash->{new} = {201 name => $name,202 note => $note,203 url => $url204 };205 205 return 1; 206 } 207 208 # Do we want to just do a preview? 209 if ( $c->req->param('preview') ) { 210 $c->stash->{preview} = 211 Scrpbk::M::Scrap::html_format( $content ); 212 return 1; 206 213 } 207 214 208 215 # Update or create the scrap. 209 216 if ($scrap) { 210 $scrap->set( name => $name, note => $note, url => $url);217 $scrap->set( content => $content ); 211 218 $scrap->update; 212 219 } … … 214 221 $scrap = 215 222 Scrpbk::M::Scrap->create( 216 { person => $person, name => $name, note => $note, url => $url} );223 { person => $person, content => $content } ); 217 224 } 218 225 trunk/lib/Scrpbk/M/Scrap.pm
r2 r8 3 3 use strict; 4 4 use base 'Scrpbk::M::DBI'; 5 use HTML::Entities; 5 6 6 7 __PACKAGE__->table('scraps'); 7 8 8 __PACKAGE__->columns( All => qw( id person holder rank name url note) );9 __PACKAGE__->columns( All => qw( id person holder rank content ) ); 9 10 10 11 __PACKAGE__->has_a( person => 'Scrpbk::M::Person' ); 11 12 __PACKAGE__->has_a( holder => 'Scrpbk::M::Holder' ); 12 13 13 =head1 NAME 14 sub html { 15 my $self = shift; 14 16 15 Scrpbk::M::Person - A Component 17 return html_format( $self->content ); 18 } 16 19 17 =head1 SYNOPSIS 20 my %HTML_FORMATS = ( 21 '__' => 'u', 22 '--' => 'strike', 23 '//' => 'i', 24 '**' => 'b', 25 ); 18 26 19 Very simple to use 27 my $HTML_REGEX = join '|', map { quotemeta } keys %HTML_FORMATS; 20 28 21 =head1 DESCRIPTION 29 sub html_format { 30 my $input = shift; 31 return '' unless defined $input && length $input; 22 32 23 Very nice component. 33 # Send it all through a htmler to get rid of bad chars. 34 my $encoded_input = encode_entities( $input ); 24 35 25 =head1 AUTHOR 36 # Turn new lines into '<br />'s. 37 $encoded_input =~ s/\n/\<br \/\>/g; 26 38 27 A clever guy 39 # Split it all into blocks to process. 40 my @blocks = split /(\[[^\]]+\]|$HTML_REGEX)/, $encoded_input; 28 41 29 =head1 LICENSE 42 # Output and tag_tracker. 43 my $output = ''; 44 my %tag_tracker = (); 30 45 31 This library is free software . You can redistribute it and/or modify 32 it under the same terms as perl itself. 46 # Process the blocks. 47 foreach my $chunk ( @blocks ) { 33 48 34 =cut 49 # Is it a HTML_FORMAT? 50 if ( $HTML_FORMATS{ $chunk } ) { 51 52 my $tag = $HTML_FORMATS{ $chunk }; 53 my $is_stop = $tag_tracker{ $tag } ? '/' : ''; 54 55 $tag_tracker{ $tag } = ! $tag_tracker{ $tag }; 56 $output .= "<$is_stop$tag>"; 57 } 58 59 # Is it a link? 60 elsif ( $chunk =~ m/^\[(.+)\]$/ ) { 61 62 # trim off the leading and trailing []. 63 my $input = $1; 64 65 # Split the url and name. 66 my ($url, $name) = split /\|/, $input, 2; 67 $name = $url unless defined $name && length $name; 68 69 $output .= "<a href=\"$url\" title=\"$url\">$name</a>"; 70 } 71 72 # Anything else. 73 else { 74 $output .= $chunk; 75 } 76 } 77 78 # Close any open tags. 79 foreach my $tag ( keys %tag_tracker ) { 80 next unless $tag_tracker{ $tag }; 81 $output .= "</$tag>"; 82 } 83 84 return $output; 85 } 35 86 36 87 1; trunk/root/base/main.css
r2 r8 23 23 font-size: 80%; 24 24 color: #888888; 25 text-align: left;26 25 } 27 26 28 27 .instruction:hover { 29 color: #444444; 28 color: black; 29 background: #dddddd; 30 30 } 31 31 trunk/root/base/menu/person
r2 r8 22 22 <input type="hidden" name="form_submitted" value="1"> 23 23 <tr> 24 <td align=right>name:</td> 25 <td><input type="text" name="name" size="12"></td> 26 24 <td class="instruction"> 25 <center> 26 __underline text__<br> 27 **bold text**<br> 28 //italic text//<br> 29 [http://link.com|optional name] 30 <center> 31 </td> 27 32 </tr><tr> 28 <td align=right>note:</td> 29 <td><textarea name="note" cols="12" rows="3"></textarea></td> 30 33 <td><textarea name="content" cols="20" rows="3"></textarea></td> 31 34 </tr><tr> 32 <td align=right>url:</td> 33 <td><input type="text" name="url" value="http://" size="12"></td> 34 35 </tr><tr> 36 <td colspan="2"> 35 <td> 37 36 <center> 38 37 <input type="submit" value="Add scrap"> trunk/root/base/scrap/edit
r2 r8 6 6 7 7 <td width="80%"> 8 9 [% IF preview %] 10 [% WRAPPER 'plain_table' title = 'Preview' %] 11 [% preview %] 12 [% END %] 13 [% END %] 8 14 9 15 [% WRAPPER 'plain_table' title = head.title %] … … 17 23 <tr> 18 24 19 <td align="right">name:</td> 20 <td><input type="text" name="name" size=60 value="[% new.name || scrap.name | html %]"></td> 25 <td> 26 <textarea name="content" cols=50 rows=20>[% new.content || scrap.content | html %]</textarea> 27 </td> 28 <td class="instruction"> 21 29 30 <p>If you want to format part of the text surround it with the following tags:</p> 31 32 <table> 33 <tr> 34 <td align="right"><b>bold text</b>:</td> 35 <td><tt>**bold text**</tt></td> 36 </tr><tr> 37 <td align="right"><u>underlined text</u>:</td> 38 <td><tt>__underlined text__</tt></td> 39 </tr><tr> 40 <td align="right"><i>italic text</i>:</td> 41 <td><tt>//italic text//</tt></td> 42 </tr><tr> 43 <td align="right"><strike>crossed out text</strike>:</td> 44 <td><tt>--crossed out text--</tt></td> 45 </tr> 46 </table> 47 48 <hr /> 49 50 <p>You can create links by enclosing the URL in square brackets. You 51 can name a link by putting the name after the URL, separating the two 52 with a bar '|'. 53 54 <table> 55 <tr> 56 <td align="right"><tt>[http://google.com]</tt>:</td> 57 <td><a href="http://google.com" title="http://google.com">http://google.com</a></td> 58 </tr><tr> 59 <td align="right"><tt>[http://google.com|Google]</tt>:</td> 60 <td><a href="http://google.com" title="http://google.com">Google</a></td> 61 </tr> 62 </table> 63 <hr /> 64 65 <table> 66 <tr> 67 <td align="right">This:</td> 68 <td><tt>This **important** --scarp-- scrap links to [http://google.com|Google] //(a search engine)//.</tt></td> 69 </tr><tr> 70 <td align="right">Gives:</td> 71 <td>This <b>important</b> <strike>scarp</strike> scrap links to <a href="http://google.com" title="http://google.com">Google</a> <i>(a search engine)</i>.</tt></td> 72 </tr> 73 </table> 74 75 76 </td> 22 77 <tr></tr> 23 78 24 <td align="right">note:</td> 25 <td><textarea name="note" cols=60 rows=10>[% new.note || scrap.note | html %]</textarea></td> 26 27 <tr></tr> 28 29 <td align="right">url:</td> 30 <td><input type="text" name="url" size=60 value="[% new.url || scrap.url | html %]"></td> 31 32 <tr></tr> 33 34 <td> </td> 35 <td><input type="submit" value="Change Scrap"></td> 36 79 <td> 80 <input type="submit" name="preview" value="Preview"> 81 <input type="submit" name="submit" value="Change Scrap"> 82 </td> 83 <td> </td> 37 84 </tr> 38 85 </table> trunk/root/base/scrap/line
r2 r8 1 [% IF scrap.name %]<b>[% scrap.name | html %]</b>[% END %] 2 3 [% scrap.note | html %] 4 5 [% IF scrap.url %] 6 <nobr> 7 <tt><a href="[% scrap.url %]">[% scrap.url.replace( '^http://','' ) | truncate(40) %]</a></tt> 8 <a href="[% scrap.url %]" target="_blank" ><img src="/i/new_window.gif" 9 border="0" 10 onmouseover="this.src='/i/new_window_col.gif'" 11 onmouseout ="this.src='/i/new_window.gif'"></a> 12 </nobr> 13 [% END %] 1 [% scrap.html %] 14 2 15 3 [% IF target.id == person.id %] … … 26 14 <input type="radio" name="scrap" value="[% scrap.id %]"> 27 15 [% END %] 28 29 30 31 16 <br> trunk/t/c/scrap.t
r5 r8 38 38 form_name => 'add_scrap', 39 39 fields => { 40 name => "Test Scrap $_", 41 note => 'This is a note on the scrap', 42 url => 'http://examle.com/', 40 content => "$_: **Test Scrap $_** - This is a scrap: [http://examle.com/]" 43 41 } 44 42 ), … … 51 49 { 52 50 for ( 1 .. 3 ) { 53 my $name = "Test Scrap $_"; 54 ok $scraps{$_} = Scrpbk::M::Scrap->retrieve( 55 person => $test_user, 56 name => $name 57 ), 58 "load the scrap '$name'"; 51 my $content = "**Test Scrap $_**"; 52 my @results = Scrpbk::M::Scrap->search_like 53 ( person => $test_user, 54 content => $_ . '%' 55 ); 56 $scraps{$_} = $results[0]; 57 ok $scraps{$_}, "load the scrap '$content'"; 59 58 } 60 59 } … … 70 69 for ( keys %scraps ) { 71 70 next unless $scraps{$_}; 72 my $ name = $scraps{$_}->name;73 ok $scraps{$_}->delete, "deleting scrap '$ name'";71 my $id = $scraps{$_}->id; 72 ok $scraps{$_}->delete, "deleting scrap '$id'"; 74 73 } 75 74
