Commits

Gabriele Lanaro committed 681b900

added functionality update-post, fixed #1

  • Participants
  • Parent commits 6dc63f0

Comments (0)

Files changed (3)

 (defvar blogger-username nil "Username used to log in")
 (defvar blogger-password nil "Password to log in")
 
-(defun blogger-quit ()
-  "quit the blogger buffer"
+(defun blogger-post ()
+  "Generic function to upload a post in blogger, it determines
+the current major mode and do exporting in various forms"
   (interactive)
-  (when (eq major-mode 'blogger-mode)
-    (kill-buffer (current-buffer))))
-
-(defun blogger-authenticate ()
-  "authenticate to blogger system"
-  (blogger-check-usn-pass)
-  (blogger-bridge-authenticate)
+  (blogger-authenticate)
+  (let (title id)
+    (setq title (read-from-minibuffer "Title: "))
+    (setq blogger-buffer-title title)
+    ;; The blogger-bridge-post return id of the post yet posted.
+    (setq blogger-buffer-post-id (blogger-bridge-post title (blogger-filter-content)))
+    )
   )
 
-(defun blogger-rename-post ()
-  "rename post under the cursor"
-  (when (get-text-property (point) 'post-id)
-    (blogger-bridge-update-title (get-text-property 'blog-id) (get-text-property 'post-id)))
-  (blogger-update-view))
+(defun blogger-update-post ()
+  "Update a blog post"
+  (interactive)
+  (let (id title content)
+    (setq id blogger-buffer-post-id)
+    (setq title blogger-buffer-title)
+    (setq content (blogger-filter-content))
+    (blogger-bridge-update-post id title content)
+    )
+  )
 
-(defun blogger-update-view ()
-  "Refill the buffer with info about the blog"
-  (interactive)
-  (let ((buffer-read-only nil))
-    (erase-buffer)
-    (blogger-create-bloglist)))
+;; Filtering
+(defun blogger-filter-content ()
+  "Filter the content of the current buffer and return the result of the filtering"
+  (case major-mode
+    ('rst-mode        
+     (blogger-process-rst))
+    )
+  )
 
-(defun blogger-check-usn-pass ()
-  "Check if username and password are defined and define it prompting the user"
-  (when (not (or blogger-username blogger-password))
-    (setq blogger-username (read-from-minibuffer "Username: "))
-    (setq blogger-password (read-passwd "Password: "))))
+(defun blogger-process-rst ()
+  "Filter the current buffer and return a string of the bloggerized post"
+  (let (buffer-substring-filters)
+    (setq buffer-substring-filters '(blogger-bridge-rst2blogger))
+    (filter-buffer-substring (point-min) (point-max))))
 
 
+;; Mode Commands
 (defun blogger-show ()
   "Starts a buffer with the blogs listed and shows the entries of
   each blog, in Blogger mode"
       (blogger-update-view)))
   )
 
-(defun blogger-post ()
-  "Generic function to upload a post in blogger, it determines
-the current major mode and do exporting in various forms"
+(defun blogger-rename-post ()
+  "rename post under the cursor"
+  (when (get-text-property (point) 'post-id)
+    (blogger-bridge-update-title (get-text-property 'blog-id) (get-text-property 'post-id)))
+  (blogger-update-view))
+
+(defun blogger-quit ()
+  "quit the blogger buffer"
   (interactive)
-  (blogger-authenticate)
-  (let (title)
-    (setq title (read-from-minibuffer "Title: "))
-    (case major-mode
-      ('rst-mode 
-       (blogger-bridge-post title (blogger-process-rst)))
-      ))
+  (when (eq major-mode 'blogger-mode)
+    (kill-buffer (current-buffer))))
+
+(defun blogger-update-view ()
+  "Refill the buffer with info about the blog"
+  (interactive)
+  (let ((buffer-read-only nil))
+    (erase-buffer)
+    (blogger-create-bloglist)))
+
+
+;; Utility/Displaying functions
+(defun blogger-authenticate ()
+  "authenticate to blogger system"
+  (blogger-check-usn-pass)
+  (blogger-bridge-authenticate)
   )
 
-(defun blogger-process-rst ()
-  "Filter the current buffer and return a string of the bloggerized post"
-  (let (buffer-substring-filters)
-    (setq buffer-substring-filters '(blogger-bridge-rst2blogger))
-    (filter-buffer-substring (point-min) (point-max))))
+(defun blogger-check-usn-pass ()
+  "Check if username and password are defined and define it prompting the user"
+  (when (not (or blogger-username blogger-password))
+    (setq blogger-username (read-from-minibuffer "Username: "))
+    (setq blogger-password (read-passwd "Password: "))))
+
 
 (defun blogger-create-bloglist ()
   "Create the list of blogs with respective entries"
         '''
         Update the post identified by post_id
         '''
-        entry = [ entry for entry in self.get_entries() if entry.id == post_id].pop()
+        entry = self.get_entry(post_id)
+        
         if title!=None:
             entry.feed.title = atom.Title('xhtml',title)
         if content!=None:

blogger_bridge.py

 
     def post(self, title, content, blog_id = None):
         blog = self.get_a_blog(blog_id)
-        blog.publish_post(title, content)
+        entry = blog.publish_post(title, content)
+        return entry.id
+    
+    def update_post(self, post_id, title=None, content=None):
+        blog = self.get_a_blog()
+        blog.update_post(post_id, title, content)
     
     def delete_post(self, post_id, blog_id = None):
         blog = self.get_a_blog(blog_id)
 
 li = LispInteractive()
 
+# Exposing functions
 authenticate = li.authenticate
 get_blogs = li.get_blogs
 get_entries = li.get_entries
                            filters.degrade_sections,
                            filters.remove_space_between_tags)
 delete_post = li.delete_post
-#interactions[create_bloglist] = ""
+update_post = li.update_post
 
 # Local Variables:
 # pymacs-auto-reload: t