-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpashua.rb
46 lines (39 loc) · 1.21 KB
/
pashua.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
45
# Ruby module to use Pashua (http://www.bluem.net/downloads/pashua_en/).
# This module was contributed to the Pashua distribution by Mike Hall,
# with some changes by Carsten Bluem.
require 'tempfile'
module Pashua
def pashua_run(script, encoding = '', path = '')
pbin = pashua_locate(path) or return nil
encoding = "-e " + encoding + " " if encoding != ''
res = Hash.new
tmp = Tempfile.open('Pashua')
tmp.puts script
tmp.close
IO.popen("'" + pbin + "' " + encoding + tmp.path).each do |s|
key, val = s.chomp.split('=', 2)
res[key] = val
end
return res
end
def pashua_rewrite(s)
return (s.nil?) ? s : s.gsub(/\[return\]/, "\n") # rewrite any 'returns'
end
private
CWD='.'
ROOT = '/'
APPS = '/Applications'
USER = File::expand_path('~' + APPS)
def pashua_locate(path = '')
locations = [File.dirname($0), $0, CWD, ROOT, APPS, USER]
locations = [path] + locations if path != ''
for d in locations
p = File::join(d, 'Pashua')
return p if File::executable?(p)
p = File::join(d, 'Pashua.app/Contents/MacOS/Pashua')
return p if File::executable?(p)
end
$stderr.puts "Cannot find Pashua binary"
return nil
end
end