/
org-converter.rb
44 lines (36 loc) · 1.01 KB
/
org-converter.rb
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
33
34
35
36
37
38
39
40
41
42
43
44
EMACS_PATH="/usr/local/Cellar/emacs-mac/emacs-24.5-z-mac-5.15/Emacs.app/Contents/MacOS/Emacs"
module Jekyll
class OrgConverter < Converter
safe true
priority :low
def matches(ext)
ext =~ /^\.org$/i
end
def output_ext(ext)
".html"
end
def ensure_server!
@server_pid ||=
begin
emacs_execution_string = EMACS_PATH + " -Q" \
" --daemon=org-convert-daemon -L " \
"_vendor/org-8.2.6/lisp/ -l _lib/org-convert.el -f start-compile-server"
server_pid = spawn(emacs_execution_string)
at_exit do
spawn("emacsclient -s org-convert-daemon -e '(kill-emacs)'")
end
sleep 3 # give the process a few secs to warm up
server_pid
end
end
def convert(content)
require 'socket'
ensure_server!
TCPSocket.open 'localhost', 9876 do |socket|
socket.puts "Length: #{content.bytesize}"
socket.write content
socket.read
end
end
end
end