OSDN Git Service

no comments
authormasahino <masahino@0978bef0-6439-0410-a06b-a62e4d60c955>
Fri, 14 Sep 2007 17:09:34 +0000 (17:09 +0000)
committermasahino <masahino@0978bef0-6439-0410-a06b-a62e4d60c955>
Fri, 14 Sep 2007 17:09:34 +0000 (17:09 +0000)
git-svn-id: svn+ssh://svn.sourceforge.jp/svnroot/lbw/ldblogwriter/trunk@12 0978bef0-6439-0410-a06b-a62e4d60c955

lib/ldblogwriter-lib.rb
lib/ldblogwriter/command.rb
misc/lbw-mode.el [new file with mode: 0644]
misc/lbwriter-mode.el

index c749fcd..f419eda 100644 (file)
@@ -32,12 +32,11 @@ module LDBlogWriter
       #      data += "<subject xmlns=\"http://purl.org/dc/elements/1.1/\">#{category}</subject>\n"
       #    end
       data += "<subject xmlns=\"http://purl.org/dc/elements/1.1/\">#{@category}</subject>\n"
-    data += "<content xmlns=\"http://purl.org/atom/ns#\" mode=\"base64\">"
-    data += [@content].pack("m")
-    data += "</content>\n"
-    data += "</entry>\n"
-    #    puts data
-    return data
+      data += "<content xmlns=\"http://purl.org/atom/ns#\" mode=\"base64\">"
+      data += [@content].pack("m")
+      data += "</content>\n"
+      data += "</entry>\n"
+      return data
   end
   end
 
@@ -125,7 +124,9 @@ module LDBlogWriter
                                   @conf.password,
                                   title, category, content)
           puts "editURI : #{edit_uri}"
-          save_edit_uri(filename, edit_uri)
+          if edit_uri != false
+            save_edit_uri(filename, edit_uri)
+          end
         end
       else
         # edit
index cbf24f9..44e4a15 100644 (file)
@@ -53,11 +53,10 @@ module LDBlogWriter
         res = http.post(uri.path, data,
                         {'X-WSSE' => Wsse::get(username, password)})
         if res.code != "201"
+          p res
           return false
         end
         edit_uri = res['Location']
-        #      return BlogWriter::Response.new(res.body)
-#        save_edit_uri(edit_uri)
         return edit_uri
       end
     end
diff --git a/misc/lbw-mode.el b/misc/lbw-mode.el
new file mode 100644 (file)
index 0000000..4f72e9c
--- /dev/null
@@ -0,0 +1,132 @@
+; ndiary-modeをベースに作成
+;;
+;; ndiary-mode.el --- mode for editing ndiary's diary file
+;; ISHIKURA Hiroyuki <hiro@nekomimist.org>
+;
+(defcustom lbw-post-command "lbw"
+  "blog投稿用コマンド. Emacsが実行可能なファイルである必要がある."
+  :type 'filename
+  :group 'lbw-mode)
+(defcustom lbw-post-command-option ""  ; 未使用
+  "blog投稿用のコマンドのオプション."
+  :type 'string
+  :group 'lbw-mode)
+(defcustom lbw-yesterday-time 2
+  "この時間(hour)を超えるまでは前日としてdiaryファイルを作成/取りあつかう."
+  :type 'number
+  :group 'lbw-mode)
+(defcustom lbw-blog-directory "~/Diary"
+  "日記の置いてあるディレクトリ."
+  :type 'directory
+  :group 'lbw-mode)
+(defcustom lbw-split-month t
+  "月毎にdiaryファイルを作成するディレクトリを分けるか否か."
+  :type 'boolean
+  :group 'lbw-mode)
+(defcustom lbw-edit-hook nil nil
+  :type 'hook
+  :group 'lbw-mode)
+
+(defun lbw-mode ()
+  (interactive)
+  (setq major-mode 'lbw-mode)
+  (setq mode-name "livedoorBlogWriter")
+  (local-set-key "\C-c\C-c" 'lbw-post))
+
+(defun lbw-post (arg)
+  "ブログをポストする"
+  (interactive "P")
+  (let ((com lbw-post-command)
+       (opt lbw-post-command-option)
+       (filename buffer-file-name)
+       proc)
+    (basic-save-buffer) ; 実行前にbufferをsave
+    (if (not (exec-installed-p lbw-post-command))
+       (error "lbw-post-commandが正しく設定されていないようです."))
+    (save-excursion
+      (set-buffer (get-buffer-create "*lbw-post*"))
+      (if (get-process "lbw-post")
+         (progn
+           (delete-process "lbw-post")))
+      (erase-buffer)
+      (setq proc (start-process
+                 "lbw-post" "*lbw-post*" com filename))
+      (set-process-filter proc 'lbw-post-filter)
+      (display-buffer "*lbw-post*")
+      )))
+
+(defun lbw-post-filter (proc string)
+  "lbw post filter"
+  (let ((buffer (process-buffer proc)))
+    (set-buffer buffer)
+    (insert string)
+    (goto-char (point-max))
+    (cond
+     ((string-match "Username: " string)
+      (setq input_str (read-string "Username: "))
+      (process-send-string proc (concat input_str "\n")))
+     ((string-match "Password: " string)
+      (setq input_str (read-string "Password: "))
+      (process-send-string proc (concat input_str "\n")))
+     )))
+
+
+; ndiary-mode.elを思いっきり参考に
+; というか、ほとんどそのまんま
+(defun lbw-edit-internal (time)
+  "timeで示される日付の日記ファイルを編集する."
+  (let (dir
+       index)
+    ;; ndiary-log-directoryがアクセス不能ならおしまい
+    (if (not (file-accessible-directory-p lbw-blog-directory))
+       (error "lbw-blog-directoryの設定が正しくないと思われます."))
+
+    ;; 日記のファイル名を決定する
+    (cond
+     ((eq lbw-split-month t)
+      (setq dir (expand-file-name
+                (format-time-string "%Y/%m" time) lbw-blog-directory))
+      (if (not (file-accessible-directory-p dir))
+         (make-directory dir t)))
+     (t
+      (setq dir lbw-blog-directory)))
+
+    ;; バッファを作る
+    (setq index 1)
+    (setq lbw-file-name (expand-file-name 
+                        (format "%s-%d.txt" (format-time-string "%Y%m%d" time) index) dir))
+    (while (file-exists-p lbw-file-name)
+      (setq index (1+ index))
+      (setq lbw-file-name (expand-file-name 
+                          (format "%s-%d.txt"
+                                  (format-time-string "%Y%m%d" time) index) dir)))
+    
+    (setq lbw-buffer (find-file lbw-file-name)))
+  (run-hooks 'lbw-edit-hook)
+  (lbw-mode))
+
+(defun lbw-edit (arg)
+  "日記ファイルを編集する."
+  (interactive "P")
+  (let ((now (current-time)) (days 0) dateh datel daysec daysh daysl dir)
+    ;; "今日"の日付の計算
+    ;; ・hourがndiary-yesterday-time以前であれば1日前にずらす
+    ;; ・引数あり呼出ならpromptを出し、入力された数値だけ「今」からずらす
+    (if arg
+       (setq days (floor (string-to-number
+                          (read-from-minibuffer "offset: ")))))
+    (setq daysec (* -1.0 days 60 60 24))
+    (setq daysh (floor (/ daysec 65536.0)))
+    (setq daysl (round (- daysec (* daysh 65536.0))))
+    (setq dateh (- (nth 0 now) daysh))
+    (setq datel (- (nth 1 now) (* lbw-yesterday-time 3600) daysl))
+    (if (< datel 0)
+       (progn
+         (setq datel (+ datel 65536))
+         (setq dateh (1- dateh))))
+    (if (< dateh 0)
+       (setq dateh 0))
+    (setq now (list dateh datel))
+    (lbw-edit-internal now)))
+
+(provide 'lbw-mode)
\ No newline at end of file
index f040623..7d75944 100644 (file)
@@ -1,6 +1,6 @@
 ; ndiary-modeをベースに作成
 ;
-(defcustom lbwriter-post-command "lbwriter"
+(defcustom lbwriter-post-command "lbw"
   "blog投稿用コマンド. Emacsが実行可能なファイルである必要がある."
   :type 'filename
   :group 'lbwriter-mode)