Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Able to parse from document (markdown/html) #2

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 19 additions & 0 deletions README.rdoc
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,25 @@ After a post is successfully created, Tumblr will return the newly created post'

The `post` item that's returned will consist of an ID. If you would like to save this to your database, please make sure the field type is a string (this has caused me grief in the past)

Tumblr gem will transform documents preceded by a YAML frontmatter block http://www.yaml.org/.

YAML frontmatter beings with `---` on a single line, followed by YAML, ending with another `---` on a single line, e.g.

---
type: regular
title: "This is my title"
date: 2011-09-15 23:00
state: draft
tags: Ruby, Tumblr
---
"And the body goes here"

All YAML parameters are taken from the Tumblr API: http://www.tumblr.com/docs/api

and to create the post just pass the `filepath` alongside the `user` object:

post = Tumblr::Post.create(user, filepath)

== Updating posts

Updating posts is a lot like creating posts. The only thing you have to do is provide the id of the post you wish to edit (the parameters +type+, +private+ and +format+ are ignored and can be omitted.):
Expand Down
12 changes: 11 additions & 1 deletion lib/tumblr/post.rb
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,17 @@ def self.destroy(*args)

# extracts options from the arguments, converts a user object to :email and :password params and fixes the :post_id/'post-id' issue.
def self.process_options(*args)
options = args.last.is_a?(Hash) ? args.pop : {}
options = {}
if args.last.is_a?(Hash)
options.merge(args.pop)
elsif args.last.is_a?(String) and File.file? args.last
doc = IO.read(args.pop)
if doc =~ /^(\s*---(.*)---\s*)/m
options = YAML.load(Regexp.last_match[2].strip)
options[:body] = doc.sub(Regexp.last_match[1],'').strip
end
end


if((user = args.first).is_a?(Tumblr::User))
options = options.merge(
Expand Down