From 109d520bfcbb4e9ddddd8fc65f13de51557c9f12 Mon Sep 17 00:00:00 2001 From: Sudar Date: Mon, 22 Apr 2013 22:25:08 +0530 Subject: [PATCH] Added an option to choose whether to store Markdown text in custom field or not --- README.md | 16 ++++++++++++---- plugin/vimrepress.py | 29 +++++++++++++++++------------ 2 files changed, 29 insertions(+), 16 deletions(-) diff --git a/README.md b/README.md index fb90fe0..d12b241 100644 --- a/README.md +++ b/README.md @@ -1,14 +1,14 @@ #Welcome -VimRepress is a plugin for managing wordpress blog from Vim, using Markdown syntax. +VimRepress is a plugin for managing WordPress blog from Vim, using Markdown syntax. ##Features - * NEW/EDIT/DELETE wordpress Posts/Pages. + * NEW/EDIT/DELETE WordPress Posts/Pages. * In both Markdown / HTML format. - * Markdown text stored in the custom fields of wordpress. + * Markdown text can be configured to be stored in the custom fields of WordPress. * Upload attachments. * Insert code highlight section. * Preview a posts in local compiled version, or remote draft. - * wordpress.com account supported. + * WordPress.com account supported. * Multiple account supported. ##Commands Reference @@ -33,6 +33,12 @@ Create file `~/.vimpressrc` in the following format: username = admin password = 123456 + [Blog1] + blog_url = https://blog1.wordpress.com/ + username = someone + password = + store_markdown = n + [BlogWhatEver] blog_url = https://someone.wordpress.com/ username = someone @@ -40,6 +46,8 @@ Create file `~/.vimpressrc` in the following format: Hardcoding the password is optional. If a password is not provided the plugin will prompt for one the first time it's needed. +`store_markdown` is also optional. If not specified then Markdown text will be stored in custom fields of WordPress. If set to `n` then the Markdown text will not be stored. + ###For Upgraded Users Defining account info in `.vimrc` is now obsolesced, if you have correspond defination in `.vimrc` (for older version vimpress), they will automaticly copied into `~/.vimpressrc`, now you're safe to remove the VIMPRESS defination in `.vimrc`. diff --git a/plugin/vimrepress.py b/plugin/vimrepress.py index 1eab25b..38ec811 100644 --- a/plugin/vimrepress.py +++ b/plugin/vimrepress.py @@ -82,6 +82,7 @@ class DataObject(object): blog_username = property(lambda self: self.xmlrpc.username) blog_url = property(lambda self: self.xmlrpc.blog_url) + store_markdown = property(lambda self: self.xmlrpc.store_markdown) conf_index = property(lambda self: self.__conf_index) current_post_id = property(lambda self: self.xmlrpc.current_post_id, lambda self, d: setattr(self.xmlrpc, "current_post_id", d)) @@ -144,6 +145,7 @@ def xmlrpc(self): blog_username = config['username'] blog_password = config.get('password', '') blog_url = config['blog_url'] + store_markdown = config.get('store_markdown', 'y') except KeyError, e: raise VimPressException("Configuration error: %s" % e) echomsg("Connecting to '%s' ... " % blog_url) @@ -151,7 +153,7 @@ def xmlrpc(self): blog_password = vim_input( "Enter password for %s" % blog_url, True) config["xmlrpc_obj"] = wp_xmlrpc(blog_url, - blog_username, blog_password) + blog_username, blog_password, store_markdown) self.__xmlrpc = config["xmlrpc_obj"] @@ -167,9 +169,9 @@ def xmlrpc(self): def config(self): if self.__config is None or len(self.__config) == 0: - confpsr = SafeConfigParser() + confpsr = SafeConfigParser({'store_markdown': 'y'}) confile = os.path.expanduser("~/.vimpressrc") - conf_options = ("blog_url", "username", "password") + conf_options = ("blog_url", "username", "password", "store_markdown") if os.path.exists(confile): conf_list = [] @@ -224,10 +226,11 @@ def config(self): class wp_xmlrpc(object): - def __init__(self, blog_url, username, password): + def __init__(self, blog_url, username, password, store_markdown): self.blog_url = blog_url self.username = username self.password = password + self.store_markdown = store_markdown p = xmlrpclib.ServerProxy(os.path.join(blog_url, "xmlrpc.php")) self.mw_api = p.metaWeblog self.wp_api = p.wp @@ -410,14 +413,16 @@ def refresh_from_buffer(self): #Translate markdown and save in custom fields. if meta["editformat"].lower() == "markdown": - for f in struct["custom_fields"]: - if f["key"] == G.CUSTOM_FIELD_KEY: - f["value"] = rawtext - break - # Not found, add new custom field. - else: - field = dict(key=G.CUSTOM_FIELD_KEY, value=rawtext) - struct["custom_fields"].append(field) + if g_data.store_markdown == 'y': + # Store markdown in custom field only when enabled + for f in struct["custom_fields"]: + if f["key"] == G.CUSTOM_FIELD_KEY: + f["value"] = rawtext + break + ## Not found, add new custom field. + else: + field = dict(key=G.CUSTOM_FIELD_KEY, value=rawtext) + struct["custom_fields"].append(field) struct["description"] = self.html_text = markdown.markdown(rawtext) else: