emacs_org_protocol_server 0.1.0 → 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 6cd216cbf9fc6631801e4c4d644c6dadf8cecb5f
4
- data.tar.gz: 4c7a17b84adba7fa55daf9a9d041dd7cde73006c
3
+ metadata.gz: 2330fe9ed02f5f65068e804fbb1cce0f9f36ab41
4
+ data.tar.gz: faf5c3997e5a1263ac1baad1cf972427e477b4af
5
5
  SHA512:
6
- metadata.gz: 279bdd2eb65b784fbf312c19fb4ac87d42812cbc10dbbb44b47ba68455d902347ae57cc0c73eb38dba2c1190c926803f1763ac73043b672137c3aa23b5ae0c59
7
- data.tar.gz: 210ca79de52caa60a636ad96482f0763636dd6be8c1e2fef3efbd80ebe4e8638e887bb2e40a2cba01a6e13d166587af7bef72c2d484f59c62b136a4b735a919f
6
+ metadata.gz: 4728aa51f40c332e9ad4428d4c6de0f2a35c7e9a2e7f3ff71a24699770b4e4d741780470d80337afd7ff80ac80c8272579efacad56960e4f3b4071525606c16f
7
+ data.tar.gz: 0ffcf8f23e782b017d7f363050502a84c0e44c845d3b9269afa76e67f6fec367f721ae3752387f24b2cd929d31e2272ad063b338b288c166824a57e0ff32a8d0
data/README.md CHANGED
@@ -24,31 +24,28 @@ Start it up:
24
24
  This will run the server on port 4567, and call
25
25
  `/usr/local/bin/emacsclient` to operate.
26
26
 
27
- ## Command line options
27
+ ## Server Configuration
28
28
 
29
- The command line options are the same as for any standard Sinatra
30
- application:
29
+ The server configuration is contained in the file `$HOME/.config/emacs_org_protocol_server.yml`, a standard YAML key-value pair file.
31
30
 
32
- emacs-org-protocol-server [-h] [-x] [-e ENVIRONMENT] [-p PORT] [-o HOST] [-s HANDLER]
33
-
34
- Options are:
35
-
36
- -h # help
37
- -p # set the port (default is 4567)
38
- -o # set the host (default is 0.0.0.0)
39
- -e # set the environment (default is development)
40
- -s # specify rack server/handler (default is thin)
41
- -x # turn on the mutex lock (default is off)
42
-
43
- In addition, you may set what the path to the `emacsclient`
44
- application is by setting the environment variable `EMACSCLIENT`. For
45
- example:
31
+ Example (defaults):
46
32
 
33
+ ``` yaml
34
+ server: [thin, mongrel, webrick]
35
+ port: 4567
36
+ bind: 0.0.0.0
37
+ emacsclient: /usr/local/bin/emacsclient
38
+ ```
47
39
 
48
- EMACSCLIENT=/usr/bin/emacsclient emacs-org-protocol-server -p 9294 -e production
40
+ You can also specify these via the environment, which will take precedence over the configuration file and the defaults:
49
41
 
50
- uses the `emacsclient` at `/usr/bin/emacsclient` running on port 9294
51
- in production.
42
+ ``` bash
43
+ EMACS_ORG_PROTOCOL_CONFIG=./my_config.yml
44
+ EMACS_ORG_PROTOCOL_BIND=127.0.0.1
45
+ EMACS_ORG_PROTOCOL_PORT=9998
46
+ EMACS_ORT_PROTOCOL_SERVER=thin
47
+ EMACSCLIENT=/Application/Emacs.app/Content/MacOS/bin/emacsclient
48
+ ```
52
49
 
53
50
  ## Browser Configuration
54
51
 
@@ -23,4 +23,5 @@ Gem::Specification.new do |spec|
23
23
  spec.add_development_dependency "rake", "~> 10.0"
24
24
  spec.add_dependency "thin"
25
25
  spec.add_dependency "sinatra"
26
+ spec.add_dependency "sinatra-contrib"
26
27
  end
File without changes
@@ -1,3 +1,3 @@
1
1
  module EmacsOrgProtocolServer
2
- VERSION = "0.1.0"
2
+ VERSION = "0.2.0"
3
3
  end
@@ -1,12 +1,43 @@
1
1
  require "emacs_org_protocol_server/version"
2
2
  require 'sinatra/base'
3
3
  require 'uri'
4
+ require 'yaml'
5
+ require 'erb'
4
6
 
5
7
  module EmacsOrgProtocolServer
6
- EMACSCLIENT=ENV['EMACSCLIENT'] || "/usr/local/bin/emacsclient"
8
+
9
+ class Settings
10
+ attr_accessor :emacsclient, :server, :port, :bind, :config_file, :settings
11
+ def initialize(server: '0.0.0.0', port: 4567, bind: '0.0.0.0', config_file: nil)
12
+ self.config_file = config_file || ENV['EMACS_ORG_PROTOCOL_CONFIG'] || File.join(ENV['HOME'], '.config', 'emacs_org_protocol_server.yml')
13
+ $stderr.puts "config_file: #{self.config_file.inspect}"
14
+
15
+ self.settings = {}
16
+ if File.exist?(self.config_file)
17
+ self.settings = YAML.load(
18
+ ERB.new(
19
+ File.read(self.config_file)
20
+ ).result
21
+ )
22
+ end
23
+
24
+ self.server = ENV['EMACS_ORG_PROTOCOL_SERVER'] || settings["server"] || %w[thin mongrel webrick]
25
+ self.port = ENV['EMACS_ORG_PROTOCOL_PORT'] || settings["port"] || '4567'
26
+ self.bind = ENV['EMACS_ORG_PROTOCOL_BIND'] || settings["bind"] || '0.0.0.0'
27
+ self.emacsclient = ENV['EMACSCLIENT'] || "/usr/local/bin/emacsclient"
28
+ end
29
+ end
30
+
31
+
7
32
 
8
33
  class OPServ < Sinatra::Application
9
34
 
35
+ settings = Settings.new
36
+ set :server , settings.server
37
+ set :port , settings.port
38
+ set :bind , settings.bind
39
+ enable :logging
40
+
10
41
  helpers do
11
42
  def esc(s)
12
43
  URI.escape(s, %r{[^[:alnum:]]})
@@ -29,9 +60,9 @@ module EmacsOrgProtocolServer
29
60
  s=params['s'].to_s
30
61
 
31
62
  emacsclient_target = "org-protocol://#{p}:#{template}//#{esc(l)}/#{esc(t)}/#{esc(s)}"
32
- cmd = "#{EMACSCLIENT} -n '#{emacsclient_target}'"
63
+ cmd = "#{settings.emacsclient} -n '#{emacsclient_target}'"
33
64
  system(cmd)
34
- puts "ran #{cmd}"
65
+ $stderr.puts "ran #{cmd}"
35
66
  redirect to(params['l'])
36
67
  end
37
68
 
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: emacs_org_protocol_server
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Tamara Temple
@@ -66,6 +66,20 @@ dependencies:
66
66
  - - ">="
67
67
  - !ruby/object:Gem::Version
68
68
  version: '0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: sinatra-contrib
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - ">="
74
+ - !ruby/object:Gem::Version
75
+ version: '0'
76
+ type: :runtime
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - ">="
81
+ - !ruby/object:Gem::Version
82
+ version: '0'
69
83
  description: Simple Sinatra server to call org-protocol with emacsclient
70
84
  email:
71
85
  - tamouse@gmail.com