Commits

Gabriele Lanaro committed 83b0e8f

a lot of improvements, now it rely on just one blog and the faces are better

Comments (0)

Files changed (5)

-;; Cleaning
-;;
+;; Variables
 
 (defvar blogger-mode-map nil "Local keymap for dired-mode buffers.")
 (defvar blogger-username nil "Username used to log in")
 (defvar blogger-password nil "Password to log in")
 (defvar blogger-default-blog-name nil "Default blog to edit")
 
+(defvar blogger-initialized nil "Check if the initialization procedure was successful")
+
+
+;; Faces
+(defface blogger-date
+  '((t (:inherit file-name-shadow))) "Face for date displaying")
+(defface blogger-title
+  '((t (:inherit font-lock-function-name-face))) "Face for displaying blog titles")
+(defface blogger-tags
+  '((t (:inherit font-lock-variable-name-face))) "Face for displaying tags")
+
+
 (defun blogger-post ()
   "Generic function to upload a post in blogger, it determines
 the current major mode and do exporting in various forms"
   (interactive)
-  (blogger-authenticate)
+  
+  (when (not blogger-initialized)
+    (blogger-initialize))
+
   (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)))
+    (message (format "Post '%s' successfully posted" title))
     )
   )
 
-(defun blogger-prompt-update ()
+(defun blogger-initialize ()
+  "Initialize the blogger object with authentication and fetching of blogs/entires"
+  (blogger-authenticate)
+  (blogger-bridge-refresh)
+  (if blogger-default-blog-name
+      (blogger-set-blog blogger-default-blog-name)
+    (blogger-select-blog)
+    )
+  (setq blogger-initialized t)
+  )
+
+(defun blogger-prompt-entry ()
   "Prompt an entry by name in the current blog, how to handle duplicate titles? mabye with numbers appended by recentness"
   )
 
     (setq title blogger-buffer-title)
     (setq content (blogger-filter-content))
     (blogger-bridge-update-post id title content)
+    (message "Post successfully updated")
     )
   )
 
   each blog, in Blogger mode"
   (interactive)
 
-    ;; Fetch the usn and pass and authenticate
-    (blogger-authenticate)
-    
-    ;; Loads/Refresh the blog list and prompt for the blog if not defined
-    (blogger-bridge-refresh)
-    (when (not blogger-default-blog-name)
-      (blogger-prompt-blog))
-    
-    (blogger-select-blog blogger-default-blog-name)
-    
-    (pop-to-buffer (generate-new-buffer "Blogger"))
-    
-    (let ((buffer-read-only nil))
-      (blogger-create-bloglist))
-    
-    (blogger-mode)
+  (when (not blogger-initialized)
+    (blogger-initialize))
 
+  (pop-to-buffer (generate-new-buffer "Blogger"))
+  
+  (let ((buffer-read-only nil))
+    (blogger-create-bloglist))
+  
+  (blogger-mode)
   )
 
 (defun blogger-delete ()
   "Delete post under cursor"
   (interactive)
-  (let (blog-id post-id)
-    (setq blog-id (get-text-property (point) 'blog-id))
+  (let (post-id)
     (setq post-id (get-text-property (point) 'entry-id))
-    (when (and blog-id post-id)
-      (blogger-bridge-delete-post post-id blog-id)
-      (blogger-update-view)))
+    
+    (when (and post-id (y-or-n-p "Delete Post?"))
+      (blogger-bridge-delete-post post-id)
+      (blogger-bridge-refresh)
+      (blogger-update-view)
+      (message "Entry successfully deleted"))
+    )
   )
 
 (defun blogger-rename-post ()
 (defun blogger-update-view ()
   "Refill the buffer with info about the blog"
   (interactive)
-  (let ((buffer-read-only nil))
-    (erase-buffer)
-    (blogger-create-bloglist)))
+  (save-excursion
+    (let ((buffer-read-only nil))
+      (erase-buffer)
+      (blogger-create-bloglist)
+      )
+    )
+  )
 
 (defun blogger-quit ()
   "quit the blogger buffer"
   (setq blogger-password (read-passwd "Password: "))
   )
 
+(defun blogger-select-blog ()
+  "Ask the user for the blog and set the current blog"
+  (interactive)
+  (blogger-set-blog (blogger-prompt-blog))
+  )
+
 (defun blogger-prompt-blog ()
   "Prompt the user for a blog with completion support"
   (setq blogger-default-blog-name 
   )
 )
 
-(defun blogger-select-blog (blog-name)
+(defun blogger-set-blog (blog-name)
   "Set the blog specified by BLOG-NAME as the current edited blog"
   (interactive)
-  (blogger-bridge-set-current-blog-by-name blog-name)
-  )
+  (blogger-bridge-set-current-blog-by-name blog-name))
 
 (defun blogger-create-bloglist ()
   "Create the list of entries in the selected blog"
-  
-  ;; Display entries of the current blog
   (dolist (entry (blogger-bridge-get-entries)) 
+    ;; Unpack the entry in various parts
     (let ((etitle (nth 1 entry))
 	  (eid (nth 0 entry))
-	  (edate (nth 2 entry)))
-      (insert (propertize (concat "-" edate "  ") 'entry-id eid))
-      (insert (propertize (concat etitle "\n") 'entry-id eid 'face 'dired-directory))
+	  (edate (nth 2 entry))
+	  (entry-tags (nth 3 entry)))
+      
+      ;; Insert date
+      (insert (propertize (concat "-" edate "  ") 'face 'blogger-date))
+      (insert (propertize (concat etitle "  ") 'face 'blogger-title))
+      ;; If there are tags
+      
+      (cond 
+       ;; If entry-tags is nil do nothing
+       ((eq entry-tags nil) (insert ""))
+       ;; If it is a string insert the string alone
+       ((stringp entry-tags) (insert entry-tags))
+       ;; If it is a list insert the tags separated by :
+       ((sequencep entry-tags)
+	(insert 
+	 (propertize
+	  (mapconcat 'identity entry-tags ":") 'face 'blogger-tags)))
+       )
+      
+      ;; Apply entry-id property to text
+      (put-text-property (line-beginning-position)
+			 (line-end-position) 'entry-id eid)
+      (insert (propertize "\n" 'entry-id eid))
       )
     ) ;; End dolist blogs
   )

blogger_bridge.py

         
         self.blogs = list(self.blogger.get_blogs())
 
+    @property
+    def blog(self):
+        if hasattr(self,"_blog"):
+            return self._blog
+        else:
+            lisp.error("Current Blog not selected")
+    
     def set_blog(self, blog_id):
-        self.blog = self.get_blog(blog_id)
+        self._blog = self.get_blog(blog_id)
 
+    blog.setter(set_blog)
+
+    
     def get_blogs(self):
         return [[blog.id, blog.name] for blog in self.blogs]    
     
         blog = self.blog
         
         entries = blog.get_entries()
-        return [[entry.id ,entry.title, entry.updated.strftime("%d/%m/%Y")] \
+        return [[entry.id ,entry.title, entry.updated.strftime("%d/%m/%Y"), entry.category] \
                     for entry in entries]
     
     def get_blog_names(self):
         blog = self.blogs[0] if blog_id == None else self.get_blog(blog_id)
         return blog
 
-    def post(self, title, content, blog_id = None):
-        blog = self.get_a_blog(blog_id)
-        entry = blog.publish_post(title, content)
+    def post(self, title, content):
+        '''Post this article to the current blog,
+        return the article id
+        '''
+        entry = self.blog.publish_post(title, content)
         return entry.id
     
     def update_post(self, post_id, title=None, content=None):

tests/test_open.el

 (load-file "setup_load.el")
 (load-file "setup_auth.el")
+(setq blogger-default-blog-name "Riding Python")
 (blogger-show)

tests/test_post.el

+(load-file "setup_load.el")
+(load-file "setup_auth.el")
+(find-file "../articles/testarticle.rst")
+(blogger-post)

tests/test_update_post.el

+(load-file "setup_load.el")
+(load-file "setup_auth.el")
+(find-file "../articles/testarticle.rst")
+(blogger-post)
+(blogger-update-post)
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.