public
Description: Publish to enki with VIM. That's pretty neat.
Homepage: http://enkiblog.com
Clone URL: git://github.com/xaviershay/enki-vim.git
enki-vim / put.rb
100644 32 lines (25 sloc) 0.732 kb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
#!/usr/bin/env ruby
require File.expand_path(File.join(File.dirname(__FILE__), 'common'))
 
# Parse buffer
buffer = VIM::Buffer.current
 
header = true
page = {'body' => []}
 
for index in (1..buffer.length)
  line = buffer[index]
  if header
    if line.length == 0
      header = false
    else
      tokens = line.split(': ')
      page[tokens.first] = tokens[1..-1].join(': ')
    end
  else
    page['body'] << line
  end
end
 
 
page['body'] = page['body'].join("\n")
id = page.delete('id')
    
post_data = {'page' => page}.to_yaml
h = Net::HTTP.new('localhost', 3000)
resp, data = h.put("/admin/pages/#{id}.yaml", post_data, { 'X-EnkiHash' => hash_request(post_data), 'Content-Type' => 'application/x-yaml' })
puts resp.code