Skip Menu |

Preferred bug tracker

Please visit the preferred bug tracker to report your issue.

This queue is for tickets about the Rubric CPAN distribution.

Report information
The Basics
Id: 17553
Status: resolved
Priority: 0/
Queue: Rubric

People
Owner: rjbs [...] cpan.org
Requestors:
Cc:
AdminCc:

Bug Information
Severity: (no value)
Broken in: (no value)
Fixed in: (no value)



I wanted to add support for individual items to have an associated image. I haven't quite figured out a good way to display them, so, for now, I just dumped them right before the description. This does require a minor schema change. Also, the tests need to be updated for 2006.
=== lib/Rubric/DBI/Setup.pm ================================================================== --- lib/Rubric/DBI/Setup.pm (revision 27703) +++ lib/Rubric/DBI/Setup.pm (local) @@ -499,8 +499,58 @@ $dbh->do($_) for split /\n\n/, $sql; }; -$from{10} = undef; +$from{10} = sub { + my $sql = <<END_SQL; + CREATE TABLE new_entries ( + id integer PRIMARY KEY, + link integer, + user varchar NOT NULL, + title varchar NOT NULL, + created integer NOT NULL, + modified integer NOT NULL, + description varchar, + body TEXT, + img varchar + ); + INSERT INTO new_entries + SELECT id, link, user, title, created, modified, description, body + FROM entries; + + DROP TABLE entries; + + CREATE TABLE entries ( + id integer PRIMARY KEY, + link integer, + img varchar, + user varchar NOT NULL, + title varchar NOT NULL, + created integer NOT NULL, + modified integer NOT NULL, + description varchar, + body TEXT + ); + + INSERT INTO entries + SELECT id, link, img, user, title, created, modified, description, body + FROM new_entries; + + DROP TABLE new_entries; + + DROP TABLE rubric; + + CREATE TABLE rubric ( + schema_version integer NOT NULL + ); + + UPDATE rubric SET schema_version = 11; +END_SQL + + $dbh->do($_) for split /\n\n/, $sql; +}; + +$from{11} = undef; + sub update_schema { my ($class) = @_; while ($_ = $class->determine_version) { @@ -553,6 +603,7 @@ CREATE TABLE entries ( id integer PRIMARY KEY, link integer, + img varchar, user varchar NOT NULL, title varchar NOT NULL, created integer NOT NULL, @@ -565,7 +616,7 @@ id INTEGER PRIMARY KEY, entry integer NOT NULL, tag varchar NOT NULL, - tag_value varchar, + tag_value varchar, UNIQUE(entry, tag) ); @@ -573,4 +624,4 @@ schema_version integer NOT NULL ); -INSERT INTO rubric (schema_version) VALUES (10); +INSERT INTO rubric (schema_version) VALUES (11); === lib/Rubric/Entry/Query.pm ================================================================== --- lib/Rubric/Entry/Query.pm (revision 27703) +++ lib/Rubric/Entry/Query.pm (local) @@ -90,7 +90,7 @@ $code->($self, $value); } -=head2 get_entries(\@constraints) +=head2 get_entries(\@constraints, $order_by) Given a set of SQL constraints, this method builds the WHERE and ORDER BY clauses and performs a query with Class::DBI's C<retrieve_from_sql>. === lib/Rubric/Entry.pm ================================================================== --- lib/Rubric/Entry.pm (revision 27703) +++ lib/Rubric/Entry.pm (local) @@ -28,6 +28,7 @@ id - a unique identifier link - the link to which the entry refers + img - img url associated with the link user - the user who made the entry title - the title of the link's destination description - a short description of the entry @@ -38,7 +39,7 @@ =cut __PACKAGE__->columns( - All => qw(id link user title description body created modified) + All => qw(id link img user title description body created modified) ); =head1 RELATIONSHIPS === lib/Rubric/User.pm ================================================================== --- lib/Rubric/User.pm (revision 27703) +++ lib/Rubric/User.pm (local) @@ -215,6 +215,7 @@ : Rubric::Entry->create({ user => $self }); $new_entry->link($link); + $new_entry->img($entry->{img}); $new_entry->title($entry->{title}); $new_entry->description($entry->{description}); $new_entry->body($entry->{body} || undef); === lib/Rubric/WebApp.pm ================================================================== --- lib/Rubric/WebApp.pm (revision 27703) +++ lib/Rubric/WebApp.pm (local) @@ -865,24 +865,26 @@ my (%form, %error); $form{$_} = $self->query->param($_) - for qw(entryid uri title description tags body); + for qw(entryid img uri title description tags body); - for (qw(uri title description body tags)) { + for (qw(uri img title description body tags)) { eval { decode_utf8($form{$_}, Encode::FB_CROAK) }; $error{$_} = "Invalid UTF-8 characters in $_." if $@; } - eval { $form{uri} = URI->new($form{uri})->canonical; }; - $error{uri} = "Invalid URI" if $@; + for (qw(uri img)) { + eval { $form{$_} = URI->new($form{$_})->canonical; }; + $error{$_} = "Invalid URI" if $@; - if ( - $form{uri} - and not $error{uri} - and defined Rubric::Config->allowed_schemes - and not grep { $_ eq $form{uri}->scheme } @{ Rubric::Config->allowed_schemes } - ) { - $error{uri} = "Invalid URI; valid schemes are: " - . "@{ Rubric::Config->allowed_schemes }"; + if ( + $form{$_} + and not $error{$_} + and defined Rubric::Config->allowed_schemes + and not grep { $_ eq $form{$_}->scheme } @{ Rubric::Config->allowed_schemes } + ) { + $error{$_} = "Invalid URI; valid schemes are: " + . "@{ Rubric::Config->allowed_schemes }"; + } } eval { Rubric::Entry->tags_from_string($form{tags}) }; === t/10_dbsetup.t ================================================================== --- t/10_dbsetup.t (revision 27703) +++ t/10_dbsetup.t (local) @@ -11,6 +11,6 @@ ok(not($@), "set up empty rubric testing db"); -cmp_ok(Rubric::DBI::Setup->determine_version, '==', 10, "got current schema"); +cmp_ok(Rubric::DBI::Setup->determine_version, '==', 11, "got current schema"); -cmp_ok(Rubric::DBI::Setup->update_schema, '==', 10, "update (nop) to current"); +cmp_ok(Rubric::DBI::Setup->update_schema, '==', 11, "update (nop) to current"); === t/entry_query.t ================================================================== --- t/entry_query.t (revision 27703) +++ t/entry_query.t (local) @@ -9,8 +9,8 @@ user => Rubric::User->retrieve('eb'), tags => { 'news' => undef }, created_after => '2004-12-15', - created_on => '2005', - created_before=> '2006-01', + created_on => '2006', + created_before=> '2006-06', has_link => 1, has_body => 0 }); === templates/entries.rss ================================================================== --- templates/entries.rss (revision 27703) +++ templates/entries.rss (local) @@ -24,7 +24,7 @@ <item rdf:about="[% xml_escape(uri.entry(entry)) %]"> <title>[% xml_escape(entry.title) %]</title> <link>[% xml_escape(item) %]</link> - <description>[% IF entry.description %][% "<p><em>" _ entry.description _ "</em></p>" | html %][% END %][% entry.body | html_line_break | html %]</description> + <description>[% IF entry.img %][% "<img src='" _ entry.img _ "'/>" | html %][% END %][% IF entry.description %][% "<p><em>" _ entry.description _ "</em></p>" | html %][% END %][% entry.body | html_line_break | html %]</description> <dc:date>[% entry.created.datetime %]-05:00</dc:date> <dc:creator>[% entry.user %]</dc:creator> </item> === templates/entries.txt ================================================================== --- templates/entries.txt (revision 27703) +++ templates/entries.txt (local) @@ -2,6 +2,7 @@ [%- WHILE (entry = entries.next) -%] [% entry.title %] [% + maybe("img", entry.img ); maybe("link", entry.link ); maybe("desc", entry.description); maybe("body", entry.body ); === templates/entry.api ================================================================== --- templates/entry.api (revision 27703) +++ templates/entry.api (local) @@ -1,5 +1,6 @@ <entry uri='[% xml_escape(entry.link) %]' + img='[% xml_escape(entry.img) %]' title='[% xml_escape(entry.title) %]' user='[% entry.user %]' description='[% xml_escape(entry.description) %]' === templates/entry.html ================================================================== --- templates/entry.html (revision 27703) +++ templates/entry.html (local) @@ -16,6 +16,9 @@ [% END %] [% END %] </div> + [% IF entry.img %] + <img class='entry-img' src="[% xml_escape(entry.img) %]" alt=""/> + [% END %] [% IF entry.description %] <div class='description'>[% entry.description %]</div> [% END %] === templates/entry_long.html ================================================================== --- templates/entry_long.html (revision 27703) +++ templates/entry_long.html (local) @@ -12,6 +12,9 @@ <a href="[% uri.edit_entry(entry) %]?then_goto=[% self_url | uri %]">(edit)</a> [% END %] </h2> + [% IF entry.img %] + <img class='entry-img' src="[% xml_escape(entry.img) %]" alt=""/> + [% END %] [% IF entry.description %] <div class='description'>[% entry.description | html %]</div> [% END %] === templates/post.html ================================================================== --- templates/post.html (revision 27703) +++ templates/post.html (local) @@ -41,7 +41,7 @@ <form id='entryform' action="[% xml_escape(uri.post_entry) %]" method='POST'> <table> [%# Yup. This is really, really ugly. %] - [% FOREACH param = [ "uri", "title", "description", "tags" ] %] + [% FOREACH param = [ "uri", "img", "title", "description", "tags" ] %] [% IF param == "tags" %] [% accessor = "entrytags" %] [% ELSE %]
From: rjbs
On Thu Feb 09 11:39:13 2006, MAHEX wrote: Show quoted text
> I wanted to add support for individual items to have an associated > image. I haven't quite figured out a good way to display them, so, for > now, I just dumped them right before the description. This does require > a minor schema change.
Consider updating to svn Rubric: http://svn.codesimply.com/projects/rubric This version has pluggable entry formatters, which would allow you to specify an image within the body. Would that be sufficient? If not, consider writing this patch to add a table, (entryid PRIMARY KEY, img) with a might_have relationship. Show quoted text
> Also, the tests need to be updated for 2006.
Thanks. :) This problem was fixed a while ago in the trunk. Boy, was my face read. -- rjbs