Skip to content

Commit

Permalink
Added an option to choose whether to store Markdown text in custom fi…
Browse files Browse the repository at this point in the history
…eld or not
  • Loading branch information
sudar committed Apr 22, 2013
1 parent ae8575f commit 109d520
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 16 deletions.
16 changes: 12 additions & 4 deletions 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
Expand All @@ -33,13 +33,21 @@ 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
password =

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`.
Expand Down
29 changes: 17 additions & 12 deletions plugin/vimrepress.py
Expand Up @@ -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))
Expand Down Expand Up @@ -144,14 +145,15 @@ 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)
if blog_password == '':
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"]

Expand All @@ -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 = []
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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:
Expand Down

0 comments on commit 109d520

Please sign in to comment.