On 7/26/05, William Morgan <[EMAIL PROTECTED]> wrote:
> Leon, would you be interested in tweaking your patch in this manner?
Sure, I've attached a modified version of my patch.

I'm playing around with the idea of making comments/trackbacks their
own type, comments (pardon the redundancy)?

Why would I want to do such a thing? I don't see a comment as a
full-fledged entry, more like an "entry-lite". One thing that a
comment often has is an origin url field ("link" is not persisted to
YAML because its a generated field and doesn't quite match in meaning
anyway). I'd also like to store the IP of the comment/trackback
source.

Lastly, splitting up the comment/trackback ERB into header/body/footer
will make it a tad more digestible from one's own templates. For
example, I don't see myself wanting to muck much with the comment
entry form, but I'd definitely want to tweak styles based on the type
of comment, I'm not comfortable with the part of my patch that embeds
the value of Entry#link in "content", but as I didn't have a
persistable field I could rely on, I did that, but its not going to
fly if people have other ways they want to render trackbacks.

Thoughts?

Leon
diff -x hobix.rb -x CVS -x webapp.rb -uNr hobix/lib/hobix/facets/comments.rb hobix.ljb/lib/hobix/facets/comments.rb
--- hobix/lib/hobix/facets/comments.rb	Sun Jul 24 02:10:34 2005
+++ hobix.ljb/lib/hobix/facets/comments.rb	Tue Jul 26 08:47:16 2005
@@ -52,11 +52,9 @@
                     end
                     c.created = Time.now
                 end
-                comments = @weblog.storage.load_attached( entry_id, 'comments' ) rescue []
-                comments << comment
 
-                # Save the attachment, upgen
-                @weblog.storage.save_attached( entry_id, "comments", comments )
+                # Save the comment, upgen
+                @weblog.append_to_attachment( entry_id, 'comments', comment )
                 @weblog.regenerate :update
 
                 # Redirect
diff -x hobix.rb -x CVS -x webapp.rb -uNr hobix/lib/hobix/facets/trackbacks.rb hobix.ljb/lib/hobix/facets/trackbacks.rb
--- hobix/lib/hobix/facets/trackbacks.rb	Thu Jan  1 01:00:00 1970
+++ hobix.ljb/lib/hobix/facets/trackbacks.rb	Tue Jul 26 08:47:56 2005
@@ -0,0 +1,88 @@
+#
+# = hobix/facets/trackbacks.rb
+#
+# Hobix command-line weblog system, support for trackbacks.
+#
+# Copyright (c) 2003-2004 why the lucky stiff
+#
+# Written & maintained by why the lucky stiff <[EMAIL PROTECTED]>
+#
+# This program is free software, released under a BSD license.
+# See COPYING for details.
+#
+#--
+# $Id$
+#++
+
+require 'hobix/entry'
+
+module Hobix
+module Facets
+
+# The Trackbacks plugin adds support for the TrackBack specification
+# (http://www.sixapart.com/pronet/docs/trackback_spec).
+#
+# Add this require to your hobix.yaml:
+#
+#   requires:
+#   - hobix/trackbacks
+#
+class Trackbacks < BaseFacet
+    FieldMap = {
+      'blog_name' => 'author',
+      'url'       => 'link',
+      'title'     => 'title',
+      'excerpt'   => 'content'
+    }
+
+    def self.trackback_fields; ['url','title', 'excerpt', 'blog_name']; end
+    def self.entry_field(name); FieldMap[name]; end
+    def self.trackback_class; Hobix::Entry; end
+
+    def initialize( weblog, defaults = {} )
+        @weblog = weblog
+    end
+    def get app
+        if app.respond_to? :action_uri
+            action, entry_id = app.action_uri.split( '/', 2 )
+            case action
+            when "trackback"
+                # Validate
+                on_entry = @weblog.storage.load_entry( entry_id ) rescue nil
+                return send_trackback_response( app, false, 'No such entry' ) if on_entry.nil?
+
+                # Create a trackback comment
+                trackback = Trackbacks.trackback_class.new do |t|
+                    Trackbacks.trackback_fields.each do |tf|
+                      t.method( "#{ Trackbacks.entry_field(tf) }=" ).call( app._POST[tf].to_s )
+                    end
+                    return send_trackback_response( app, false, 'Missing URL field' ) if t.link.strip.empty?
+                    t.content = %{"#{t.title}":#{t.link}\n\n#{t.content}}
+                    t.created = Time.now
+                end
+
+                # Save the trackback, upgen
+                @weblog.append_to_attachment( entry_id, 'comments', trackback )
+                @weblog.regenerate :update
+
+                # Send response
+                send_trackback_response( app, true )
+                return true
+            end
+        end
+    end
+
+    def send_trackback_response(app, ok = true, message = nil)
+      app.content_type = 'text/xml'
+      app.puts %{<?xml version="1.0" encoding="UTF-8"?>
+        <response>
+          <error>%d</error>
+          %s
+        </response>
+      } % [ok ? 0 : 1, message ? %{<message>#{message}</message>} : '']
+      true
+    end
+end
+
+end
+end
diff -x hobix.rb -x CVS -x webapp.rb -uNr hobix/lib/hobix/trackbacks.rb hobix.ljb/lib/hobix/trackbacks.rb
--- hobix/lib/hobix/trackbacks.rb	Thu Jan  1 01:00:00 1970
+++ hobix.ljb/lib/hobix/trackbacks.rb	Sun Jul 24 06:43:29 2005
@@ -0,0 +1,17 @@
+#
+# = hobix/trackbacks.rb
+#
+# Hobix command-line weblog system, API for trackbacks.
+#
+# Copyright (c) 2003-2004 why the lucky stiff
+#
+# Written & maintained by why the lucky stiff <[EMAIL PROTECTED]>
+#
+# This program is free software, released under a BSD license.
+# See COPYING for details.
+#
+#--
+# $Id$
+#++
+
+require 'hobix/facets/trackbacks'
diff -x hobix.rb -x CVS -x webapp.rb -uNr hobix/lib/hobix/weblog.rb hobix.ljb/lib/hobix/weblog.rb
--- hobix/lib/hobix/weblog.rb	Sat Jul 23 19:19:55 2005
+++ hobix.ljb/lib/hobix/weblog.rb	Tue Jul 26 08:31:38 2005
@@ -792,6 +792,15 @@
         entry
     end
 
+    # Appends the given items to an entry attachment with the given type, and
+    # then saves the modified attachment. If an attachment of the given type
+    # does not exist, it will be created.
+    def append_to_attachment( entry_id, attachment_type, *items )
+      attachment = storage.load_attached( entry_id, attachment_type ) rescue []
+      attachment += items
+      storage.save_attached( entry_id, attachment_type, attachment )
+    end
+
     # For convenience, storage queries can be made through the Weblog
     # class.  Queries will return the full Entry data, though, so it's
     # best to use this only when you're scripting and need data quick.
_______________________________________________
Hobix-is-the-way mailing list
[email protected]
http://rubyforge.org/mailman/listinfo/hobix-is-the-way

Reply via email to