Changeset 8

Show
Ignore:
Timestamp:
05/16/05 20:35:29 (3 years ago)
Author:
evdb
Message:

Changed: scraps now just content, not name note and url.

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/Build.PL

    r2 r8  
    1616        'File::Spec'           => 0, 
    1717        'FindBin'              => 0, 
     18        'HTML::Entities'       => 0, 
    1819        'Getopt::Long'         => 0, 
    1920        'Mail::Mailer'         => 0, 
  • trunk/lib/Scrpbk.pm

    r6 r8  
    1818Scrpbk->setup; 
    1919 
     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 
    2028# 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 }; 
    2230 
    2331sub begin : Private { 
  • trunk/lib/Scrpbk/C/Scrap.pm

    r5 r8  
    176176 
    177177    # 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. 
    185196    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; 
    196201 
    197202    # Return if errors found. 
    198203    if ( scalar @messages ) { 
    199204        $c->stash->{messages} = \@messages; 
    200         $c->stash->{new}      = { 
    201             name => $name, 
    202             note => $note, 
    203             url  => $url 
    204         }; 
    205205        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; 
    206213    } 
    207214 
    208215    # Update or create the scrap. 
    209216    if ($scrap) { 
    210         $scrap->set( name => $name, note => $note, url => $url ); 
     217        $scrap->set( content => $content ); 
    211218        $scrap->update; 
    212219    } 
     
    214221        $scrap = 
    215222          Scrpbk::M::Scrap->create( 
    216             { person => $person, name => $name, note => $note, url => $url } ); 
     223            { person => $person, content => $content } ); 
    217224    } 
    218225 
  • trunk/lib/Scrpbk/M/Scrap.pm

    r2 r8  
    33use strict; 
    44use base 'Scrpbk::M::DBI'; 
     5use HTML::Entities; 
    56 
    67__PACKAGE__->table('scraps'); 
    78 
    8 __PACKAGE__->columns( All => qw( id person holder rank name url note ) ); 
     9__PACKAGE__->columns( All => qw( id person holder rank content ) ); 
    910 
    1011__PACKAGE__->has_a( person => 'Scrpbk::M::Person' ); 
    1112__PACKAGE__->has_a( holder => 'Scrpbk::M::Holder' ); 
    1213 
    13 =head1 NAME 
     14sub html { 
     15    my $self = shift; 
    1416 
    15 Scrpbk::M::Person - A Component 
     17    return html_format( $self->content ); 
     18
    1619 
    17 =head1 SYNOPSIS 
     20my %HTML_FORMATS = ( 
     21                    '__' => 'u', 
     22                    '--' => 'strike', 
     23                    '//' => 'i', 
     24                    '**' => 'b', 
     25                    ); 
    1826 
    19     Very simple to use 
     27my $HTML_REGEX = join '|', map { quotemeta } keys %HTML_FORMATS; 
    2028 
    21 =head1 DESCRIPTION 
     29sub html_format { 
     30    my $input = shift; 
     31    return '' unless defined $input && length $input; 
    2232 
    23 Very nice component. 
     33    # Send it all through a htmler to get rid of bad chars. 
     34    my $encoded_input = encode_entities( $input ); 
    2435 
    25 =head1 AUTHOR 
     36    # Turn new lines into '<br />'s. 
     37    $encoded_input =~ s/\n/\<br \/\>/g; 
    2638 
    27 A clever guy 
     39    # Split it all into blocks to process. 
     40    my @blocks = split /(\[[^\]]+\]|$HTML_REGEX)/, $encoded_input; 
    2841 
    29 =head1 LICENSE 
     42    # Output and tag_tracker. 
     43    my $output = ''; 
     44    my %tag_tracker = (); 
    3045 
    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 ) { 
    3348 
    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
    3586 
    36871; 
  • trunk/root/base/main.css

    r2 r8  
    2323  font-size: 80%; 
    2424  color: #888888; 
    25   text-align: left; 
    2625} 
    2726 
    2827.instruction:hover { 
    29   color: #444444; 
     28  color: black; 
     29  background: #dddddd; 
    3030} 
    3131 
  • trunk/root/base/menu/person

    r2 r8  
    2222<input type="hidden" name="form_submitted" value="1"> 
    2323  <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> 
    2732  </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> 
    3134  </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> 
    3736      <center> 
    3837        <input type="submit" value="Add scrap"> 
  • trunk/root/base/scrap/edit

    r2 r8  
    66 
    77    <td width="80%"> 
     8 
     9[% IF preview %] 
     10  [% WRAPPER 'plain_table' title = 'Preview' %] 
     11    [% preview %] 
     12  [% END %] 
     13[% END %] 
    814 
    915[% WRAPPER 'plain_table' title = head.title %] 
     
    1723  <tr> 
    1824 
    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"> 
    2129 
     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 
     51can name a link by putting the name after the URL, separating the two 
     52with 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> 
    2277  <tr></tr> 
    2378 
    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>&nbsp;</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>&nbsp</td> 
    3784  </tr> 
    3885</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 %] 
    142 
    153[% IF target.id == person.id %] 
     
    2614<input type="radio" name="scrap" value="[% scrap.id %]"> 
    2715[% END %] 
    28  
    29  
    30  
    3116<br> 
  • trunk/t/c/scrap.t

    r5 r8  
    3838        form_name => 'add_scrap', 
    3939        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/]" 
    4341        } 
    4442      ), 
     
    5149{ 
    5250    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'"; 
    5958    } 
    6059} 
     
    7069for ( keys %scraps ) { 
    7170    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'"; 
    7473} 
    7574