public
Description: Some more or less useful rake tasks. Includes tasks to work with git-cvs, convert an Atom collection to a blog, post to an AtomPub server and more.
Homepage:
Clone URL: git://github.com/sr/tasks.git
tasks / atom_publish.rake
100644 21 lines (20 sloc) 0.985 kb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
namespace :atompub do
  desc 'Publish FILE or STDIN to the Atom collection located at URI. Specify LOGIN and PASS if needed.'
  task :publish do
    %w(rubygems rake atom/collection atom/yaml maruku rubypants).each { |l| require l }
    yaml = (ENV['FILE'] && File.exists?(ENV['FILE'])) ? File.read(ENV['FILE']) : STDIN.read
    http = Atom::HTTP.new
    if ENV['LOGIN'] && ENV['PASS']
      http.user = ENV['LOGIN']
      http.pass = ENV['PASS']
    end
    collection = Atom::Collection.new(ENV['URI'], http)
    entry = Atom::Entry.from_yaml(yaml)
    entry.content = Maruku.new(RubyPants.new(entry.content.to_s).to_html).to_html if ENV['HTMLIZE']
    entry.content['type'] = ENV['CONTENT_TYPE'] || 'xhtml'
    response = collection.post!(entry, ENV['SLUG'] || yaml['slug'])
    puts response.code.to_i == 201 ?
      "Ok, entry created. Location: #{Atom::Entry.parse(response.body).edit_url}" :
      "Oops, something went wrong. #{response.code} - #{response.message}"
  end
end